Skip to content

Commit

Permalink
ParmParse::addfile needs Init
Browse files Browse the repository at this point in the history
`ParmParse` can be used before AMReX is initialized for most
functionality, which is greatly helpful for us. One function that
cannot be used before init is reading from a file, because it needs
an MPI context to broadcast.

Add a clean error message instead of a segfault.
  • Loading branch information
ax3l committed Jul 21, 2023
1 parent 587542a commit 452a29b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Src/Base/AMReX_ParmParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,11 @@ read_file (const char* fname, std::list<ParmParse::PP_entry>& tab)
//
if ( fname != nullptr && fname[0] != 0 )
{
#ifdef AMREX_USE_MPI
if (!amrex::Initialized())
amrex::Error("read_file: AMReX must be initialized");
#endif

Vector<char> fileCharPtr;
std::string filename = fname;
ParallelDescriptor::ReadAndBcastFile(filename, fileCharPtr);
Expand Down Expand Up @@ -1068,6 +1073,11 @@ ParmParse::prefixedName (const std::string& str) const

void
ParmParse::addfile (std::string const& filename) {
#ifdef AMREX_USE_MPI
if (!amrex::Initialized())
amrex::Error("ParmParse::addfile: AMReX must be initialized");
#endif

auto l = std::list<std::string>{filename};
auto file = FileKeyword;
addDefn(file,
Expand Down

0 comments on commit 452a29b

Please sign in to comment.