14#include "arcane/utils/ArcanePrecomp.h"
16#include "arcane/utils/ScopedPtr.h"
17#include "arcane/utils/StringBuilder.h"
18#include "arcane/utils/Convert.h"
20#include "arcane/core/ISubDomain.h"
21#include "arcane/core/EntryPoint.h"
22#include "arcane/core/Timer.h"
23#include "arcane/core/ITimeHistoryMng.h"
24#include "arcane/core/ModuleFactory.h"
25#include "arcane/core/ServiceUtils.h"
26#include "arcane/core/ICheckpointWriter.h"
27#include "arcane/core/ICheckpointMng.h"
28#include "arcane/core/Directory.h"
29#include "arcane/core/IParallelMng.h"
31#include "arcane/core/OutputChecker.h"
32#include "arcane/std/ArcaneCheckpoint_axl.h"
46class ArcaneCheckpointModule
47:
public ArcaneArcaneCheckpointObject
51 ArcaneCheckpointModule(
const ModuleBuilder& cb);
52 ~ArcaneCheckpointModule();
61 virtual void checkpointStartInit();
62 virtual void checkpointInit();
68 Timer* m_checkpoint_timer;
70 String m_checkpoint_dirname;
76 void _getCheckpointService();
77 void _setDirectoryName();
78 bool _checkHasOutput();
84ARCANE_REGISTER_MODULE_ARCANECHECKPOINT(ArcaneCheckpointModule);
89ArcaneCheckpointModule::
90ArcaneCheckpointModule(
const ModuleBuildInfo& mb)
92, m_output_checker(mb.subDomain(),
"CheckpointRestart")
93, m_checkpoint_timer(0)
94, m_checkpoint_writer(0)
95, m_checkpoint_dirname(
".")
97 m_checkpoint_timer =
new Timer(mb.subDomain(),
"Checkpoint",
Timer::TimerReal);
99 m_output_checker.assignGlobalTime(&m_next_global_time, &
options()->frequency);
100 m_output_checker.assignCPUTime(&m_next_cpu_time, &
options()->frequencyCpu);
106ArcaneCheckpointModule::
107~ArcaneCheckpointModule()
109 delete m_checkpoint_timer;
115void ArcaneCheckpointModule::
120 m_next_cpu_time =
options()->frequencyCpu();
121 info() <<
" -------------------------------------------";
122 info() <<
"| PROTECTION-REPRISE |";
123 info() <<
" -------------------------------------------";
128 m_output_checker.initialize();
132 if (
options()->doDumpAtEnd()) {
133 info() <<
"Protection required at the end of computations";
134 _getCheckpointService();
141bool ArcaneCheckpointModule::
149 bool do_output = m_output_checker.check(old_time, current_time, iteration, cpu_used);
156void ArcaneCheckpointModule::
159 m_next_global_time = 0.;
184 if (m_checkpoint_writer)
185 m_checkpoint_writer->close();
186 m_checkpoint_writer = 0;
192void ArcaneCheckpointModule::
197 info() <<
"Total time spent in protection output (second): " << total_time;
200 info() <<
"Average time per output (second): " << total_time / nb_time
201 <<
" (for " << nb_time <<
" outputs";
207void ArcaneCheckpointModule::
211 if (export_dir.path().null())
214 Directory output_directory = Directory(export_dir,
"protection");
216 if (pm->isMasterIO())
217 output_directory.createDirectory();
220 m_checkpoint_dirname = output_directory.path();
237 if (!m_checkpoint_writer)
238 _getCheckpointService();
239 if (m_checkpoint_writer) {
240 Integer nb_checkpoint = m_checkpoints_time.size();
241 m_checkpoints_time.resize(nb_checkpoint + 1);
243 m_checkpoints_time[nb_checkpoint] = checkpoint_time;
244 m_checkpoint_writer->setCheckpointTimes(m_checkpoints_time);
245 m_checkpoint_writer->setBaseDirectoryName(m_checkpoint_dirname);
246 info() <<
"**** Protection active at time " << checkpoint_time
247 <<
" directory=" << m_checkpoint_dirname
248 <<
" number " << nb_checkpoint <<
" ******";
252 info() <<
"Checkpoint write time (second): "
253 << m_checkpoint_timer->lastActivationTime();
263void ArcaneCheckpointModule::
264_getCheckpointService()
269 options()->checkpointService.getAvailableNames(valid_values);
270 pfatal() <<
"Protections required but protection/restore service selected ("
271 <<
options()->checkpointService.serviceName() <<
") not available "
272 <<
"(valid values: " << String::join(
", ", valid_values) <<
")";
274 m_checkpoint_writer = checkpoint;
288 bool do_output = _checkHasOutput();
292 info() <<
"Protection required.";
Generation de la classe de base du Module.
CaseOptionsArcaneCheckpoint * options() const
Options du jeu de données du module.
Arcane::VariableScalarInteger m_next_iteration
Variables du module.
ISubDomain * subDomain() const override
Sub-domain associated with the module.
IParallelMng * parallelMng() const override
Message passing parallelism manager.
virtual void checkpointCheckAndWriteData()
Checks if a checkpoint should be performed at this moment and performs it if necessary.
virtual VersionInfo versionInfo() const
Module version.
void _doCheckpoint(bool save_history)
Performs a checkpoint.
virtual void checkpointExit()
End-of-calculation operations.
VariableScalarInt32 m_global_iteration
Current iteration.
VariableScalarReal m_global_cpu_time
CPU time used (in seconds).
VariableScalarReal m_global_time
Current time.
VariableScalarReal m_global_old_time
Time previous to the current time.
virtual void writeDefaultCheckpoint(ICheckpointWriter *writer)=0
Writes a checkpoint using the writer.
Interface of the checkpoint/recovery write service.
virtual const IDirectory & storageDirectory() const =0
Base directory for exports requiring archiving.
virtual ICheckpointMng * checkpointMng() const =0
Protection manager.
virtual ITimeHistoryMng * timeHistoryMng()=0
Returns the history manager.
virtual const IDirectory & exportDirectory() const =0
Base directory for exports.
virtual void dumpHistory(bool is_verbose)=0
Saves the history.
Manages outputs based on physical time, CPU time, or a number of iterations.
Unicode character string.
Positions the phase of the currently executing action.
Sentinel for the timer. The sentinel associated with a timer allows it to be triggered upon its const...
Integer nbActivated() const
Returns the number of times the timer has been activated.
@ TimerReal
Timer using real time.
Real totalTime() const
Returns the total time (in seconds) spent in the timer.
TraceMessage pfatal() const
Flow for a parallel fatal error message.
TraceMessage info() const
Flow for an information message.
Information about a version.
Integer toInteger(Real r)
Converts a Real to Integer.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.
UniqueArray< String > StringUniqueArray
Dynamic 1D array of strings.