-
Notifications
You must be signed in to change notification settings - Fork 3
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
Constellation checkpointing #129
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,7 +8,10 @@ | |||||
|
||||||
#include "HDF5Definitions.h" | ||||||
|
||||||
HDF5Writer::HDF5Writer(const std::string &filename, bool replace, unsigned int compressionLevel) | ||||||
HDF5Writer::HDF5Writer(const std::string &filename, | ||||||
bool replace, | ||||||
unsigned int compressionLevel, | ||||||
const std::set<size_t> &alreadyExistingIds) | ||||||
#ifdef LADDS_HDF5 | ||||||
: _file(filename, replace ? h5pp::FilePermission::REPLACE : h5pp::FilePermission::READWRITE), | ||||||
collisionInfoH5Type(H5Tcreate(H5T_COMPOUND, sizeof(HDF5Definitions::CollisionInfo))), | ||||||
|
@@ -20,6 +23,13 @@ HDF5Writer::HDF5Writer(const std::string &filename, bool replace, unsigned int c | |||||
if (replace) { | ||||||
_file.setCompressionLevel(compressionLevel); | ||||||
} | ||||||
|
||||||
// add ids of previous checkpoint to list of existing particle ids in order to avoid adding duplicate | ||||||
// constantProperties | ||||||
for (auto &id : alreadyExistingIds) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
addedConstantPropertiesIds.insert(static_cast<HDF5Definitions::IntType>(id)); | ||||||
} | ||||||
|
||||||
// CollisionInfo | ||||||
H5Tinsert(collisionInfoH5Type, | ||||||
"idA", | ||||||
|
@@ -75,7 +85,6 @@ void HDF5Writer::writeParticles(size_t iteration, const AutoPas_t &autopas) { | |||||
std::vector<HDF5Definitions::Vec3<HDF5Definitions::FloatType>> vecPos; | ||||||
std::vector<HDF5Definitions::Vec3<HDF5Definitions::FloatType>> vecVel; | ||||||
std::vector<HDF5Definitions::IntType> vecId; | ||||||
HDF5Definitions::IntType maxParticleId{0}; | ||||||
std::vector<HDF5Definitions::ParticleConstantProperties> newConstantProperties; | ||||||
|
||||||
vecPos.reserve(autopas.getNumberOfParticles()); | ||||||
|
@@ -96,11 +105,10 @@ void HDF5Writer::writeParticles(size_t iteration, const AutoPas_t &autopas) { | |||||
static_cast<HDF5Definitions::FloatType>(vel[1]), | ||||||
static_cast<HDF5Definitions::FloatType>(vel[2])}); | ||||||
vecId.emplace_back(id); | ||||||
// track the highest particle id that was written to the file | ||||||
// All particles that have a higher id than the highest id from the last time something was written are new | ||||||
// and their static properties need to be recorded. | ||||||
maxParticleId = std::max(maxParticleId, id); | ||||||
if (maxWrittenParticleID == 0 or id > maxWrittenParticleID) { | ||||||
|
||||||
// only add properties not yet added | ||||||
if (addedConstantPropertiesIds.find(id) == addedConstantPropertiesIds.end()) { | ||||||
addedConstantPropertiesIds.insert(id); | ||||||
Comment on lines
+110
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't this potentially expensive? We do this if for every particle (O(N)) and the find is in O(log(M)) where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is :( I can add a comment |
||||||
newConstantProperties.emplace_back( | ||||||
HDF5Definitions::ParticleConstantProperties{id, | ||||||
particle.getIdentifier().c_str(), | ||||||
|
@@ -127,7 +135,6 @@ void HDF5Writer::writeParticles(size_t iteration, const AutoPas_t &autopas) { | |||||
_file.appendTableRecords(newConstantProperties, particleConstantPropertiesFullPath); | ||||||
} | ||||||
|
||||||
maxWrittenParticleID = maxParticleId; | ||||||
#endif | ||||||
} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -29,7 +29,10 @@ class HDF5Writer final : public ConjuctionWriterInterface { | |||||
* @param replace if true replace an existing file, else append. | ||||||
* @param compressionLevel | ||||||
*/ | ||||||
HDF5Writer(const std::string &filename, bool replace, unsigned int compressionLevel); | ||||||
HDF5Writer(const std::string &filename, | ||||||
bool replace, | ||||||
unsigned int compressionLevel, | ||||||
const std::set<size_t> &alreadyExistingIds); | ||||||
|
||||||
~HDF5Writer() override = default; | ||||||
|
||||||
|
@@ -49,10 +52,10 @@ class HDF5Writer final : public ConjuctionWriterInterface { | |||||
|
||||||
private: | ||||||
/** | ||||||
* Highest partilce ID that was written in any previous iteration. | ||||||
* For anything below this ID constant particle properties are already written. | ||||||
* Contains particle IDs in order to add a particles constantProperties only once. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Is this correct? Maybe rename it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is technically not true during the execution of |
||||||
*/ | ||||||
HDF5Definitions::IntType maxWrittenParticleID{0}; | ||||||
std::set<HDF5Definitions::IntType> addedConstantPropertiesIds{}; | ||||||
|
||||||
#ifdef LADDS_HDF5 | ||||||
/** | ||||||
* Actual file that will be created. All of the data this writer gets ends up in this one file. | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,11 @@ Constellation::Constellation(ConfigReader &constellationConfig, ConfigReader &co | |
schedule[i].push_back(timestamps[i] + j * timeStepSize); | ||
} | ||
} | ||
|
||
// if checkpoint is loaded, throw away already inserted satellites | ||
if (config.defines("io/hdf5/checkpoint/file")) { | ||
tick(config.get<size_t>("io/hdf5/checkpoint/iteration", -1, true)); | ||
} | ||
Comment on lines
+73
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add some more explanatory comments here? I don't fully get this. So if a checkpoint is used you call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I needed the
Is there actually a case where the -1 (+1) becomes relevant? Because if a checkpoint is used, but no iteration is given, the highest iteration found in the checkpoint is always loaded right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I casted |
||
} | ||
|
||
void Constellation::setStartTime(const std::string &startTimeStr, const std::string &refTimeStr) { | ||
|
@@ -95,7 +100,7 @@ void Constellation::setDuration(const std::string &durationStr) { | |
} | ||
} | ||
|
||
std::vector<Particle> Constellation::tick() { | ||
std::vector<Particle> Constellation::tick(size_t simulationTime) { | ||
std::vector<Particle> particles{}; | ||
switch (status) { | ||
case Status::deployed: | ||
|
@@ -135,7 +140,6 @@ std::vector<Particle> Constellation::tick() { | |
timeActive += interval; | ||
break; | ||
} | ||
simulationTime += interval; | ||
return particles; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ class Constellation { | |
* and linearly over time. | ||
* @return std::vector<Particle> : satellites to be added to the simulation. | ||
*/ | ||
std::vector<Particle> tick(); | ||
std::vector<Particle> tick(size_t simulationTime); | ||
Comment on lines
38
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doc for new parameter missing |
||
|
||
/** | ||
* Offsets all local constellation IDs by the parameter baseId to create global IDs. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why don't you rename the parameter to
iteration
then?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to more stress that this is in the time unit of the simulation. But I think you are right iteration also makes it clear and is less confusing :D