REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1#include <iostream>
2
3#include <AMReX.H>
4#include <AMReX_BLProfiler.H>
5#include <AMReX_ParallelDescriptor.H>
6
7#include <REMORA.H>
8
9#if defined(AMREX_USE_FLOAT) && (defined(__SSE__) || defined(__x86_64__))
10#include <xmmintrin.h>
11#include <pmmintrin.h>
12#define REMORA_CAN_FLUSH_SUBNORMALS
13#endif
14
15std::string inputs_name = "";
16
17using namespace amrex;
18
19// In single precision, small intermediate products (e.g. velocity times metric
20// terms) can fall below FLT_MIN. Operations on subnormal floats take a slow
21// microcode path on x86, which can make single precision slower than double.
22// Flush them to zero (FTZ) and treat subnormal inputs as zero (DAZ) on every
23// thread. Disable with remora.flush_subnormals = false.
25#ifdef REMORA_CAN_FLUSH_SUBNORMALS
26 bool flush_subnormals = true;
27 ParmParse pp("remora");
28 pp.query("flush_subnormals",flush_subnormals);
29 if (!flush_subnormals) { return; }
30
31 auto set_mode = [] () {
34 };
35 set_mode();
36#ifdef AMREX_USE_OMP
37#pragma omp parallel
38 set_mode();
39#endif
40#endif
41}
42
43// Set the refine_grid_layout flags to (NGROW-1,NGROW-1,0) by default
44// since the REMORA default is different from the amrex default (NGROW-1,NGROW-1,NGROW-1)
45// Also set max_grid_size to very large since the only reason for
46// chopping grids is if Nprocs > Ngrids
47void add_par () {
48 ParmParse pp("amr");
49 ParmParse pp_remora("remora");
50
51 // Set the refine_grid_layout flags to (NGROW-1,NGROW-1,0) by default
52 pp.add("refine_grid_layout_x",1);
53 pp.add("refine_grid_layout_y",1);
54 pp.add("refine_grid_layout_z",0);
55
56 // n_proper is the minimum number of coarse cells between coarse-fine boundaries
57 // between levels (ell and ell+1) and levels (ell-1 and ell). We want this to be
58 // greater than or equal to the stencil width (a function of spatial order) divided by
59 // ref_ratio (which can be 2,3 or 4). This ensures that fillpatch at level (ell)
60 // does not need to reach beyond level (ell-1). Here to be conservative we set this to 2
61 // (rather than the amrex default of 1).
62 pp.add("n_proper",2);
63
64 int max_grid_size = 2048;
65 pp.queryAdd("max_grid_size",max_grid_size);
66
67 // This will set the default value of blocking_factor to be 1, but will allow
68 // the user to override it in the inputs file or on command line
69 int blocking_factor = 1;
70 pp.queryAdd("blocking_factor",blocking_factor);
71
72 // Default error buf of 0, user can override. Note that the whole column will be tagged
73 // if any one cell is tagged, even if n_error_buf_z = 0
74 int n_error_buf = 0;
75 pp.queryAdd("n_error_buf",n_error_buf);
76
77 // Inject variables into ParmParse database with the prefixes AMReX expects
78 // This allows a REMORA user to use the remora. prefix for some AMReX-specific options
79 amrex::Vector<int> n_cell;
80 pp_remora.queryarr("n_cell",n_cell);
81 pp.queryAdd("n_cell",n_cell);
82
83 int max_level = 0;
84 // Default max_level to 0 if not in file
85 if (!pp.query("max_level",max_level)) {
86 pp.queryAdd("max_level",max_level);
87 }
88
89 // If amr.v is not specified, set it equal to remora.v
90 int amr_verbosity = 0;
91 bool defined_amr_verbosity = pp.query("v",amr_verbosity);
93 int rem_verbosity = 0;
94 pp_remora.query("v",rem_verbosity);
95 pp.queryAdd("v",rem_verbosity);
96 }
97
98 ParmParse pp_geometry("geometry");
99 amrex::Vector<amrex::Real> prob_lo;
100 amrex::Vector<amrex::Real> prob_hi;
101 amrex::Vector<int> is_periodic;
102 pp_remora.queryarr("prob_lo",prob_lo);
103 pp_remora.queryarr("prob_hi",prob_hi);
104 pp_remora.queryarr("is_periodic",is_periodic);
105 pp_geometry.queryAdd("prob_lo",prob_lo);
106 pp_geometry.queryAdd("prob_hi",prob_hi);
107 pp_geometry.queryAdd("is_periodic",is_periodic);
108
109 ParmParse pp_fabarray("fabarray");
110#if defined(REMORA_USE_GPU)
111 amrex::Vector<int> omp_tile_size = {1024000,1024000,1024000};
112#else
113 amrex::Vector<int> omp_tile_size = {8, 8, 1024000};
114#endif
115 pp_remora.queryarr("omp_tile_size",omp_tile_size,0,3);
116 pp_fabarray.queryAdd("mfiter_tile_size",omp_tile_size);
117}
118
119int main(int argc, char* argv[])
120{
121{
122#ifdef AMREX_USE_MPI
123 MPI_Init(&argc, &argv);
124#endif
125
126 if (argc < 2) {
127 // Print usage and exit with error code if no input file was provided.
128 REMORA::print_usage(MPI_COMM_WORLD, std::cout);
130 MPI_COMM_WORLD, "No input file provided. Exiting!!");
131 return 1;
132 }
133
134 // Look for "-h" or "--help" flag and print usage
135 for (auto i = 1; i < argc; i++) {
136 const std::string param(argv[i]);
137 if ((param == "--help") || (param == "-h") || (param == "--usage")) {
138 REMORA::print_banner(MPI_COMM_WORLD, std::cout);
139 REMORA::print_usage(MPI_COMM_WORLD, std::cout);
140 return 0;
141 }
142 }
143
144 if (!amrex::FileSystem::Exists(std::string(argv[1]))) {
145 // Print usage and exit with error code if we cannot find the input file
146 REMORA::print_usage(MPI_COMM_WORLD, std::cout);
148 MPI_COMM_WORLD, "Input file does not exist = " +
149 std::string(argv[1]) + ". Exiting!!");
150 return 1;
151 }
152
153 // print_banner(MPI_COMM_WORLD, std::cout);
154 // Check to see if the command line contains --describe
155 if (argc >= 2) {
156 for (auto i = 1; i < argc; i++) {
157 if (std::string(argv[i]) == "--describe") {
158 REMORA::writeBuildInfo(std::cout);
159 return 0;
160 }
161 }
162 } else if(argc < 2) {
163 amrex::Print() << "REMORA is currently under development as a next-generation version of the Regional Ocean Modeling System (ROMS). See Docs for more information.\n"
164 <<" usage:\n"
165 <<" ./REMORA3d.xxx.yyy.ex inputs" <<std::endl;
166// std::cerr << "inputs should follow executable on command line" << std::endl;
167 return -1;
168 }
169
170 amrex::Initialize(argc,argv,true,MPI_COMM_WORLD,add_par);
171
173
174 // Save the inputs file name for later.
175 if (!strchr(argv[1], '=')) {
176 inputs_name = argv[1];
177 }
178
179 // timer for profiling
180 BL_PROFILE_VAR("main()", pmain);
181
182 // wallclock time
183 const Real strt_total = Real(amrex::second());
184
185 {
186 BL_PROFILE_VAR("REMORA::InitData()", pinit);
187 // constructor - reads in parameters from inputs file
188 // - sizes multilevel arrays and data structures
190
191 // initialize AMR data
193
195
196 // advance solution to final time
197 remora.Evolve();
198
199 // wallclock time
200 Real end_total = Real(amrex::second()) - strt_total;
201
202 // print wallclock time
203 ParallelDescriptor::ReduceRealMax(end_total ,ParallelDescriptor::IOProcessorNumber());
204 if (remora.Verbose()) {
205 amrex::Print() << "\nTotal Time: " << end_total << '\n';
206 }
207 }
208
209 // destroy timer for profiling
211 amrex::Finalize();
212#ifdef AMREX_USE_MPI
213 MPI_Finalize();
214#endif
215}
216}
mf_h setVal(geomdata.ProbHi(2))
Class that stores all relevant simulation state data with methods for time stepping.
Definition REMORA.H:93
static void print_error(MPI_Comm, const std::string &msg)
static void writeBuildInfo(std::ostream &os)
Write build info to os.
void InitData()
Initialize multilevel data.
Definition REMORA.cpp:466
static void print_usage(MPI_Comm, std::ostream &)
static void print_banner(MPI_Comm, std::ostream &)
int main(int argc, char *argv[])
Definition main.cpp:119
void set_flush_subnormals()
Definition main.cpp:24
void add_par()
Definition main.cpp:47
std::string inputs_name
Definition main.cpp:15