Skip to content

Commit 6bbde4f

Browse files
committed
Make pmacc checkpointing class
Moves checkpointing simulation control in its own class Checkpoint class now has a compile time toggle to disable checkpoint/restart functionality Simplified restart state management and changed from using bools to an enum tracking state
1 parent aab61db commit 6bbde4f

File tree

5 files changed

+519
-263
lines changed

5 files changed

+519
-263
lines changed

include/picongpu/simulation/control/Simulation.hpp

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "picongpu/random/seed/ISeed.hpp"
4040
#include "picongpu/simulation/control/DomainAdjuster.hpp"
4141
#include "picongpu/simulation/control/MovingWindow.hpp"
42+
#include "picongpu/simulation/control/checkpointingState.hpp"
4243
#include "picongpu/simulation/stage/AtomicPhysics.hpp"
4344
#include "picongpu/simulation/stage/Collision.hpp"
4445
#include "picongpu/simulation/stage/CurrentBackground.hpp"
@@ -69,6 +70,7 @@
6970
#include <pmacc/particles/traits/FilterByIdentifier.hpp>
7071
#include <pmacc/random/RNGProvider.hpp>
7172
#include <pmacc/random/methods/methods.hpp>
73+
#include <pmacc/simulationControl/Checkpointing.hpp>
7274
#include <pmacc/simulationControl/SimulationHelper.hpp>
7375
#include <pmacc/types.hpp>
7476
#include <pmacc/verify.hpp>
@@ -91,6 +93,8 @@ namespace picongpu
9193
{
9294
using namespace pmacc;
9395

96+
using SimHelper = SimulationHelper<simDim, simulationControl::Checkpointing<checkpointingEnabled>>;
97+
9498
/**
9599
* Global simulation controller class.
96100
*
@@ -99,7 +103,7 @@ namespace picongpu
99103
*
100104
* @tparam DIM the dimension (2-3) for the simulation
101105
*/
102-
class Simulation : public SimulationHelper<simDim>
106+
class Simulation : public SimHelper
103107
{
104108
public:
105109
/**
@@ -109,7 +113,7 @@ namespace picongpu
109113

110114
void pluginRegisterHelp(po::options_description& desc) override
111115
{
112-
SimulationHelper<simDim>::pluginRegisterHelp(desc);
116+
SimHelper::pluginRegisterHelp(desc);
113117

114118
// clang-format off
115119
desc.add_options()(
@@ -159,7 +163,7 @@ namespace picongpu
159163
void startSimulation() override
160164
{
161165
if(!skipSimulation)
162-
SimulationHelper<simDim>::startSimulation();
166+
SimHelper::startSimulation();
163167
}
164168

165169
nlohmann::json metadata() const
@@ -283,7 +287,7 @@ namespace picongpu
283287
log<picLog::DOMAINS>("rank %1%; localsize %2%; localoffset %3%;") % myGPUpos.toString()
284288
% gridSizeLocal.toString() % gridOffset.toString();
285289

286-
SimulationHelper<simDim>::pluginLoad();
290+
SimHelper::pluginLoad();
287291

288292
GridLayout<simDim> layout(gridSizeLocal, GuardSize::toRT() * SuperCellSize::toRT());
289293
cellDescription = std::make_unique<MappingDesc>(layout.sizeND(), DataSpace<simDim>(GuardSize::toRT()));
@@ -304,7 +308,7 @@ namespace picongpu
304308
{
305309
DataConnector& dc = Environment<>::get().DataConnector();
306310

307-
SimulationHelper<simDim>::pluginUnload();
311+
SimHelper::pluginUnload();
308312

309313
/** unshare all registered ISimulationData sets
310314
*
@@ -456,36 +460,10 @@ namespace picongpu
456460
if(initialiserController)
457461
{
458462
initialiserController->printInformation();
459-
if(this->restartRequested)
460-
{
461-
/* we do not require '--checkpoint.restart.step' if a master checkpoint file is found */
462-
if(this->restartStep < 0)
463-
{
464-
std::vector<uint32_t> checkpoints = readCheckpointMasterFile();
465-
466-
if(checkpoints.empty())
467-
{
468-
if(this->tryRestart == false)
469-
{
470-
throw std::runtime_error(
471-
"Restart failed. You must provide the "
472-
"'--checkpoint.restart.step' argument. See picongpu --help.");
473-
}
474-
else
475-
{
476-
// no checkpoint found: start simulation from scratch
477-
this->restartRequested = false;
478-
}
479-
}
480-
else
481-
this->restartStep = checkpoints.back();
482-
}
483-
}
484-
485-
if(this->restartRequested)
463+
if(this->checkpointing.checkRestart(step))
486464
{
487-
initialiserController->restart((uint32_t) this->restartStep, this->restartDirectory);
488-
step = this->restartStep;
465+
step = static_cast<uint32_t>(this->checkpointing.getRestartStep());
466+
initialiserController->restart(step, this->checkpointing.getRestartDir());
489467
}
490468
else
491469
{
@@ -547,13 +525,13 @@ namespace picongpu
547525
void dumpOneStep(uint32_t currentStep) override
548526
{
549527
fieldBackground->toDumpState(currentStep);
550-
SimulationHelper<simDim>::dumpOneStep(currentStep);
528+
SimHelper::dumpOneStep(currentStep);
551529
}
552530

553531
void notifyPlugins(uint32_t currentStep) override
554532
{
555533
fieldBackground->toPluginState(currentStep);
556-
SimulationHelper<simDim>::notifyPlugins(currentStep);
534+
SimHelper::notifyPlugins(currentStep);
557535
}
558536

559537
void movingWindowCheck(uint32_t currentStep) override
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* Copyright 2025 Tapish Narwal
2+
*
3+
* This file is part of PIConGPU.
4+
*
5+
* PIConGPU is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* PIConGPU is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with PIConGPU.
17+
* If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#pragma once
21+
22+
namespace picongpu
23+
{
24+
static constexpr bool checkpointingEnabled =
25+
#if (ENABLE_OPENPMD == 1)
26+
true;
27+
#else
28+
false;
29+
#endif
30+
} // namespace picongpu

0 commit comments

Comments
 (0)