Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
EntryPoint.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* EntryPoint.cc (C) 2000-2022 */
9/* */
10/* Entry point of a module. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/core/EntryPoint.h"
15
16#include "arcane/utils/ITraceMng.h"
17#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/StringBuilder.h"
19
20#include "arcane/core/IModule.h"
21#include "arcane/core/IEntryPointMng.h"
22#include "arcane/core/ISubDomain.h"
23#include "arcane/core/Timer.h"
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34const char* const IEntryPoint::WComputeLoop = "ComputeLoop";
35const char* const IEntryPoint::WBuild = "Build";
36const char* const IEntryPoint::WInit = "Init";
37const char* const IEntryPoint::WContinueInit = "ContinueInit";
38const char* const IEntryPoint::WStartInit = "StartInit";
39const char* const IEntryPoint::WRestore = "Restore";
40const char* const IEntryPoint::WOnMeshChanged = "OnMeshChanged";
41const char* const IEntryPoint::WOnMeshRefinement = "OnMeshRefinement";
42const char* const IEntryPoint::WExit = "Exit";
43
44/*---------------------------------------------------------------------------*/
45/*---------------------------------------------------------------------------*/
46
47EntryPoint::
48EntryPoint(const EntryPointBuildInfo& bi)
49: m_sub_domain(bi.module()->subDomain())
50, m_caller(bi.caller())
51, m_elapsed_timer(new Timer(m_sub_domain, bi.name(), Timer::TimerReal))
52, m_name(bi.name())
53, m_module(bi.module())
54, m_where(bi.where())
55, m_property(bi.property())
56, m_nb_call(0)
57, m_is_destroy_caller(bi.isDestroyCaller())
58{
59 // Registers with the entry point manager.
60 // which will handle the destruction.
61 m_sub_domain->entryPointMng()->addEntryPoint(this);
62
63 {
64 StringBuilder sb;
65 sb.append(m_module->name());
66 sb.append(".");
67 sb.append(m_name);
68 sb.append(".");
69 sb.append(m_where);
70 m_full_name = sb.toString();
71 }
72}
73
74/*---------------------------------------------------------------------------*/
75/*---------------------------------------------------------------------------*/
76
77EntryPoint* EntryPoint::
78create(const EntryPointBuildInfo& bi)
79{
80 EntryPoint* x = new EntryPoint(bi);
81 return x;
82}
83
84/*---------------------------------------------------------------------------*/
85/*---------------------------------------------------------------------------*/
86
87EntryPoint::
88~EntryPoint()
89{
90 delete m_elapsed_timer;
91 //FIXME this must not be destroyed if we go through the C# wrapper
93 delete m_caller;
94}
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
99#ifdef __GNUG__
100#pragma GCC optimize "O0"
101#endif
102void EntryPoint::
103_getAddressForHyoda(void* next_entry_point_address)
104{
105#ifndef ARCANE_OS_WIN32
107 return;
108 {
109 char address[48 + 1];
110 snprintf(address, sizeof(address) - 1, "%p", next_entry_point_address);
111 //m_sub_domain->traceMng()->debug()<< "\33[7m" << m_where <<"->"<< m_name << "\33[m" << " @" << address;
112 }
113#endif
114}
115#ifdef __GNUG__
116#pragma GCC reset_options
117#endif
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
121void EntryPoint::
122executeEntryPoint()
123{
124 // Entry points for the compute loop are not
125 // called if the module is not active.
126 if (m_module->disabled() && m_where == WComputeLoop)
127 return;
128
129 // In the case of GCC, we will fetch from the module_vtable to retrieve the upcoming address
130 // which we will present to Hyoda
132#ifdef __GNUG__
133 _getAddressForHyoda((static_cast<IFunctorWithAddress*>(m_caller))->functorAddress());
134#else
135 _getAddressForHyoda();
136#endif
137 }
138
139 Trace::Setter mclass(m_sub_domain->traceMng(), m_module->name());
140
141 {
142 Timer::Sentry ts_elapsed(m_elapsed_timer);
143 Timer::Action ts_action1(m_sub_domain, m_module->name());
144 Timer::Phase ts_phase(m_sub_domain, TP_Computation);
145 Timer::Action ts_action2(m_sub_domain, m_name);
146 m_caller->executeFunctor();
147 }
148
149 ++m_nb_call;
150}
151
152/*---------------------------------------------------------------------------*/
153/*---------------------------------------------------------------------------*/
154
155Real EntryPoint::
156lastCPUTime() const
157{
158 return m_elapsed_timer->lastActivationTime();
159}
160
161/*---------------------------------------------------------------------------*/
162/*---------------------------------------------------------------------------*/
163
164Real EntryPoint::
165totalCPUTime() const
166{
167 return m_elapsed_timer->totalTime();
168}
169
170/*---------------------------------------------------------------------------*/
171/*---------------------------------------------------------------------------*/
172
173Real EntryPoint::
174lastElapsedTime() const
175{
176 return m_elapsed_timer->lastActivationTime();
177}
178
179/*---------------------------------------------------------------------------*/
180/*---------------------------------------------------------------------------*/
181
182Real EntryPoint::
183totalElapsedTime() const
184{
185 return m_elapsed_timer->totalTime();
186}
187
188/*---------------------------------------------------------------------------*/
189/*---------------------------------------------------------------------------*/
190
191Real EntryPoint::
192totalTime(Timer::eTimerType) const
193{
194 return totalElapsedTime();
195}
196
197/*---------------------------------------------------------------------------*/
198/*---------------------------------------------------------------------------*/
199
200Real EntryPoint::
201lastTime(Timer::eTimerType) const
202{
203 return lastElapsedTime();
204}
205
206/*---------------------------------------------------------------------------*/
207/*---------------------------------------------------------------------------*/
208
209} // End namespace Arcane
210
211/*---------------------------------------------------------------------------*/
212/*---------------------------------------------------------------------------*/
Information to build an entry point.
Definition EntryPoint.h:38
Real lastElapsedTime() const override
Elapsed execution time (clock time) of the last iteration (in milliseconds).
IFunctor * m_caller
Call point.
Definition EntryPoint.h:134
Timer * m_elapsed_timer
Entry point clock timer.
Definition EntryPoint.h:135
ISubDomain * m_sub_domain
Sub-domain manager.
Definition EntryPoint.h:133
Integer m_nb_call
Number of times the entry point has been executed.
Definition EntryPoint.h:141
Real totalElapsedTime() const override
Elapsed execution time (clock time) in this entry point (in milliseconds).
bool m_is_destroy_caller
Indicates whether the calling functor should be destroyed.
Definition EntryPoint.h:142
IModule * m_module
Associated module.
Definition EntryPoint.h:138
String m_where
Call location.
Definition EntryPoint.h:139
String m_name
Entry point name.
Definition EntryPoint.h:136
static const char *const WComputeLoop
called during the calculation loop
Definition IEntryPoint.h:43
static const char *const WBuild
called for module construction
Definition IEntryPoint.h:45
static const char *const WStartInit
called during new case initialization
Definition IEntryPoint.h:51
static const char *const WRestore
called to restore variables during a rollback
Definition IEntryPoint.h:53
static const char *const WOnMeshRefinement
called after mesh refinement
Definition IEntryPoint.h:57
static const char *const WOnMeshChanged
called after a mesh change
Definition IEntryPoint.h:55
static const char *const WContinueInit
called during continuation initialization
Definition IEntryPoint.h:49
static const char *const WInit
called during initialization
Definition IEntryPoint.h:47
Interface of a functor.
Positions the name of the currently executing action.
Definition Timer.h:119
Positions the phase of the currently executing action.
Definition Timer.h:142
Sentinel for the timer. The sentinel associated with a timer allows it to be triggered upon its const...
Definition Timer.h:90
Management of a timer.
Definition Timer.h:63
eTimerType
Timer type.
Definition Timer.h:68
bool hasDotNETRuntime()
True if the code is running with the .NET runtime.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
double Real
Type representing a real number.
void addEntryPoint(ModuleType *module, const char *name, void(ModuleType::*func)(), const String &where=IEntryPoint::WComputeLoop, int property=IEntryPoint::PNone)
Template routine allowing an entry point to be referenced in a module.
Definition EntryPoint.h:174