Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
DefaultBackwardMng.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* DefaultBackwardMng.cc (C) 2000-2016 */
9/* */
10/* Implémentation par défaut d'une stratégie de retour-arrière. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/impl/DefaultBackwardMng.h"
15
16#include "arcane/IVariableFilter.h"
17#include "arcane/IVariable.h"
18#include "arcane/IVariableMng.h"
19#include "arcane/ISubDomain.h"
20#include "arcane/IParallelMng.h"
21#include "arcane/CommonVariables.h"
22#include "arcane/Timer.h"
23#include "arcane/VariableCollection.h"
24
25#include "arcane/utils/ITraceMng.h"
26
27#include "arcane/impl/MemoryDataReaderWriter.h"
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32ARCANE_BEGIN_NAMESPACE
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
38: public IVariableFilter
39{
40public:
41
42 virtual bool applyFilter(IVariable& var)
43 {
44 if (!var.isUsed())
45 return false;
46 if (var.property() & (IVariable::PTemporary|IVariable::PNoRestore))
47 return false;
48 return true;
49 }
50};
51
52/*---------------------------------------------------------------------------*/
53/*---------------------------------------------------------------------------*/
54
55DefaultBackwardMng::
56DefaultBackwardMng(ITraceMng* trace,ISubDomain* sub_domain)
57: m_trace(trace)
58, m_sub_domain(sub_domain)
59, m_filter(0)
60, m_data_io(0)
61, m_backward_time(-1)
62, m_period(0)
63, m_first_save(true)
64, m_action_refused(true)
65, m_sequence(SEQNothing)
66{
67 ARCANE_ASSERT((m_trace),("ITraceMng pointer null"));
68 ARCANE_ASSERT((m_sub_domain),("ISubDomain pointer null"));
69
70 m_filter = new RestoreVariableFilter();
71
72 m_data_io = new MemoryDataReaderWriter(trace);
73}
74
75/*---------------------------------------------------------------------------*/
76/*---------------------------------------------------------------------------*/
77
78DefaultBackwardMng::
79~DefaultBackwardMng()
80{
81 delete m_filter;
82
83 delete m_data_io;
84}
85
86/*---------------------------------------------------------------------------*/
87/*---------------------------------------------------------------------------*/
88
90clear()
91{
92 m_data_io->free();
93}
94
95/*---------------------------------------------------------------------------*/
96/*---------------------------------------------------------------------------*/
97
100{
101 if (!m_action_refused){
102 m_trace->pfatal() << "Trying to go backward during an action phase";
103 }
104
105 // Si déjà en train de faire un retour arrière, on ne peut pas continuer
106 if (m_sequence == SEQRestore) {
107 m_trace->pfatal() << "Impossible to go backward while it is already going backward";
108 }
109
111
112 m_trace->info() << "Execution of the backward mode !";
113}
114
115/*---------------------------------------------------------------------------*/
116/*---------------------------------------------------------------------------*/
117
118void DefaultBackwardMng::
119_checkValidAction()
120{
122 throw FatalErrorException(A_FUNCINFO,"Action requested outside the authorized period");
123}
124
125/*---------------------------------------------------------------------------*/
126/*---------------------------------------------------------------------------*/
127
130{
131 _checkValidAction();
133 _restore();
134 return true;
135 }
136 return false;
137}
138
139/*---------------------------------------------------------------------------*/
140/*---------------------------------------------------------------------------*/
141
144{
145 _checkValidAction();
146 m_action_refused = true;
147 _checkSave(is_forced);
148 if (m_sequence==SEQSave){
149 _save();
150 return true;
151 }
152
154 m_trace->info() << "Physical time of the last backward reached or passed. Save is forced";
155 _save();
156 return true;
157 }
158
159 return false;
160}
161
162/*---------------------------------------------------------------------------*/
163/*---------------------------------------------------------------------------*/
164
165void DefaultBackwardMng::
166_restore()
167{
168 m_backward_time = m_sub_domain->commonVariables().globalTime();
169
170 m_sub_domain->variableMng()->readVariables(m_data_io,m_filter);
171
173}
174
175/*---------------------------------------------------------------------------*/
176/*---------------------------------------------------------------------------*/
177
178void DefaultBackwardMng::
179_save()
180{
181 Timer::Action ts_action(m_sub_domain,"RestoreSave");
182
183 m_trace->info() << "Saving variable before going backward";
184
185 m_sub_domain->variableMng()->writeVariables(m_data_io,m_filter);
186
188
189 m_backward_time = -1.;
190
191 const Real var_mem = m_sub_domain->variableMng()->exportSize(VariableList());
192 const Real max_var_mem = m_sub_domain->parallelMng()->reduce(Parallel::ReduceMax,var_mem);
193
194 m_trace->info() << "Memory allocated for the variables (in Mo): used="
195 << var_mem << " max=" << max_var_mem;
196
197 m_first_save = false;
198}
199
200/*---------------------------------------------------------------------------*/
201/*---------------------------------------------------------------------------*/
202
205{
207 {
208 m_trace->pfatal() << "Begin of action requested before the end";
209 }
210
211 m_action_refused = false;
212}
213
214/*---------------------------------------------------------------------------*/
215/*---------------------------------------------------------------------------*/
216
217void DefaultBackwardMng::
218_checkSave(bool is_forced)
219{
220 if (m_period == 0) {
222 return;
223 }
224
225 if (m_sequence == SEQRestore)
226 return;
227
228 const Real time = m_sub_domain->commonVariables().globalTime();
229
230 if (m_backward_time >= 0. && m_backward_time < time) {
232 return;
233 }
234
235 // Ne sauve pas les infos tant que le retour-arrière est actif
236 if (m_backward_time >= 0.) {
238 return;
239 }
240
241 const Integer iteration = m_sub_domain->commonVariables().globalIteration();
242
243 bool do_save = false;
244
245 if (iteration > 1){
246 do_save |= m_first_save;
247 do_save |= (iteration % m_period) == 0;
248 }
249
250 if (is_forced)
251 do_save = true;
252
253 if(do_save) {
255 }
256 else {
258 }
259}
260
261/*---------------------------------------------------------------------------*/
262/*---------------------------------------------------------------------------*/
263
265endAction()
266{
267}
268
269/*---------------------------------------------------------------------------*/
270/*---------------------------------------------------------------------------*/
271
272ARCANE_END_NAMESPACE
273
274/*---------------------------------------------------------------------------*/
275/*---------------------------------------------------------------------------*/
276
virtual bool checkAndApplyRestore() override
Vérifie et applique la restauration si nécessaire.
virtual bool checkAndApplySave(bool is_forced) override
Vérifie et applique la sauvegarde des variables si nécessaire. Si is_forced est vrai,...
void beginAction() override
Indique qu'on commence les actions de sauvegarde/restauration sont terminées.
void endAction() override
Indique que les actions de sauvegarde/restauration sont terminées.
void clear() override
Supprime les ressources associées au retour-arrière.
Integer m_period
Période entre deux sauvegardes pour le retour-arrière.
void goBackward() override
Signale qu'on souhaite effectué un retour arrière.
bool m_action_refused
Actions authorisées ?
Real m_backward_time
Temps du dernier retour demandé
@ SEQForceSave
Sauvegarde en force.
virtual const CommonVariables & commonVariables() const =0
Informations sur les variables standards.
virtual IParallelMng * parallelMng()=0
Retourne le gestionnaire de parallélisme.
virtual IVariableMng * variableMng()=0
Retourne le gestionnaire de variables.
Fonctor d'un filtre applicable sur des variables.
Interface d'une variable.
Definition IVariable.h:54
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
virtual bool applyFilter(IVariable &var)
Applique le filtre sur la variable var.
Exception lorsqu'une erreur fatale est survenue.
virtual TraceMessage info()=0
Flot pour un message d'information.
virtual TraceMessage pfatal()=0
Flot pour un message d'erreur fatale parallèle.
Int32 Integer
Type représentant un entier.