SST  14.1.0
StructuralSimulationToolkit
checkpointAction.h
1 // Copyright 2009-2024 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2024, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_CHECKPOINT_ACTION_H
13 #define SST_CORE_CHECKPOINT_ACTION_H
14 
15 #include "sst/core/action.h"
16 #include "sst/core/config.h"
17 #include "sst/core/cputimer.h"
18 #include "sst/core/output.h"
19 #include "sst/core/rankInfo.h"
20 #include "sst/core/sst_types.h"
21 #include "sst/core/threadsafe.h"
22 
23 #include <set>
24 
25 namespace SST {
26 
27 class Simulation_impl;
28 class TimeConverter;
29 
30 namespace Checkpointing {
31 /* Utility functions needed to manage directories */
32 
33 /**
34  Creates a directory of the specified basename. If a directory named
35  basename already exists, it will append an _N to the end,
36  incrementing N from 1 until it finds an unused name.
37  */
38 std::string createUniqueDirectory(const std::string basename);
39 
40 /**
41  Removes a directory. For safety, this will recurse and remove each
42  file individually instead of issuing an rm -r. It will not follow
43  links, but will simply remove the link.
44  */
45 void removeDirectory(const std::string name);
46 
47 /**
48  Initializes the infrastructure needed for checkpointing. Uses the
49  createUniqueDirectory() function to create the directory, then
50  broadcasts the name to all ranks.
51  */
52 std::string initializeCheckpointInfrastructure(Config* cfg, bool rt_can_ckpt, int myRank);
53 
54 } // namespace Checkpointing
55 
56 /**
57  \class CheckpointAction
58  A recurring event to trigger checkpoint generation
59 */
60 class CheckpointAction : public Action
61 {
62 public:
63  /**
64  Create a new checkpoint object for the simulation core to initiate checkpoints
65  */
66  CheckpointAction(Config* cfg, RankInfo this_rank, Simulation_impl* sim, TimeConverter* period);
68 
69  /** Generate a checkpoint next time check() is called */
70  void setCheckpoint();
71 
72  /** Called by TimeVortex to trigger checkpoint on simulation clock interval - not used in parallel simulation */
73  void execute(void) override;
74 
75  /** Called by SyncManager to check whether a checkpoint should be generated */
76  SimTime_t check(SimTime_t current_time);
77 
78  /** Return next checkpoint time */
79  SimTime_t getNextCheckpointSimTime();
80 
81  static Core::ThreadSafe::Barrier barrier;
82  static uint32_t checkpoint_id;
83 
84  NotSerializable(SST::CheckpointAction);
85 
86 private:
87  CheckpointAction() {}
89 
90  void operator=(CheckpointAction const&);
91  void createCheckpoint(Simulation_impl* sim); // The actual checkpoint operation
92 
93  RankInfo rank_; // RankInfo for this thread/rank
94  TimeConverter* period_; // Simulation time interval for scheduling or nullptr if not set
95  double last_cpu_time_; // Last time a checkpoint was triggered
96  bool generate_; // Whether a checkpoint should be done next time check() is called
97  SimTime_t next_sim_time_; // Next simulationt ime a checkpoint should trigger at or 0 if not applicable
98 };
99 
100 } // namespace SST
101 
102 #endif // SST_CORE_CHECKPOINT_ACTION_H
An Action is a schedulable Activity which is not an Event.
Definition: action.h:26
Class to contain SST Simulation Configuration variables.
Definition: config.h:38
A class to convert between a component&#39;s view of time and the core&#39;s view of time.
Definition: timeConverter.h:27
A recurring event to trigger checkpoint generation.
Definition: checkpointAction.h:60
Definition: action.cc:18
SimTime_t getNextCheckpointSimTime()
Return next checkpoint time.
Definition: checkpointAction.cc:212
SimTime_t check(SimTime_t current_time)
Called by SyncManager to check whether a checkpoint should be generated.
Definition: checkpointAction.cc:188
Main control class for a SST Simulation.
Definition: simulation_impl.h:76
Definition: rankInfo.h:21
void setCheckpoint()
Generate a checkpoint next time check() is called.
Definition: checkpointAction.cc:206
Definition: threadsafe.h:47
void execute(void) override
Called by TimeVortex to trigger checkpoint on simulation clock interval - not used in parallel simula...
Definition: checkpointAction.cc:76