|
ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
|
#include <cstdio>#include <cstdlib>#include <iostream>#include <AMReX.H>#include <AMReX_BLProfiler.H>#include <AMReX_ParallelDescriptor.H>#include "ERF.H"#include "ERF_InputsName.H"
Functions | |
| void | add_par () |
| static void | erf_flush_fortran_units () |
| void | install_exit_trap () |
| int | main (int argc, char *argv[]) |
Variables | |
| std::string | inputs_name |
| 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, and set no_box_split_dir to 2 so that grids are never decomposed in the vertical direction
Referenced by main().


|
static |
| void install_exit_trap | ( | ) |
Make a run that leaves through exit() before amrex::Finalize report failure.
A normal run calls amrex::Finalize before main returns, so a process that reaches exit() while AMReX is still initialised has stopped part-way – with no final plotfile or checkpoint – whatever status it asked for. The ways in are a Fortran STOP in a coupled library (Noah-MP has 27, all exit status 0) and the exit() calls left in ERF itself, some of which also pass 0. Run under Open MPI's launcher such a run is still flagged, because the rank never calls MPI_Finalize; run directly, or under a launcher that does not enforce that, it reports success. Every return from main after amrex::Initialize goes through amrex::Finalize, so this never fires on a normal exit.
amrex::Abort ends in MPI_Abort, or std::_Exit in a serial build. Open MPI's MPI_Abort kills the job without exit(), but MPICH's (and Cray MPICH's) ends in exit(errorcode), so there the trap runs after an abort as well: the run is still reported as a failure, with status 1 in place of the abort's code, and the message below allows for it.
A Fortran STOP or an exit() fires on the one rank that hit the problem; ending only that rank would leave the others blocked in their next collective until the launcher notices (Open MPI does; srun without –kill-on-bad-exit and some PMI setups may not). So the trap calls MPI_Abort to tear the whole job down, guarded so that an MPI whose own MPI_Abort ends in exit() (MPICH, Cray MPICH) cannot re-enter it, and skipped when MPI is not initialised or already finalised.
std::_Exit is the only way to change the status from here, and it skips the rest of the exit sequence, which is what would flush the output buffers. Standard output is fully buffered when it is redirected to a file, so flush everything first – C++ streams, C stdio and the Fortran units – or the lines that explain the stop are lost.
Referenced by main().


| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Main driver – creates the ERF object, calls ERF.InitData() and ERF.Evolve()

| std::string inputs_name |
Referenced by main(), and ERF::writeJobInfo().