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 058838a
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions Src/Base/AMReX_ParmParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <limits>
Expand Down Expand Up @@ -1070,28 +1069,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 058838a

Please sign in to comment.