Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
EntryPoint.h
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.h (C) 2000-2025 */
9/* */
10/* Module entry point. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ENTRYPOINT_H
13#define ARCANE_CORE_ENTRYPOINT_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/String.h"
18#include "arcane/utils/FunctorWithAddress.h"
19#include "arcane/core/IEntryPoint.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26class Timer;
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31/*!
32 * \brief Information to build an entry point.
33 *
34 * Normally this class is not used directly. To
35 * build an entry point, you must use addEntryPoint().
36 */
37class ARCANE_CORE_EXPORT EntryPointBuildInfo
38{
39 public:
40
41 /*!
42 * \brief Entry point build information.
43 *
44 * \param module module associated with the function
45 * \param where location in the time loop where the entry point is called
46 * \param property properties of the entry point (see IEntryPoint)
47 * \param name name of the entry point
48 * \param caller encapsulation of the method to be called.
49 * \param is_destroy_caller indicates whether the entry point should destroy
50 * the functor \a caller.
51 *
52 * Generally, \a is_destroy_caller must be \a true, otherwise the
53 * memory will not be released. Note that the C# wrapping handles the functor
54 * via a garbage collector, so in this case \a is_destroy_caller must
55 * be \a false.
56 */
57 EntryPointBuildInfo(IModule* module, const String& name,
58 IFunctor* caller, const String& where, int property,
59 bool is_destroy_caller)
60 : m_module(module)
61 , m_name(name)
62 , m_caller(caller)
63 , m_where(where)
64 , m_property(property)
65 , m_is_destroy_caller(is_destroy_caller)
66 {
67 }
68
69 public:
70
71 IModule* module() const { return m_module; }
72 const String& name() const { return m_name; }
73 IFunctor* caller() const { return m_caller; }
74 const String& where() const { return m_where; }
75 int property() const { return m_property; }
76 bool isDestroyCaller() const { return m_is_destroy_caller; }
77
78 private:
79
80 IModule* m_module;
81 String m_name;
82 IFunctor* m_caller;
83 String m_where;
84 int m_property;
85 bool m_is_destroy_caller;
86};
87
88/*---------------------------------------------------------------------------*/
89/*---------------------------------------------------------------------------*/
90
91/*!
92 * \internal
93 * \brief Module entry point.
94 */
95class ARCANE_CORE_EXPORT EntryPoint
96: public IEntryPoint
97{
98 public:
99
100 //! Frees resources
101 ~EntryPoint() override;
102
103 public:
104
105 /*!
106 * \brief Constructs and returns an entry point.
107 *
108 * The entry point is constructed with the information provided by \bi.
109 * It is automatically added to the IEntryPointMng manager and should not
110 * be explicitly destroyed.
111 */
112 static EntryPoint* create(const EntryPointBuildInfo& bi);
113
114 public:
115
116 String name() const override { return m_name; }
117 String fullName() const override { return m_full_name; }
118 ISubDomain* subDomain() const override { return m_sub_domain; }
119 IModule* module() const override { return m_module; }
120 void executeEntryPoint() override;
121 Real totalCPUTime() const override;
122 Real lastCPUTime() const override;
123 Real totalElapsedTime() const override;
124 Real lastElapsedTime() const override;
125 Real totalTime(Timer::eTimerType type) const override;
126 Real lastTime(Timer::eTimerType type) const override;
127 Integer nbCall() const override { return m_nb_call; }
128 String where() const override { return m_where; }
129 int property() const override { return m_property; }
130
131 private:
132
133 ISubDomain* m_sub_domain = nullptr; //!< Sub-domain manager
134 IFunctor* m_caller = nullptr; //!< Call point
135 Timer* m_elapsed_timer = nullptr; //!< Entry point clock timer
136 String m_name; //!< Entry point name
137 String m_full_name; //!< Entry point name
138 IModule* m_module = nullptr; //!< Associated module
139 String m_where; //!< Call location
140 int m_property = 0; //!< Entry point properties
141 Integer m_nb_call = 0; //!< Number of times the entry point has been executed
142 bool m_is_destroy_caller = false; //!< Indicates whether the calling functor should be destroyed.
143
144 private:
145
146 explicit EntryPoint(const EntryPointBuildInfo& build_info);
147
148 public:
149
150 EntryPoint(const EntryPoint&) = delete;
151 void operator=(const EntryPoint&) = delete;
152
153 private:
154
155 void _getAddressForHyoda(void* = nullptr);
156};
157
158/*---------------------------------------------------------------------------*/
159/*---------------------------------------------------------------------------*/
160
161/*!
162 * \brief Template routine allowing an entry point to be referenced
163 * in a module.
164 *
165 * The parameter \a ModuleType must be a type that derives from IModule.
166 *
167 * \param module Module associated with the function
168 * \param func member function called by the function
169 * \param where location where the entry point is called
170 * \param property properties of the entry point (see IEntryPoint)
171 * \param name name of the function for Arcane
172 */
173template <typename ModuleType> inline void
174addEntryPoint(ModuleType* module, const char* name, void (ModuleType::*func)(),
175 const String& where = IEntryPoint::WComputeLoop,
176 int property = IEntryPoint::PNone)
177{
178 IFunctorWithAddress* caller = new FunctorWithAddressT<ModuleType>(module, func);
179 EntryPoint::create(EntryPointBuildInfo(module, name, caller, where, property, true));
180}
181
182/*---------------------------------------------------------------------------*/
183/*---------------------------------------------------------------------------*/
184
185/*!
186 * \brief Template routine allowing an entry point to be referenced
187 * in a module.
188 *
189 * The parameter \a ModuleType must be a type that derives from IModule.
190 *
191 * \param module Module associated with the function
192 * \param func member function called by the function
193 * \param where location where the entry point is called
194 * \param property properties of the entry point (see IEntryPoint)
195 * \param name name of the function for Arcane
196 */
197template <typename ModuleType> inline void
198addEntryPoint(ModuleType* module, const String& name, void (ModuleType::*func)(),
199 const String& where = IEntryPoint::WComputeLoop,
200 int property = IEntryPoint::PNone)
201{
202 IFunctorWithAddress* caller = new FunctorWithAddressT<ModuleType>(module, func);
203 EntryPoint::create(EntryPointBuildInfo(module, name, caller, where, property, true));
204}
205
206/*---------------------------------------------------------------------------*/
207/*---------------------------------------------------------------------------*/
208
209} // End namespace Arcane
210
211/*---------------------------------------------------------------------------*/
212/*---------------------------------------------------------------------------*/
213
214#endif
Information to build an entry point.
Definition EntryPoint.h:38
EntryPointBuildInfo(IModule *module, const String &name, IFunctor *caller, const String &where, int property, bool is_destroy_caller)
Entry point build information.
Definition EntryPoint.h:57
String where() const override
Returns where the entry point is called.
Definition EntryPoint.h:128
IModule * module() const override
Returns the module associated with the entry point.
Definition EntryPoint.h:119
static EntryPoint * create(const EntryPointBuildInfo &bi)
Constructs and returns an entry point.
Definition EntryPoint.cc:78
String name() const override
Returns the name of the entry point.
Definition EntryPoint.h:116
String fullName() const override
Full name (with the module) of the entry point. This name is unique.
Definition EntryPoint.h:117
Integer nbCall() const override
Returns the number of times the entry point has been executed.
Definition EntryPoint.h:127
int property() const override
Returns the properties of the entry point.
Definition EntryPoint.h:129
ISubDomain * subDomain() const override
Returns the main manager.
Definition EntryPoint.h:118
Interface of a module entry point.
Definition IEntryPoint.h:35
static const char *const WComputeLoop
called during the calculation loop
Definition IEntryPoint.h:43
@ PNone
No properties.
Definition IEntryPoint.h:67
Interface of a functor.
Interface of a module.
Definition IModule.h:40
Interface of the subdomain manager.
Definition ISubDomain.h:75
Management of a timer.
Definition Timer.h:63
eTimerType
Timer type.
Definition Timer.h:68
-- 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.
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