Skip to content

Commit

Permalink
ParmParse:addFile: User-Friendly Error (#4156)
Browse files Browse the repository at this point in the history
## Summary

If a file added via `ParmParse:addFile` does not exist, we did not yet
receive a user-friendly error message. This fixes this in a way that
does not hammer the file system from all MPI ranks.

## Additional background

Follow-up to #2842 #2936 #3440

X-ref: ECP-WarpX/WarpX#5283
ECP-WarpX/impactx#704
  • Loading branch information
ax3l committed Sep 18, 2024
1 parent 23a7f34 commit 6c7668c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Src/Base/AMReX_ParmParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1069,12 +1069,23 @@ ParmParse::prefixedName (const std::string_view& str) const
void
ParmParse::addfile (std::string const& filename) {
#ifdef AMREX_USE_MPI
// this is required because we will BCast the file content in sub-function calls
if (ParallelDescriptor::Communicator() == MPI_COMM_NULL)
{
throw std::runtime_error("ParmParse::addfile: AMReX must be initialized");
}
#endif

// check the file exists and give a user-friendly error
if (ParallelDescriptor::IOProcessor())
{
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
FileExists(filename),
"ParmParse::addfile: file does not exist: " + filename
);
}

// add the file
auto file = FileKeyword;
std::vector<std::string> val{{filename}};
addDefn(file, val, g_table);
Expand Down

0 comments on commit 6c7668c

Please sign in to comment.