14#include "arcane/utils/ArcanePrecomp.h"
16#include "arcane/utils/ScopedPtr.h"
17#include "arcane/utils/StringBuilder.h"
19#include "arcane/core/ISubDomain.h"
20#include "arcane/core/EntryPoint.h"
21#include "arcane/core/Timer.h"
22#include "arcane/core/ITimeHistoryMng.h"
23#include "arcane/core/ModuleFactory.h"
24#include "arcane/core/ServiceUtils.h"
25#include "arcane/core/ICheckpointWriter.h"
26#include "arcane/core/ICheckpointMng.h"
27#include "arcane/core/Directory.h"
28#include "arcane/core/IParallelMng.h"
30#include "arcane/core/OutputChecker.h"
31#include "arcane/std/ArcaneCheckpoint_axl.h"
45class ArcaneCheckpointModule
46:
public ArcaneArcaneCheckpointObject
50 ArcaneCheckpointModule(
const ModuleBuilder& cb);
51 ~ArcaneCheckpointModule();
60 virtual void checkpointStartInit();
61 virtual void checkpointInit();
67 Timer* m_checkpoint_timer;
69 String m_checkpoint_dirname;
75 void _getCheckpointService();
76 void _setDirectoryName();
77 bool _checkHasOutput();
83ARCANE_REGISTER_MODULE_ARCANECHECKPOINT(ArcaneCheckpointModule);
88ArcaneCheckpointModule::
89ArcaneCheckpointModule(
const ModuleBuildInfo& mb)
91, m_output_checker(mb.subDomain(),
"CheckpointRestart")
92, m_checkpoint_timer(0)
93, m_checkpoint_writer(0)
94, m_checkpoint_dirname(
".")
96 m_checkpoint_timer =
new Timer(mb.subDomain(),
"Checkpoint",
Timer::TimerReal);
98 m_output_checker.assignGlobalTime(&m_next_global_time, &
options()->frequency);
99 m_output_checker.assignCPUTime(&m_next_cpu_time, &
options()->frequencyCpu);
105ArcaneCheckpointModule::
106~ArcaneCheckpointModule()
108 delete m_checkpoint_timer;
114void ArcaneCheckpointModule::
119 m_next_cpu_time =
options()->frequencyCpu();
120 info() <<
" -------------------------------------------";
121 info() <<
"| PROTECTION-REPRISE |";
122 info() <<
" -------------------------------------------";
127 m_output_checker.initialize();
131 if (
options()->doDumpAtEnd()) {
132 info() <<
"Protection required at the end of computations";
133 _getCheckpointService();
140bool ArcaneCheckpointModule::
148 bool do_output = m_output_checker.check(old_time, current_time, iteration, cpu_used);
155void ArcaneCheckpointModule::
158 m_next_global_time = 0.;
183 if (m_checkpoint_writer)
184 m_checkpoint_writer->close();
185 m_checkpoint_writer = 0;
191void ArcaneCheckpointModule::
196 info() <<
"Total time spent in protection output (second): " << total_time;
199 info() <<
"Average time per output (second): " << total_time / nb_time
200 <<
" (for " << nb_time <<
" outputs";
206void ArcaneCheckpointModule::
210 if (export_dir.path().null())
213 Directory output_directory = Directory(export_dir,
"protection");
215 if (pm->isMasterIO())
216 output_directory.createDirectory();
219 m_checkpoint_dirname = output_directory.path();
236 if (!m_checkpoint_writer)
237 _getCheckpointService();
238 if (m_checkpoint_writer) {
239 Integer nb_checkpoint = m_checkpoints_time.size();
240 m_checkpoints_time.resize(nb_checkpoint + 1);
242 m_checkpoints_time[nb_checkpoint] = checkpoint_time;
243 m_checkpoint_writer->setCheckpointTimes(m_checkpoints_time);
244 m_checkpoint_writer->setBaseDirectoryName(m_checkpoint_dirname);
245 info() <<
"**** Protection active at time " << checkpoint_time
246 <<
" directory=" << m_checkpoint_dirname
247 <<
" number " << nb_checkpoint <<
" ******";
251 info() <<
"Checkpoint write time (second): "
252 << m_checkpoint_timer->lastActivationTime();
262void ArcaneCheckpointModule::
263_getCheckpointService()
268 options()->checkpointService.getAvailableNames(valid_values);
269 pfatal() <<
"Protections required but protection/restore service selected ("
270 <<
options()->checkpointService.serviceName() <<
") not available "
271 <<
"(valid values: " << String::join(
", ", valid_values) <<
")";
273 m_checkpoint_writer = checkpoint;
287 bool do_output = _checkHasOutput();
291 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.