ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
main.cpp File Reference
#include <iostream>
#include <AMReX.H>
#include <AMReX_BLProfiler.H>
#include <AMReX_ParallelDescriptor.H>
#include "ERF.H"
#include "ERF_InputsName.H"
Include dependency graph for main.cpp:

Functions

void add_par ()
 
int main (int argc, char *argv[])
 

Variables

std::string inputs_name
 

Function Documentation

◆ add_par()

void add_par ( )

Function to set the refine_grid_layout flags to (1,1,0) by default since the ERF default is different from the amrex default (1,1,1) Also set max_grid_size to very large since the only reason for chopping grids is if Nprocs > Ngrids

25  {
26  ParmParse pp("amr");
27 
28  // Set the refine_grid_layout flags to (1,1,0) by default
29  pp.add("refine_grid_layout_x",1);
30  pp.add("refine_grid_layout_y",1);
31  pp.add("refine_grid_layout_z",0);
32 
33  // n_proper is the minimum number of coarse cells between coarse-fine boundaries
34  // between levels (ell and ell+1) and levels (ell-1 and ell). We want this to be
35  // greater than or equal to the stencil width (a function of spatial order) divided by
36  // ref_ratio (which can be 2,3 or 4). This ensures that fillpatch at level (ell)
37  // does not need to reach beyond level (ell-1). Here to be conservative we set this to 2
38  // (rather than the amrex default of 1).
39  pp.add("n_proper",2);
40 
41  int max_grid_size = 2048;
42  pp.queryAdd("max_grid_size",max_grid_size);
43 
44  // This will set the default value of blocking_factor to be 1, but will allow
45  // the user to override it in the inputs file or on command line
46  int blocking_factor = 1;
47  pp.queryAdd("blocking_factor",blocking_factor);
48 
49  int n_error_buf = 0;
50  pp.queryAdd("n_error_buf",n_error_buf);
51 }
ParmParse pp("prob")

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

Main driver – creates the ERF object, calls ERF.InitData() and ERF.Evolve()

57 {
58 
59 auto finalize_mpi_and_return = [](int code) {
60 #ifdef AMREX_USE_MPI
61 #ifdef ERF_USE_WW3_COUPLING
62  amrex::MPMD::Finalize();
63 +#else
64  MPI_Finalize();
65 #endif
66 #endif
67 return code;
68 };
69 
70 #if defined(AMREX_MPI_THREAD_MULTIPLE)
71  int requested = MPI_THREAD_MULTIPLE;
72  int provided = -1;
73  MPI_Init_thread(&argc, &argv, requested, &provided);
74 #elif defined(AMREX_USE_MPI)
75  MPI_Init(&argc, &argv);
76 #endif
77 
78  if (argc < 2) {
79  // Print usage and exit with error code if no input file was provided.
80  ERF::print_usage(MPI_COMM_WORLD, std::cout);
82  MPI_COMM_WORLD, "No input file provided. Exiting!!");
83  return 1;
84  }
85 
86  // Look for "-h" or "--help" flag and print usage
87  for (auto i = 1; i < argc; i++) {
88  const std::string param(argv[i]);
89  if ((param == "--help") || (param == "-h") || (param == "--usage")) {
90  ERF::print_banner(MPI_COMM_WORLD, std::cout);
91  ERF::print_usage(MPI_COMM_WORLD, std::cout);
92  return 0;
93  }
94  }
95 
96  if (argc >= 2) {
97  for (auto i = 1; i < argc; i++) {
98  if (std::string(argv[i]) == "--describe") {
99  ERF::writeBuildInfo(std::cout);
100  return finalize_mpi_and_return(0);
101  }
102  }
103  }
104 
105  if (!strchr(argv[1], '=') && !amrex::FileSystem::Exists(std::string(argv[1])))
106  {
107  // Print usage and exit with error code if we cannot find the input file
108  ERF::print_usage(MPI_COMM_WORLD, std::cout);
110  MPI_COMM_WORLD, "Input file does not exist = " +
111  std::string(argv[1]) + ". Exiting!!");
112  return finalize_mpi_and_return(1);
113  }
114 
115  // print_banner(MPI_COMM_WORLD, std::cout);
116  // Check to see if the command line contains --describe
117  if (argc >= 2) {
118  for (auto i = 1; i < argc; i++) {
119  if (std::string(argv[i]) == "--describe") {
120  ERF::writeBuildInfo(std::cout);
121  return 0;
122  }
123  }
124  }
125 #ifdef ERF_USE_WW3_COUPLING
126  MPI_Comm comm = amrex::MPMD::Initialize(argc, argv);
127  amrex::Initialize(argc,argv,true,comm,add_par);
128 #else
129  amrex::Initialize(argc,argv,true,MPI_COMM_WORLD,add_par);
130 #endif
131 
132 #ifdef ERF_USE_KOKKOS
133  // Initialize kokkos
134  if (!Kokkos::is_initialized()) {
135  Kokkos::initialize(Kokkos::InitializationSettings()
136  .set_device_id(amrex::Gpu::Device::deviceId()));
137  }
138 #endif
139 
140  // Save the inputs file name for later.
141  if (!strchr(argv[1], '=')) {
142  inputs_name = argv[1];
143  }
144 
145  // timer for profiling
146  BL_PROFILE_VAR("main()", pmain);
147 
148  // wallclock time
149  const Real strt_total = Real(amrex::second());
150 
151  {
152  // constructor - reads in parameters from inputs file
153  // - sizes multilevel arrays and data structures
154  ERF erf;
155 
156  // initialize AMR data
157  erf.InitData();
158 
159  // advance solution to final time
160  erf.Evolve();
161 
162  // wallclock time
163  Real end_total = Real(amrex::second()) - strt_total;
164 
165  // print wallclock time
166  ParallelDescriptor::ReduceRealMax(end_total ,ParallelDescriptor::IOProcessorNumber());
167  if (erf.Verbose()) {
168  amrex::Print() << "\nTotal Time: " << end_total << '\n';
169  }
170  }
171 
172  // destroy timer for profiling
173  BL_PROFILE_VAR_STOP(pmain);
174 #ifdef ERF_USE_WW3_COUPLING
175  MPI_Barrier(MPI_COMM_WORLD);
176 #endif
177 
178 #ifdef ERF_USE_KOKKOS
179  Kokkos::finalize();
180 #endif
181 
182  amrex::Finalize();
183 #ifdef AMREX_USE_MPI
184 #ifdef ERF_USE_WW3_COUPLING
185  amrex::MPMD::Finalize();
186 #else
187  MPI_Finalize();
188 #endif
189 #endif
190 }
amrex::Real Real
Definition: ERF_ShocInterface.H:19
void Evolve()
Definition: ERF.cpp:608
static void print_banner(MPI_Comm, std::ostream &)
Definition: ERF_ConsoleIO.cpp:60
void InitData()
Definition: ERF.cpp:983
static void print_error(MPI_Comm, const std::string &msg)
Definition: ERF_ConsoleIO.cpp:43
static void writeBuildInfo(std::ostream &os)
Definition: ERF_WriteJobInfo.cpp:143
static void print_usage(MPI_Comm, std::ostream &)
Definition: ERF_ConsoleIO.cpp:26
void add_par()
Definition: main.cpp:25
std::string inputs_name
Definition: main.cpp:15
Definition: ERF_InterpolationUtils.H:16
Here is the call graph for this function:

Variable Documentation

◆ inputs_name

std::string inputs_name

Referenced by main(), and ERF::writeJobInfo().