Skip to content

Commit

Permalink
Read regular plugin options from TOML
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Oct 14, 2021
1 parent ffd5419 commit 8e7273d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
9 changes: 5 additions & 4 deletions include/picongpu/plugins/openPMD/openPMDWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,20 +399,21 @@ make sure that environment variable OPENPMD_BP_BACKEND is not set to ADIOS1.
fileExtension = help.fileNameExtension.get(id);
fileInfix = help.fileNameInfix.get(id);
/* if file name is relative, prepend with common directory */
fileName = boost::filesystem::path(file).has_root_path() ? file : dir + "/" + file;

fileName = file;
// avoid deadlock between not finished pmacc tasks and mpi blocking collectives
__getTransactionEvent().waitForFinished();

log<picLog::INPUT_OUTPUT>("openPMD: setting file pattern: %1%%2%.%3%") % fileName % fileInfix
% fileExtension;

strategyString = help.dataPreparationStrategy.get(id);
jsonString = help.jsonConfig.get(id);
break;
}
}

fileName = boost::filesystem::path(file).has_root_path() ? fileName : dir + "/" + fileName;
log<picLog::INPUT_OUTPUT>("openPMD: setting file pattern: %1%%2%.%3%") % fileName % fileInfix
% fileExtension;

/*
* Enforce group-based iteration layout for streaming backends
*/
Expand Down
47 changes: 39 additions & 8 deletions include/picongpu/plugins/openPMD/toml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,44 @@ namespace
return res;
}

Period_t parseTomlFile(std::string const& content, std::string const& file = "unknown file")
void parsePluginOptions(picongpu::toml::PluginOptions & options, toml::value tomlConfig)
{
auto parseOption = [&tomlConfig](std::string& target, std::string const& key) {
if(not tomlConfig.contains(key))
{
return; // leave the default option
}
try
{
target = toml::find<std::string>(tomlConfig, key);
}
catch(toml::type_error const& e)
{
throw std::runtime_error(
"[openPMD plugin] Global key '" + key + "' must point to a value of string type.");
}
};

parseOption( options.fileName, "file" );
parseOption( options.fileInfix, "infix" );
parseOption( options.fileExtension, "ext" );
parseOption( options.jsonConfig, "backend_config" );
parseOption( options.dataPreparationStrategy, "data_preparation_strategy" );
}

void parseTomlFile(
picongpu::toml::DataSources& dataSources,
std::string const& content,
std::string const& file = "unknown file")
{
auto data = [&content, &file]() {
std::istringstream istream(content.c_str());
return toml::parse(istream, file);
}();
if(not data.contains("sink"))
{
return {};
return;
}
Period_t res;
auto& sinkTable = [&data]() -> toml::value::table_type const& {
try
{
Expand Down Expand Up @@ -175,13 +202,17 @@ namespace
"[openPMD plugin] Key 'period' in TOML file must be a table (" + std::string(e.what()) + ")");
}
}();
mergePeriodTable(res, parseSinglePeriodTable(periodTable));
mergePeriodTable(dataSources.m_period, parseSinglePeriodTable(periodTable));
}
return res;
parsePluginOptions( dataSources.openPMDPluginOptions, data );
}

template<typename ChronoDuration>
Period_t waitForParseAndMergeTomlFiles(std::string const path, ChronoDuration&& sleepInterval, MPI_Comm comm)
void waitForParseAndMergeTomlFiles(
picongpu::toml::DataSources& dataSources,
std::string const path,
ChronoDuration&& sleepInterval,
MPI_Comm comm)
{
int rank;
MPI_Comm_rank(comm, &rank);
Expand All @@ -206,7 +237,7 @@ namespace
picongpu::toml::writeLog("openPMD: Reading TOML file collectively");
std::string fileContents = picongpu::collective_file_read(path, comm);

return parseTomlFile(fileContents, path);
parseTomlFile(dataSources, fileContents, path);
}
} // namespace

Expand All @@ -219,8 +250,8 @@ namespace picongpu
constexpr std::chrono::seconds const WAIT_TIME = 5s;

DataSources::DataSources(std::string const& tomlFile, MPI_Comm comm)
: m_period{waitForParseAndMergeTomlFiles(tomlFile, WAIT_TIME, comm)}
{
waitForParseAndMergeTomlFiles(*this, tomlFile, WAIT_TIME, comm);
// todo: read from toml files
// verify that a step will always be available
m_upcomingSteps[0].reserve(m_period.size());
Expand Down
4 changes: 2 additions & 2 deletions include/picongpu/plugins/openPMD/toml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ namespace picongpu
using Period_t = std::map<SimulationStep_t, std::set<std::string>>;

private:
Period_t m_period;

/*
* For each period p, let s be the upcoming step divisible by p.
* Then m_nextActiveAt[s] contains p.
*/
std::map<SimulationStep_t, std::vector<SimulationStep_t>> m_upcomingSteps;

public:
Period_t m_period;

PluginOptions openPMDPluginOptions; // @todo read these from TOML

DataSources(std::string const& tomlFile, MPI_Comm);
Expand Down

0 comments on commit 8e7273d

Please sign in to comment.