Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ArcaneLauncher.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/* ArcaneLauncher.h (C) 2000-2025 */
9/* */
10/* Class managing execution. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_LAUNCHER_ARCANELAUNCHER_H
13#define ARCANE_LAUNCHER_ARCANELAUNCHER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/launcher/LauncherGlobal.h"
18
19// The following files are not directly used in this '.h'
20// but are added so that user code only needs to include
21// 'ArcaneLauncher.h'.
22#include "arcane/utils/ApplicationInfo.h"
23#include "arcane/utils/CommandLineArguments.h"
24
25#include "arcane/core/ApplicationBuildInfo.h"
26#include "arcane/core/DotNetRuntimeInitialisationInfo.h"
27#include "arcane/core/AcceleratorRuntimeInitialisationInfo.h"
28
29#include "arcane/launcher/DirectExecutionContext.h"
30#include "arcane/launcher/DirectSubDomainExecutionContext.h"
31#include "arcane/launcher/IDirectExecutionContext.h"
32#include "arcane/launcher/StandaloneAcceleratorMng.h"
33#include "arcane/launcher/StandaloneSubDomain.h"
34
35#include <functional>
36
37/*---------------------------------------------------------------------------*/
38/*---------------------------------------------------------------------------*/
39
40namespace Arcane
41{
42class IMainFactory;
43
44/*---------------------------------------------------------------------------*/
45/*---------------------------------------------------------------------------*/
46
47/*!
48 * \brief Execution management class.
49 *
50 * There are two modes of using %Arcane: classic mode and standalone mode.
51 *
52 * Regardless of the mode chosen, the first thing to do is initialize %Arcane by
53 * setting the arguments via the init() method, because certain command-line
54 * parameters are used to populate the properties of applicationInfo() and
55 * dotNetRuntimeInitialisationInfo().
56 *
57 * The page \ref arcanedoc_execution_launcher provides usage examples.
58 *
59 * The two execution modes are:
60 * - classic mode, which uses a time loop, and thus the entire execution
61 * will be managed by %Arcane. In this mode, you simply call the run() method
62 * without arguments.
63 * - standalone mode, which allows %Arcane to be used as a library.
64 * For this mode, you must use the createStandaloneSubDomain()
65 * or createStandaloneAcceleratorMng() method. The page
66 * \ref arcanedoc_execution_direct_execution describes how to use this mechanism.
67 *
68 * The classic usage is as follows:
69 *
70 * \code
71 * int main(int* argc,char* argv[])
72 * {
73 * ArcaneLauncher::init(CommandLineArguments(&argc,&argv));
74 * auto& app_info = ArcaneLauncher::applicationInfo();
75 * app_info.setCodeName("MyCode");
76 * app_info.setCodeVersion(VersionInfo(1,0,0));
77 * return ArcaneLauncher::run();
78 * }
79 * \endcode
80 */
81class ARCANE_LAUNCHER_EXPORT ArcaneLauncher
82{
83 friend StandaloneSubDomain;
84
85 public:
86
87 /*!
88 * \brief Positions information from command-line arguments and initializes
89 * the launcher.
90 *
91 * This method fills the uninitialized values of applicationInfo() and
92 * dotNetRuntimeInitialisationInfo() with the parameters specified in \a args.
93 *
94 * This method must only be called once. Additional calls generate a
95 * FatalErrorException.
96 */
97 static void init(const CommandLineArguments& args);
98
99 /*!
100 * \brief Indicates if init() has already been called.
101 */
102 static bool isInitialized();
103
104 /*!
105 * \brief Entry point of the executable in Arcane.
106 *
107 * This method initializes the application, reads the dataset, and executes
108 * the code according to the time loop specified in the dataset.
109 *
110 * \retval 0 upon success
111 * \return a value different from 0 in case of error.
112 */
113 static int run();
114
115 /*!
116 * \brief Direct execution.
117 *
118 * Initializes the application and calls the function \a func after
119 * initialization.
120 * This method must only be called in sequential execution.
121 */
122 static int run(std::function<int(DirectExecutionContext&)> func);
123
124 /*!
125 * \brief Direct execution with subdomain creation.
126 *
127 * Initializes the application and creates the subdomain(s) and calls
128 * the function \a func afterward.
129 * This method allows executing code without going through the time loop
130 * mechanisms.
131 * This method automatically manages the creation of subdomains
132 * based on launch parameters (MPI parallel execution, multithreading, ...).
133 */
134 static int run(std::function<int(DirectSubDomainExecutionContext&)> func);
135
136 /*!
137 * \brief Positions the default factory for creating the different managers
138 *
139 * This method must be called before run(). The instance passed as an argument
140 * must remain valid during the execution of run(). The caller remains the owner
141 * of the instance.
142 */
143 static void setDefaultMainFactory(IMainFactory* mf);
144
145 /*!
146 * \brief Application information.
147 *
148 * This method allows retrieving the `ApplicationInfo` instance
149 * that will be used when calling run().
150 *
151 * To be taken into account, this information must be modified
152 * before calling run() or runDirect().
153 */
155
156 /*!
157 * \brief Application execution parameter information.
158 *
159 * This method allows retrieving the `ApplicationBuildInfo` instance
160 * that will be used when calling run().
161 *
162 * To be taken into account, this information must be modified
163 * before calling run() or runDirect().
164 */
166
167 /*!
168 * \brief Information for '.Net' runtime initialization.
169 *
170 * To be taken into account, this information must be modified
171 * before calling run() or rundDirect().
172 */
174
175 /*!
176 * \brief Information for accelerator initialization.
177 *
178 * To be taken into account, this information must be modified
179 * before calling run() or rundDirect().
180 */
182
183 //! Full name of the directory where the executable is located
184 static String getExeDirectory();
185
186 /*!
187 * \brief Creates a standalone implementation to manage accelerators.
188 *
189 * You must call init() before calling this method. The choice of
190 * runtime (Arcane::Accelerator::eExecutionPolicy) is determined
191 * by the arguments used when calling init() or specified via
192 * acceleratorRuntimeInitialisationInfo() (see
193 * \ref arcanedoc_parallel_accelerator_exec for more information)
194 */
196
197 /*!
198 * \brief Creates a standalone implementation to manage a subdomain.
199 *
200 * Only one instance of StandaloneSubDomain is allowed. Calling this
201 * method more than once generates an exception.
202 *
203 * You must call init() before calling this method.
204 *
205 * If this method is called, you must not call other ArcaneLauncher execution
206 * methods (for example ArcaneLauncher::run()).
207 *
208 * \a case_file_name is the name of the file containing the dataset. If null,
209 * there is no dataset.
210 */
211 static StandaloneSubDomain createStandaloneSubDomain(const String& case_file_name);
212
213 /*!
214 * \brief Requests help with the "--help" or "-h" option.
215 *
216 * Method allowing to know if the user requested help with the "--help" or "-h" option.
217 *
218 * \return true if help was requested.
219 */
220 static bool needHelp();
221
222 /*!
223 * \brief Display of generic Arcane help.
224 *
225 * Method allowing to display generic Arcane help if the user requested it with
226 * the "--help" or "-h" option.
227 *
228 * \return true if help was requested.
229 */
230 static bool printHelp();
231
232 public:
233
234 /*!
235 * \deprecated
236 */
237 ARCCORE_DEPRECATED_2020("Use run(func) instead")
238 static int runDirect(std::function<int(IDirectExecutionContext*)> func);
239
240 /*!
241 * \deprecated
242 */
243 ARCCORE_DEPRECATED_2020("Use init(args) instead")
245 {
246 init(args);
247 }
248
249 private:
250
251 static void _initStandalone();
252 static void _notifyRemoveStandaloneSubDomain();
253};
254
255/*---------------------------------------------------------------------------*/
256/*---------------------------------------------------------------------------*/
257
258} // End namespace Arcane
259
260/*---------------------------------------------------------------------------*/
261/*---------------------------------------------------------------------------*/
262
263#endif
Information for constructing an instance of IApplication.
Application information.
Execution management class.
static StandaloneAcceleratorMng createStandaloneAcceleratorMng()
Creates a standalone implementation to manage accelerators.
static int run()
Entry point of the executable in Arcane.
static String getExeDirectory()
Full name of the directory where the executable is located.
static DotNetRuntimeInitialisationInfo & dotNetRuntimeInitialisationInfo()
Information for '.Net' runtime initialization.
static bool needHelp()
Requests help with the "--help" or "-h" option.
static void init(const CommandLineArguments &args)
Positions information from command-line arguments and initializes the launcher.
static ApplicationBuildInfo & applicationBuildInfo()
Application execution parameter information.
static StandaloneSubDomain createStandaloneSubDomain(const String &case_file_name)
Creates a standalone implementation to manage a subdomain.
static bool isInitialized()
Indicates if init() has already been called.
static bool printHelp()
Display of generic Arcane help.
static ApplicationInfo & applicationInfo()
Application information.
static AcceleratorRuntimeInitialisationInfo & acceleratorRuntimeInitialisationInfo()
Information for accelerator initialization.
static int runDirect(std::function< int(IDirectExecutionContext *)> func)
static void setDefaultMainFactory(IMainFactory *mf)
Positions the default factory for creating the different managers.
static void setCommandLineArguments(const CommandLineArguments &args)
Direct execution context with subdomain creation.
Information for the initialization of the '.Net' runtime.
Standalone implementation of 'IAcceleratorMng.h'.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --