Skip to content

Commit

Permalink
ParmParse: Prefix to FILE
Browse files Browse the repository at this point in the history
For CI/CD workflows and out-of-source tests we often want to include
dependent inputs files via `FILE = <filename>`. For development, we
often want to run in temporary run directories but want to avoid
having to copy over the latest inputs file from a source directory.

Now, the environment variable `AMREX_INPUTS_FILE_PREFIX`
can be set to prefix every `FILE = <filename>` with a custom path.
We will use this in the CTests integration of WarpX.
  • Loading branch information
ax3l committed Sep 3, 2024
1 parent de4dc97 commit 59bb1cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Src/Base/AMReX_ParmParse.H
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class RealVect;
// '\n's. The "FILE = <filename>" definition is special. Rather than just
// adding this entry to the database, it reads the contents of <filename>
// into the database.
// For CI/CD workflows and out-of-source tests, the environment variable
// AMREX_INPUTS_FILE_PREFIX can be set to prefix every FILE = <filename>
// with a custom path.
//
// ParmParse stores all entries in a static table which is built the
// first time a ParmParse object is constructed (usually in main()).
Expand Down
10 changes: 9 additions & 1 deletion Src/Base/AMReX_ParmParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <numeric>
Expand Down Expand Up @@ -407,6 +408,14 @@ read_file (const char* fname, ParmParse::Table& tab)
//
if ( fname != nullptr && fname[0] != 0 )
{
std::string filename = fname;

// optional prefix to search files in
char const *amrex_inputs_file_prefix = std::getenv("AMREX_INPUTS_FILE_PREFIX");
if (amrex_inputs_file_prefix != nullptr) {
filename = std::string(amrex_inputs_file_prefix) + filename;
}

#ifdef AMREX_USE_MPI
if (ParallelDescriptor::Communicator() == MPI_COMM_NULL)
{
Expand All @@ -415,7 +424,6 @@ read_file (const char* fname, ParmParse::Table& tab)
#endif

Vector<char> fileCharPtr;
std::string filename = fname;
ParallelDescriptor::ReadAndBcastFile(filename, fileCharPtr);

std::istringstream is(fileCharPtr.data());
Expand Down

0 comments on commit 59bb1cd

Please sign in to comment.