Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParmParse: Prefix to FILE #4126

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 14 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,19 @@ 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_c = std::getenv("AMREX_INPUTS_FILE_PREFIX");
if (amrex_inputs_file_prefix_c != nullptr) {
// we expect a directory path as the prefix: append a trailing "/" if missing
auto amrex_inputs_file_prefix = std::string(amrex_inputs_file_prefix_c);
if (amrex_inputs_file_prefix.back() != '/') {
amrex_inputs_file_prefix += "/";
}
filename = amrex_inputs_file_prefix + filename;
}

#ifdef AMREX_USE_MPI
if (ParallelDescriptor::Communicator() == MPI_COMM_NULL)
{
Expand All @@ -415,7 +429,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
Loading