Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
ax3l committed Sep 18, 2024
1 parent 41d0284 commit 0e2b8cb
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions Src/Base/AMReX_ParmParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,28 +1070,21 @@ 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
int file_exists = int(false);
// check the file exists and give a user-friendly error
if (ParallelDescriptor::IOProcessor())
{
if (std::FILE *fp = std::fopen(filename.c_str(), "r")) {
fclose(fp);
file_exists = int(true);
}
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
FileExists(filename),
"ParmParse::addfile: file does not exist: " + filename
);
}
amrex::ParallelDescriptor::Bcast(
&file_exists,
1,
amrex::ParallelDescriptor::IOProcessorNumber()
);
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(bool(file_exists),
"ParmParse::addfile: file does not exist: " + filename);

// add the file
auto file = FileKeyword;
Expand Down

0 comments on commit 0e2b8cb

Please sign in to comment.