REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
REMORA_console_io.cpp
Go to the documentation of this file.
1#include <chrono>
2#include <ctime>
3#include "REMORA.H"
4#include "AMReX.H"
5#include "AMReX_Vector.H"
6
7#ifdef REMORA_USE_NETCDF
9#endif
10
11namespace amrex {
13const char* buildInfoGetComp();
14const char* buildInfoGetGitHash(int i);
16} // namespace amrex
17
18//namespace REMORA::io {
19
20namespace {
21const std::string dbl_line = std::string(78, '=') + "\n";
22const std::string dash_line = "\n" + std::string(78, '-') + "\n";
23} // namespace
24
25
26void REMORA::print_usage(MPI_Comm comm, std::ostream& out)
27{
28#ifdef AMREX_USE_MPI
29 int irank = 0;
30 int num_ranks = 1;
31 MPI_Comm_size(comm, &num_ranks);
32 MPI_Comm_rank(comm, &irank);
33
34 // Only root process does the printing
35 if (irank != 0) return;
36#else
37 amrex::ignore_unused(comm);
38#endif
39
40 out << R"doc(Usage:
41 REMORA3d.*.ex <input_file> [param=value] [param=value] ...
42
43Required:
44 input_file : Input file with simulation settings
45
46Optional:
47 param=value : Overrides for parameters during runtime
48)doc" << std::endl;
49}
50
51void REMORA::print_error(MPI_Comm comm, const std::string& msg)
52{
53#ifdef AMREX_USE_MPI
54 int irank = 0;
55 int num_ranks = 1;
56 MPI_Comm_size(comm, &num_ranks);
57 MPI_Comm_rank(comm, &irank);
58
59 // Only root process does the printing
60 if (irank != 0) return;
61#else
62 amrex::ignore_unused(comm);
63#endif
64
65 std::cout << "ERROR: " << msg << std::endl;
66}
67
68void REMORA::print_banner(MPI_Comm comm, std::ostream& out)
69{
70#ifdef AMREX_USE_MPI
71 int irank = 0;
72 int num_ranks = 1;
73 MPI_Comm_size(comm, &num_ranks);
74 MPI_Comm_rank(comm, &irank);
75
76 // Only root process does the printing
77 if (irank != 0) return;
78#else
79 amrex::ignore_unused(comm);
80#endif
81
82 auto etime = std::chrono::system_clock::now();
83 auto etimet = std::chrono::system_clock::to_time_t(etime);
84#ifndef _WIN32
85 char time_buf[64];
86 ctime_r(&etimet, time_buf);
87 const std::string tstamp(time_buf);
88#else
89 char* time_buf = new char[64];
90 ctime_s(time_buf, 64, &etimet);
91 const std::string tstamp(time_buf);
92#endif
93
94 const char* githash1 = amrex::buildInfoGetGitHash(1);
95 const char* githash2 = amrex::buildInfoGetGitHash(2);
96
97 // clang-format off
98 out << dbl_line
99 << " REMORA (https://github.com/seahorce-scidac/REMORA)"
100 << std::endl << std::endl
101 << " REMORA Git SHA :: " << githash1 << std::endl
102 << " AMReX Git SHA :: " << githash2 << std::endl
103 << " AMReX version :: " << amrex::Version() << std::endl << std::endl
104 << " Exec. time :: " << tstamp
105 << " Build time :: " << amrex::buildInfoGetBuildDate() << std::endl
106 << " C++ compiler :: " << amrex::buildInfoGetComp()
107 << " " << amrex::buildInfoGetCompVersion() << std::endl << std::endl
108 << " MPI :: "
109#ifdef AMREX_USE_MPI
110 << "ON (Num. ranks = " << num_ranks << ")" << std::endl
111#else
112 << "OFF " << std::endl
113#endif
114 << " GPU :: "
115#ifdef AMREX_USE_GPU
116 << "ON "
117#if defined(AMREX_USE_CUDA)
118 << "(Backend: CUDA)"
119#elif defined(AMREX_USE_HIP)
120 << "(Backend: HIP)"
121#elif defined(AMREX_USE_SYCL)
122 << "(Backend: SYCL)"
123#endif
124 << std::endl
125#else
126 << "OFF" << std::endl
127#endif
128 << " OpenMP :: "
129#ifdef AMREX_USE_OMP
130 << "ON (Num. threads = " << omp_get_max_threads() << ")" << std::endl
131#else
132 << "OFF" << std::endl
133#endif
134 << std::endl;
135
136 print_tpls(out);
138 out << " This software is released under the BSD 3-clause license. "
139 << std::endl
140 << " See https://github.com/seahorce-scidac/REMORA/blob/development/LICENSE.md for details. "
141 << dash_line << std::endl;
142 // clang-format on
143}
144
145void REMORA::print_tpls(std::ostream& out)
146{
147 amrex::Vector<std::string> tpls;
148
149#ifdef REMORA_USE_NETCDF
150 tpls.push_back(std::string("NetCDF ") + PNETCDF_VERSION);
151#endif
152
153 if (!tpls.empty()) {
154 out << " Enabled third-party libraries: ";
155 for (const auto& val : tpls) {
156 out << "\n " << val;
157 }
158 out << std::endl << std::endl;
159 } else {
160 out << " No additional third-party libraries enabled" << std::endl
161 << std::endl;
162 }
163}
164
165//} // namespace REMORA::io
static void print_error(MPI_Comm, const std::string &msg)
static void print_usage(MPI_Comm, std::ostream &)
static void print_banner(MPI_Comm, std::ostream &)
static void print_tpls(std::ostream &)
const char * buildInfoGetGitHash(int i)
const char * buildInfoGetBuildDate()
const char * buildInfoGetCompVersion()
const char * buildInfoGetComp()