Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ApplicationBuildInfo.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/* ApplicationBuildInfo.cc (C) 2000-2026 */
9/* */
10/* Information to build an instance of IApplication. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/core/ApplicationBuildInfo.h"
15
16#include "arcane/utils/PlatformUtils.h"
17#include "arcane/utils/String.h"
18#include "arcane/utils/List.h"
19#include "arcane/utils/CommandLineArguments.h"
20#include "arcane/utils/TraceClassConfig.h"
21#include "arcane/utils/ApplicationInfo.h"
22
23#include "arcane/core/CaseDatasetSource.h"
24
25#include "arccore/common/internal/FieldProperty.h"
26#include "arccore/common/internal/ArccoreApplicationBuildInfoImpl.h"
27
28#include <functional>
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33namespace Arcane
34{
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
39namespace
40{
41 void _clamp(Int32& x, Int32 min_value, Int32 max_value)
42 {
43 x = std::min(std::max(x, min_value), max_value);
44 }
45} // namespace
46
47/*---------------------------------------------------------------------------*/
48/*---------------------------------------------------------------------------*/
49
51{
52 template <typename T> using FieldProperty = PropertyImpl::FieldProperty<T>;
53
54 public:
55
56 Impl()
57 : m_nb_shared_memory_sub_domain(0)
58 , m_nb_replication_sub_domain(0)
59 , m_nb_processus_sub_domain(0)
60 , m_config_file_name("")
61 {
62 // Sets a hard limit to prevent having too many sub-domains
63 // in shared memory (the maximum is generally the number of cores per
64 // node)
65 m_nb_shared_memory_sub_domain.setValidator([](Int32& x) { _clamp(x, 0, 1024); });
66 m_nb_replication_sub_domain.setValidator([](Int32& x) { x = std::max(x, 0); });
67 m_nb_processus_sub_domain.setValidator([](Int32& x) { x = std::max(x, 0); });
68 }
69
70 public:
71 public:
72
73 FieldProperty<String> m_message_passing_service;
74 FieldProperty<Int32> m_nb_shared_memory_sub_domain;
75 FieldProperty<Int32> m_nb_replication_sub_domain;
76 FieldProperty<Int32> m_nb_processus_sub_domain;
77 FieldProperty<String> m_config_file_name;
78 FieldProperty<Int32> m_output_level;
79 FieldProperty<Int32> m_verbosity_level;
80 FieldProperty<Int32> m_minimal_verbosity_level;
81 FieldProperty<bool> m_is_master_has_output_file;
82 FieldProperty<String> m_output_directory;
83 FieldProperty<String> m_thread_binding_strategy;
84 ApplicationInfo m_app_info;
85 CaseDatasetSource m_case_dataset_source;
86 String m_default_message_passing_service;
87};
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
92ApplicationBuildInfo::
93ApplicationBuildInfo()
94: m_p(new Impl())
95{
96}
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100
101ApplicationBuildInfo::
102ApplicationBuildInfo(const ApplicationBuildInfo& rhs)
104, m_p(new Impl(*rhs.m_p))
105{
106}
107
108ApplicationBuildInfo& ApplicationBuildInfo::
109operator=(const ApplicationBuildInfo& rhs)
110{
111 ArccoreApplicationBuildInfo::operator=(rhs);
112 if (&rhs != this) {
113 delete m_p;
114 m_p = new Impl(*(rhs.m_p));
115 }
116 return (*this);
117}
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
121
122ApplicationBuildInfo::
123~ApplicationBuildInfo()
124{
125 delete m_p;
126}
127
128/*---------------------------------------------------------------------------*/
129/*---------------------------------------------------------------------------*/
130
131void ApplicationBuildInfo::
132setDefaultValues()
133{
134 ArccoreApplicationBuildInfo::setDefaultValues();
135 {
136 String str = m_core->getValue({ "ARCANE_PARALLEL_SERVICE" }, "MessagePassingService", String());
137 if (!str.null()) {
138 String service_name = str + "ParallelSuperMng";
139 PropertyImpl::checkSet(m_p->m_message_passing_service, service_name);
140 }
141 }
142 {
143 String str = m_core->getValue({ "ARCANE_NB_THREAD" }, "S", String());
144 PropertyImpl::checkSet(m_p->m_nb_shared_memory_sub_domain, str);
145 }
146 {
147 String str = m_core->getValue({ "ARCANE_NB_REPLICATION" }, "R", String());
148 PropertyImpl::checkSet(m_p->m_nb_replication_sub_domain, str);
149 }
150 {
151 String str = m_core->getValue({ "ARCANE_NB_SUB_DOMAIN" }, "P", String());
152 PropertyImpl::checkSet(m_p->m_nb_processus_sub_domain, str);
153 }
154 {
155 String str = m_core->getValue({ "ARCANE_OUTPUT_LEVEL" }, "OutputLevel",
156 String::fromNumber(Trace::UNSPECIFIED_VERBOSITY_LEVEL));
157 PropertyImpl::checkSet(m_p->m_output_level, str);
158 }
159 {
160 String str = m_core->getValue({ "ARCANE_VERBOSITY_LEVEL", "ARCANE_VERBOSE_LEVEL" }, "VerbosityLevel",
161 String::fromNumber(Trace::UNSPECIFIED_VERBOSITY_LEVEL));
162 PropertyImpl::checkSet(m_p->m_verbosity_level, str);
163 }
164 {
165 String str = m_core->getValue({}, "MinimalVerbosityLevel",
166 String::fromNumber(Trace::UNSPECIFIED_VERBOSITY_LEVEL));
167 PropertyImpl::checkSet(m_p->m_minimal_verbosity_level, str);
168 }
169 {
170 String str = m_core->getValue({ "ARCANE_MASTER_HAS_OUTPUT_FILE" }, "MasterHasOutputFile", "0");
171 PropertyImpl::checkSet(m_p->m_is_master_has_output_file, str);
172 }
173 {
174 String str = m_core->getValue({ "ARCANE_OUTPUT_DIRECTORY" }, "OutputDirectory",
175 String());
176 PropertyImpl::checkSet(m_p->m_output_directory, str);
177 }
178 {
179 String str = m_core->getValue({}, "CaseDatasetFileName",
180 String());
181 if (!str.null())
182 m_p->m_case_dataset_source.setFileName(str);
183 }
184 {
185 String str = m_core->getValue({ "ARCANE_THREAD_BINDING_STRATEGY" }, "ThreadBindingStrategy",
186 String());
187 PropertyImpl::checkSet(m_p->m_thread_binding_strategy, str);
188 }
189}
190
191/*---------------------------------------------------------------------------*/
192/*---------------------------------------------------------------------------*/
193
194void ArccoreApplicationBuildInfo::
195setDefaultServices()
196{
197 {
198 String str = m_core->getValue({ "ARCANE_TASK_IMPLEMENTATION" }, "TaskService", "TBB");
199 String service_name = str + "TaskImplementation";
200 PropertyImpl::checkSet(m_core->m_task_implementation_services, service_name);
201 }
202 {
203 StringList list1;
204 String thread_str = m_core->getValue({ "ARCANE_THREAD_IMPLEMENTATION" }, "ThreadService", "Std");
205 list1.add(thread_str + "ThreadImplementationService");
206 list1.add("TBBThreadImplementationService");
207 PropertyImpl::checkSet(m_core->m_thread_implementation_services, list1);
208 }
209}
210
211/*---------------------------------------------------------------------------*/
212/*---------------------------------------------------------------------------*/
213
214void ApplicationBuildInfo::
215setDefaultServices()
216{
217 ArccoreApplicationBuildInfo::setDefaultServices();
218 bool has_shm = nbSharedMemorySubDomain() > 0;
219 {
220 String def_name = (has_shm) ? "Thread" : "Sequential";
221 String default_service_name = def_name + "ParallelSuperMng";
222 // Sets the default value if it hasn't been set already.
223 if (m_p->m_default_message_passing_service.null())
224 m_p->m_default_message_passing_service = default_service_name;
225 }
226}
227
228/*---------------------------------------------------------------------------*/
229/*---------------------------------------------------------------------------*/
230
231void ApplicationBuildInfo::
232setMessagePassingService(const String& name)
233{
234 m_p->m_message_passing_service = name;
235}
236
237String ApplicationBuildInfo::
238messagePassingService() const
239{
240 return m_p->m_message_passing_service;
241}
242
243/*---------------------------------------------------------------------------*/
244/*---------------------------------------------------------------------------*/
245
246void ArccoreApplicationBuildInfo::
247setTaskImplementationService(const String& name)
248{
249 StringList s;
250 s.add(name);
251 m_core->m_task_implementation_services = s;
252}
253void ArccoreApplicationBuildInfo::
254setTaskImplementationServices(const StringList& names)
255{
256 m_core->m_task_implementation_services = names;
257}
258StringList ArccoreApplicationBuildInfo::
259taskImplementationServices() const
260{
261 return m_core->m_task_implementation_services;
262}
263
264/*---------------------------------------------------------------------------*/
265/*---------------------------------------------------------------------------*/
266
267void ArccoreApplicationBuildInfo::
268setThreadImplementationService(const String& name)
269{
270 StringList s;
271 s.add(name);
272 m_core->m_thread_implementation_services = s;
273}
274void ArccoreApplicationBuildInfo::
275setThreadImplementationServices(const StringList& names)
276{
277 m_core->m_thread_implementation_services = names;
278}
279StringList ArccoreApplicationBuildInfo::
280threadImplementationServices() const
281{
282 return m_core->m_thread_implementation_services;
283}
284
285/*---------------------------------------------------------------------------*/
286/*---------------------------------------------------------------------------*/
287
288Int32 ArccoreApplicationBuildInfo::
289nbTaskThread() const
290{
291 return m_core->m_nb_task_thread;
292}
293
294/*---------------------------------------------------------------------------*/
295/*---------------------------------------------------------------------------*/
296
297void ArccoreApplicationBuildInfo::
298setNbTaskThread(Int32 v)
299{
300 m_core->m_nb_task_thread = v;
301}
302
303/*---------------------------------------------------------------------------*/
304/*---------------------------------------------------------------------------*/
305
306Int32 ApplicationBuildInfo::
307nbSharedMemorySubDomain() const
308{
309 return m_p->m_nb_shared_memory_sub_domain;
310}
311
312/*---------------------------------------------------------------------------*/
313/*---------------------------------------------------------------------------*/
314
315void ApplicationBuildInfo::
316setNbSharedMemorySubDomain(Int32 v)
317{
318 m_p->m_nb_shared_memory_sub_domain = v;
319}
320
321/*---------------------------------------------------------------------------*/
322/*---------------------------------------------------------------------------*/
323
324Int32 ApplicationBuildInfo::
325nbReplicationSubDomain() const
326{
327 return m_p->m_nb_replication_sub_domain;
328}
329
330/*---------------------------------------------------------------------------*/
331/*---------------------------------------------------------------------------*/
332
333void ApplicationBuildInfo::
334setNbReplicationSubDomain(Int32 v)
335{
336 m_p->m_nb_replication_sub_domain = v;
337}
338
339/*---------------------------------------------------------------------------*/
340/*---------------------------------------------------------------------------*/
341
342Int32 ApplicationBuildInfo::
343nbProcessusSubDomain() const
344{
345 return m_p->m_nb_processus_sub_domain;
346}
347
348/*---------------------------------------------------------------------------*/
349/*---------------------------------------------------------------------------*/
350
351void ApplicationBuildInfo::
352setNbProcessusSubDomain(Int32 v)
353{
354 m_p->m_nb_processus_sub_domain = v;
355}
356
357/*---------------------------------------------------------------------------*/
358/*---------------------------------------------------------------------------*/
359
361configFileName() const
362{
363 return m_p->m_config_file_name;
364}
365
366/*---------------------------------------------------------------------------*/
367/*---------------------------------------------------------------------------*/
368
371{
372 m_p->m_config_file_name = v;
373}
374
375/*---------------------------------------------------------------------------*/
376/*---------------------------------------------------------------------------*/
377
378Int32 ApplicationBuildInfo::
379outputLevel() const
380{
381 return m_p->m_output_level;
382}
383
386{
387 m_p->m_output_level = v;
388}
389
390/*---------------------------------------------------------------------------*/
391/*---------------------------------------------------------------------------*/
392
393Int32 ApplicationBuildInfo::
394verbosityLevel() const
395{
396 return m_p->m_verbosity_level;
397}
398
401{
402 m_p->m_verbosity_level = v;
403}
404
405/*---------------------------------------------------------------------------*/
406/*---------------------------------------------------------------------------*/
407
408Int32 ApplicationBuildInfo::
409minimalVerbosityLevel() const
410{
411 return m_p->m_minimal_verbosity_level;
412}
413
414void ApplicationBuildInfo::
415setMinimalVerbosityLevel(Int32 v)
416{
417 m_p->m_minimal_verbosity_level = v;
418}
419
420/*---------------------------------------------------------------------------*/
421/*---------------------------------------------------------------------------*/
422
423bool ApplicationBuildInfo::
424isMasterHasOutputFile() const
425{
426 return m_p->m_is_master_has_output_file;
427}
428
429void ApplicationBuildInfo::
430setIsMasterHasOutputFile(bool v)
431{
432 m_p->m_is_master_has_output_file = v;
433}
434
435/*---------------------------------------------------------------------------*/
436/*---------------------------------------------------------------------------*/
437
438String ApplicationBuildInfo::
439outputDirectory() const
440{
441 return m_p->m_output_directory;
442}
443
444/*---------------------------------------------------------------------------*/
445/*---------------------------------------------------------------------------*/
446
449{
450 m_p->m_output_directory = v;
451}
452
453/*---------------------------------------------------------------------------*/
454/*---------------------------------------------------------------------------*/
455
458{
459 return m_p->m_thread_binding_strategy;
460}
461
464{
465 m_p->m_thread_binding_strategy = v;
466}
467
468/*---------------------------------------------------------------------------*/
469/*---------------------------------------------------------------------------*/
470
471void ArccoreApplicationBuildInfo::
472addParameter(const String& name, const String& value)
473{
474 m_core->addKeyValue(name, value);
475}
476
477/*---------------------------------------------------------------------------*/
478/*---------------------------------------------------------------------------*/
479
482{
483 // We only retrieve arguments of the style:
484 // -A,x=b,y=c
485 StringList names;
486 StringList values;
487 command_line_args.fillParameters(names, values);
488 for (Integer i = 0, n = names.count(); i < n; ++i) {
489 addParameter(names[i], values[i]);
490 }
491 setDefaultValues();
492}
493
494/*---------------------------------------------------------------------------*/
495/*---------------------------------------------------------------------------*/
496
497ApplicationInfo& ApplicationBuildInfo::
498_internalApplicationInfo()
499{
500 return m_p->m_app_info;
501}
502
503/*---------------------------------------------------------------------------*/
504/*---------------------------------------------------------------------------*/
505
506const ApplicationInfo& ApplicationBuildInfo::
507_internalApplicationInfo() const
508{
509 return m_p->m_app_info;
510}
511
512/*---------------------------------------------------------------------------*/
513/*---------------------------------------------------------------------------*/
514
517{
518 m_p->m_app_info.setApplicationName(v);
519}
521applicationName() const
522{
523 return m_p->m_app_info.applicationName();
524}
525
526/*---------------------------------------------------------------------------*/
527/*---------------------------------------------------------------------------*/
528
530setCodeVersion(const VersionInfo& version_info)
531{
532 m_p->m_app_info.setCodeVersion(version_info);
533}
534
536codeVersion() const
537{
538 return m_p->m_app_info.codeVersion();
539}
540
541/*---------------------------------------------------------------------------*/
542/*---------------------------------------------------------------------------*/
543
545setCodeName(const String& code_name)
546{
547 m_p->m_app_info.setCodeName(code_name);
548}
549
551codeName() const
552{
553 return m_p->m_app_info.codeName();
554}
555
556/*---------------------------------------------------------------------------*/
557/*---------------------------------------------------------------------------*/
558
561{
562 return m_p->m_case_dataset_source;
563}
564
566caseDatasetSource() const
567{
568 return m_p->m_case_dataset_source;
569}
570
571/*---------------------------------------------------------------------------*/
572/*---------------------------------------------------------------------------*/
573
575addDynamicLibrary(const String& lib_name)
576{
577 m_p->m_app_info.addDynamicLibrary(lib_name);
578}
579
580/*---------------------------------------------------------------------------*/
581/*---------------------------------------------------------------------------*/
582
585{
586 m_p->m_default_message_passing_service = name;
587}
588
589/*---------------------------------------------------------------------------*/
590/*---------------------------------------------------------------------------*/
591
592String ApplicationBuildInfo::
593internalDefaultMessagePassingService() const
594{
595 return m_p->m_default_message_passing_service;
596}
597
598/*---------------------------------------------------------------------------*/
599/*---------------------------------------------------------------------------*/
600
601} // End namespace Arcane
602
603/*---------------------------------------------------------------------------*/
604/*---------------------------------------------------------------------------*/
Information for constructing an instance of IApplication.
void setVerbosityLevel(Int32 v)
Sets the message verbosity level of reduced listing files.
void setOutputDirectory(const String &name)
Sets the directory containing the various simulation outputs.
VersionInfo codeVersion() const
Version number.
void setOutputLevel(Int32 v)
Sets the message verbosity level on standard output.
String configFileName() const
Name of the code configuration file.
void addDynamicLibrary(const String &lib_name)
Adds the library lib_name to the list of dynamically loaded libraries.
void internalSetDefaultMessagePassingService(const String &name)
Default message passing manager name. Must only be modified by Arcane.
void setCodeName(const String &code_name)
Sets the code name.
String applicationName() const
Application name.
void setApplicationName(const String &v)
Sets the application name.
String codeName() const
Returns the code name.
CaseDatasetSource & caseDatasetSource()
Dataset source.
void setConfigFileName(const String &name)
Sets the code configuration file.
void setCodeVersion(const VersionInfo &version_info)
Sets the code version.
String threadBindingStrategy() const
Strategy for binding task threads.
Application information.
void setApplicationName(const String &v)
Sets the application name.
Information for initializing an application.
void parseArgumentsAndSetDefaultsValues(const CommandLineArguments &args)
Parses the arguments in args.
Source of a case dataset.
Integer count() const
Number of elements in the collection.
void fillParameters(StringList &param_names, StringList &values) const
Retrieves the list of parameters and their values.
Information about a version.
Definition VersionInfo.h:47
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
List< String > StringList
Unicode string list.
Definition UtilsTypes.h:509
std::int32_t Int32
Signed integer type of 32 bits.