14#include "arcane/utils/ArcanePrecomp.h"
16#include "arcane/utils/CheckedConvert.h"
17#include "arcane/utils/ITraceMng.h"
19#include "arcane/core/ISubDomain.h"
20#include "arcane/core/ICaseFunction.h"
21#include "arcane/core/CommonVariables.h"
23#include "arcane/core/OutputChecker.h"
38, m_out_type(OutTypeNone)
40, m_next_global_time(0)
43, m_step_global_time(0)
48assignGlobalTime(VariableScalarReal* variable,
const CaseOptionReal* option)
50 m_next_global_time = variable;
51 m_step_global_time = option;
55assignCPUTime(VariableScalarInteger* variable,
const CaseOptionInteger* option)
57 m_next_cpu_time = variable;
58 m_step_cpu_time = option;
62assignIteration(VariableScalarInteger* variable,
const CaseOptionInteger* option)
64 m_next_iteration = variable;
65 m_step_iteration = option;
87check(
Real old_time,
Real current_time,
89 const String& from_function)
91 String function_id =
"OutputChecker::check >>> ";
96 ITraceMng* trace = m_sub_domain->traceMng();
99 bool do_output =
false;
100 switch (m_out_type) {
102 Real next_time = (*m_next_global_time)();
103 trace->
debug() << from_function << function_id <<
"Next out: " << next_time <<
" Saved Time: " << old_time
104 <<
" Current time: " << current_time <<
" step=" << m_step_global_time;
111 else if (next_time > old_time && next_time < current_time) {
115 if (do_output || next_time < old_time) {
120 Real to_add = m_step_global_time->valueAtParameter(current_time);
123 Real diff = (current_time - next_time) / to_add;
125 *m_next_global_time = next_time + to_add;
128 *m_next_global_time = next_time + (to_add * (i_diff + 1));
130 trace->
debug() << from_function << function_id
131 <<
"Next output at time " << next_time
132 <<
" (" << to_add <<
' ' << old_time
133 <<
' ' << current_iteration <<
")";
138 Integer next_iteration = (*m_next_iteration)();
139 Integer to_add = m_step_iteration->valueAtParameter(current_time);
141 if (next_iteration > current_iteration + to_add) {
144 next_iteration = current_iteration;
147 if (next_iteration == current_iteration)
151 if (next_iteration <= current_iteration) {
153 Integer diff = (current_iteration - next_iteration) / to_add;
154 (*m_next_iteration) = next_iteration + ((diff + 1) * to_add);
155 trace->
debug() << from_function << function_id
156 <<
"Next output at iteration " << (*m_next_iteration)()
157 <<
" (" << to_add <<
' ' << old_time
158 <<
' ' << current_iteration <<
" diff=" << diff <<
")";
163 Integer next_cpu_time = (*m_next_cpu_time)();
164 Integer cpu_time = cpu_time_used;
168 Integer current_cpu_time = cpu_time / 60;
170 if (next_cpu_time <= current_cpu_time)
174 if (next_cpu_time <= current_cpu_time) {
175 Integer to_add = m_step_cpu_time->valueAtParameter(current_time);
177 Integer diff = (current_cpu_time - next_cpu_time) / to_add;
178 (*m_next_cpu_time) = next_cpu_time + ((diff + 1) * to_add);
179 trace->
debug() << from_function << function_id
180 <<
"Next output at cpu time " << (*m_next_cpu_time)()
181 <<
" (" << to_add <<
' ' << current_cpu_time <<
" diff=" << diff <<
")";
186 if (current_cpu_time == 0)
211_recomputeTypeGlobalTime()
213 Real current_time = m_sub_domain->commonVariables().globalTime();
214 Real step = m_step_global_time->valueAtParameter(current_time);
216 Real old_next = (*m_next_global_time)();
217 Real next = old_next;
218 Real current_value = current_time;
220 Real index = ::floor(current_value / step);
221 next = step * (index + 1.0);
222 *m_next_global_time = next;
225 ITraceMng* tm = m_sub_domain->traceMng();
226 tm->info(4) <<
"Recompute OutputChecker for Global Time: old=" << old_next
234_recomputeTypeCPUTime()
236 Real current_time = m_sub_domain->commonVariables().globalTime();
237 Integer step = m_step_cpu_time->valueAtParameter(current_time);
239 Integer old_next = (*m_next_cpu_time)();
241 double current_value = math::floor(m_sub_domain->commonVariables().globalCPUTime());
244 current_value /= 60.0;
247 Integer index = CheckedConvert::toInteger(current_value / step);
248 next = step * (index + 1);
249 *m_next_cpu_time = next;
252 ITraceMng* tm = m_sub_domain->traceMng();
253 tm->info(4) <<
"Recompute OutputChecker for CPU Time: old=" << old_next <<
" new=" << next;
260_recomputeTypeIteration()
262 Real current_time = m_sub_domain->commonVariables().globalTime();
263 Integer step = m_step_iteration->valueAtParameter(current_time);
265 Integer old_next = (*m_next_iteration)();
267 Integer current_value = m_sub_domain->commonVariables().globalIteration();
269 if (old_next <= current_value) {
270 *m_next_iteration = current_value;
273 Integer index = current_value / step;
274 next = step * (index + 1);
275 *m_next_iteration = next;
279 ITraceMng* tm = m_sub_domain->traceMng();
280 tm->info(4) <<
"Recompute OutputChecker for CPU Time: old=" << old_next <<
" new=" << next;
296initialize(
bool recompute_next_value)
298 ITraceMng* trace = m_sub_domain->traceMng();
299 m_out_type = OutTypeNone;
301 ICaseFunction* func = 0;
304 if (m_step_global_time && m_next_global_time && m_step_global_time->isPresent()) {
305 m_out_type = OutTypeGlobalTime;
306 func = m_step_global_time->function();
308 trace->info() <<
"Output in real time controlled by function '" << func->name() <<
"'.";
310 trace->info() <<
"Output in real time every " << (*m_step_global_time)() <<
" seconds.";
311 if (recompute_next_value)
312 _recomputeTypeGlobalTime();
314 else if (m_step_iteration && m_next_iteration && m_step_iteration->value() != 0) {
315 m_out_type = OutTypeIteration;
316 func = m_step_iteration->function();
318 trace->info() <<
"Output in iterations controlled by function '" << func->name() <<
"'.";
320 trace->info() <<
"Output every " << (*m_step_iteration)() <<
" iterations.";
321 if (recompute_next_value)
322 _recomputeTypeIteration();
324 else if (m_step_cpu_time && m_next_cpu_time && m_step_cpu_time->isPresent()) {
325 m_out_type = OutTypeCPUTime;
326 func = m_step_cpu_time->function();
328 trace->info() <<
"Output in CPU time controlled by function '" << func->name() <<
"'.";
330 trace->info() <<
"Output in CPU time every " << (*m_step_cpu_time)() <<
" minutes.";
331 if (recompute_next_value)
332 _recomputeTypeCPUTime();
335 trace->info() <<
"No output required.";
342nextGlobalTime()
const
345 if (m_next_global_time)
346 v = (*m_next_global_time)();
357 if (m_next_iteration)
358 v = (*m_next_iteration)();
370 v = (*m_next_cpu_time)();
Interface of the subdomain manager.
virtual TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium)=0
Stream for a debug message.
@ OutTypeCPUTime
Output based on consumed CPU time.
@ OutTypeIteration
Output based on number of iterations.
@ OutTypeGlobalTime
Output based on physical time.
Unicode character string.
__host__ __device__ double floor(double v)
Round v down to the immediately lower integer.
bool isZero(const BuiltInProxy< _Type > &a)
Tests if a value is exactly equal to zero.
constexpr __host__ __device__ bool isEqual(const _Type &a, const _Type &b)
Tests the bit-by-bit equality between two values.
-- 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.