Skip to content

Commit 4e937bc

Browse files
authored
Fix bug in Tests/ParmParse (AMReX-Codes#5324)
1 parent 51285c1 commit 4e937bc

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

Src/Base/AMReX_ParmParse.H

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,9 @@ public:
17241724
//! duplicates, only the last one is printed.
17251725
static void prettyPrintUsedInputs (std::ostream& os);
17261726

1727-
//! Add keys and values from a file to the end of the PP table.
1727+
//! Add keys and values from a file to the end of the PP table. This
1728+
//! function must be called on all MPI processes because it contains a
1729+
//! call to MPI_Bcast.
17281730
static void addfile (std::string const& filename);
17291731

17301732
static bool QueryUnusedInputs ();

Tests/ParmParse/GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AMREX_HOME ?= ../../amrex
1+
AMREX_HOME ?= ../..
22

33
DEBUG = TRUE
44

Tests/ParmParse/main.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int main(int argc, char* argv[])
4141
std::vector<std::string> sa;
4242
std::vector<std::string> sb;
4343
pp.getarr("sa", sa);
44-
pp.getarr("sa", sb);
44+
pp.getarr("sb", sb);
4545
AMREX_ALWAYS_ASSERT(sa == sb && (sa == std::vector<std::string>{"abc","xyz","123"}));
4646

4747
IntVect iv;
@@ -325,25 +325,28 @@ int main(int argc, char* argv[])
325325
AMREX_ALWAYS_ASSERT(s == sv[i]);
326326
}
327327
}
328-
if (ParallelDescriptor::IOProcessor()) // print & addfile
328+
329+
// print & addfile
329330
{
330-
{
331-
ParmParse pp;
332-
pp.add("string-for-testing-addfile", "string for testing addfile");
333-
pp.add("string-for-testing-addfile", "string for testing addfile");
334-
int n = pp.countname("string-for-testing-addfile");
335-
AMREX_ALWAYS_ASSERT(n==2);
336-
}
331+
ParmParse pp;
332+
pp.add("string-for-testing-addfile", "string for testing addfile");
333+
pp.add("string-for-testing-addfile", "string for testing addfile");
334+
int n = pp.countname("string-for-testing-addfile");
335+
AMREX_ALWAYS_ASSERT(n==2);
336+
}
337+
if (ParallelDescriptor::IOProcessor()) {
337338
std::ofstream ofs("my-inputs");
338339
ParmParse::prettyPrintTable(ofs);
339-
ofs.close();
340+
}
341+
{
340342
ParmParse::addfile("my-inputs");
341343
std::string s;
342344
ParmParse pp;
343345
pp.get("string-for-testing-addfile", s);
344346
int n = pp.countname("string-for-testing-addfile");
345347
AMREX_ALWAYS_ASSERT(n==3 && s == "string for testing addfile");
346348
}
349+
347350
{ // UNSET directive
348351
ParmParse pp;
349352
// "unset_me" is defined then immediately unset in the inputs file

0 commit comments

Comments
 (0)