Skip to content

Commit

Permalink
Fix checkpointing, see ComputationalRadiationPhysics#3977
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Feb 9, 2022
1 parent 9c96339 commit 56a588b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
3 changes: 2 additions & 1 deletion include/picongpu/plugins/openPMD/openPMDWriter.def
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <limits>
#include <list>
#include <memory> // std::unique_ptr
#include <optional>
#include <sstream>
#include <stdexcept> // throw std::runtime_error
#include <string>
Expand Down Expand Up @@ -124,7 +125,7 @@ namespace picongpu
/*
* If file is empty, read from command line parameters.
*/
void initFromConfig(Help&, size_t id, std::string const& dir, std::string const& file = "");
void initFromConfig(Help&, size_t id, std::string const& dir, std::optional<std::string> file = {});

/**
* Wrapper for ::openPMD::resetDataset, set dataset parameters
Expand Down
33 changes: 27 additions & 6 deletions include/picongpu/plugins/openPMD/openPMDWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,11 @@ make sure that environment variable OPENPMD_BP_BACKEND is not set to ADIOS1.
std::string const prefix = "openPMD";
};

void ThreadParams::initFromConfig(Help& help, size_t id, std::string const& dir, std::string const& file)
void ThreadParams::initFromConfig(
Help& help,
size_t id,
std::string const& dir,
std::optional<std::string> file)
{
std::string strategyString;
std::string jsonString;
Expand All @@ -373,23 +377,40 @@ make sure that environment variable OPENPMD_BP_BACKEND is not set to ADIOS1.
}
case ConfigurationVia::CommandLine:
{
if(!file.has_value())
{
/*
* If file is empty, then the openPMD plugin is running as a normal IO plugin.
* In this case, read the file from command line parameters.
* If there is a filename, it is running as a checkpoint and the filename
* has been supplied from outside.
* We must not read it from the command line since it's not there.
* Reason: A checkpoint is triggered by writing something like:
* > --checkpoint.file asdf --checkpoint.period 100
* ... and NOT by something like:
* > --checkpoint.openPMD.file asdf --checkpoint.period 100
*/
/* if file name is relative, prepend with common directory */
fileName = help.fileName.get(id);
}

/*
* These two however should always be read because they have default values.
*/
fileExtension = help.fileNameExtension.get(id);
fileInfix = help.fileNameInfix.get(id);
/* if file name is relative, prepend with common directory */
fileName = help.fileName.get(id);


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

if(not file.empty())
if(file.has_value())
{
// If file was specified as function parameter (i.e. when checkpointing), ignore command line
// parameters for it
fileName = file;
fileName = file.value();
}

fileName = boost::filesystem::path(fileName).has_root_path() ? fileName : dir + "/" + fileName;
Expand Down

0 comments on commit 56a588b

Please sign in to comment.