Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
ApplicationBuildInfo.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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-2024 */
9/* */
10/* Informations pour construire une instance de IApplication. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/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/ValueConvert.h"
20#include "arcane/utils/CommandLineArguments.h"
21#include "arcane/utils/TraceClassConfig.h"
22#include "arcane/utils/ApplicationInfo.h"
23
24#include "arcane/CaseDatasetSource.h"
25
26#include <functional>
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31namespace Arcane
32{
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
37namespace
38{
39void _clamp(Int32& x,Int32 min_value,Int32 max_value)
40{
41 x = std::min(std::max(x,min_value),max_value);
42}
43}
44
45/*---------------------------------------------------------------------------*/
46/*---------------------------------------------------------------------------*/
47
49{
50 public:
52 {
53 public:
54 NameValuePair(const String& n,const String& v) : name(n), value(v){}
55 String name;
56 String value;
57 };
58 template<typename DataType>
60 {
61 public:
62 explicit Property(DataType default_value)
63 : m_value(default_value), m_default_value(default_value), m_has_value(false){}
64 Property() : Property(DataType()) {}
65 Property<DataType>& operator=(const DataType& v) { setValue(v); return (*this); }
66 operator DataType() const { return m_value; }
67 public:
68 void setValue(const DataType& v)
69 {
70 if (m_validator){
71 DataType copy(v);
72 m_validator(copy);
73 m_value = copy;
74 }
75 else
76 m_value = v;
77 m_has_value = true;
78 }
79 DataType value() const { return m_value; }
80 bool isValueSet() const { return m_has_value; }
81 void setValidator(std::function<void(DataType&)>&& func) { m_validator = func; }
82 private:
83 DataType m_value;
84 DataType m_default_value;
85 bool m_has_value;
86 std::function<void(DataType&)> m_validator;
87 };
89 {
90 public:
91 explicit Int32Value(Int32 v) : value(v){}
92 operator Int32() const { return value; }
93 public:
94 Int32Value minValue(Int32 x)
95 {
96 return Int32Value(std::max(value,x));
97 }
98 Int32Value maxValue(Int32 x)
99 {
100 return Int32Value(std::min(value,x));
101 }
102 public:
103 Int32 value;
104 };
105 public:
106 Impl()
107 : m_nb_task_thread(-1), m_nb_shared_memory_sub_domain(0),
108 m_nb_replication_sub_domain(0), m_nb_processus_sub_domain(0),
109 m_config_file_name("")
110 {
111 // Fixe une limite pour le nombre de tâches
112 m_nb_task_thread.setValidator([](Int32& x){ _clamp(x,-1,512); });
113 // Fixe une limite en dur pour éviter d'avoir trop de sous-domaines
114 // en mémoire partagé (le maximum est en général le nombre de coeurs par
115 // noeud)
116 m_nb_shared_memory_sub_domain.setValidator([](Int32& x){ _clamp(x,0,1024); });
117 m_nb_replication_sub_domain.setValidator([](Int32& x){ x = std::max(x,0); });
118 m_nb_processus_sub_domain.setValidator([](Int32& x){ x = std::max(x,0); });
119 }
120 public:
121 Property<String> m_message_passing_service;
122 Property<StringList> m_task_implementation_services;
123 Property<StringList> m_thread_implementation_services;
124 Property<Int32> m_nb_task_thread;
125 Property<Int32> m_nb_shared_memory_sub_domain;
126 Property<Int32> m_nb_replication_sub_domain;
127 Property<Int32> m_nb_processus_sub_domain;
128 Property<String> m_config_file_name;
129 Property<Int32> m_output_level;
130 Property<Int32> m_verbosity_level;
131 Property<Int32> m_minimal_verbosity_level;
132 Property<bool> m_is_master_has_output_file;
133 Property<String> m_output_directory;
134 Property<String> m_thread_binding_strategy;
135 UniqueArray<NameValuePair> m_values;
136 ApplicationInfo m_app_info;
137 CaseDatasetSource m_case_dataset_source;
138 String m_default_message_passing_service;
139
140 public:
141 /*!
142 * \brief Récupère la valeur d'une option.
143 *
144 * L'ordre de récupération est le suivant:
145 * - si \a param_name est non nul, regarde s'il existe une valeur
146 * dans \a m_values associée à ce paramètre. Si oui, on retourne cette
147 * valeur.
148 * - pour chaque nom \a x de \a env_values, regarde si une variable
149 * d'environnement \a x existe et retourne sa valeur si c'est le cas.
150 * - si aucune des méthodes précédente n'a fonctionnée, retourne
151 * la valeur \a default_value.
152 */
153 String getValue(const UniqueArray<String>& env_values,const String& param_name,
154 const String& default_value)
155 {
156 if (!param_name.null()){
157 String v = _searchParam(param_name);
158 if (!v.null())
159 return v;
160 }
161 for( const auto& x : env_values ){
162 String ev = platform::getEnvironmentVariable(x);
163 if (!ev.null())
164 return ev;
165 }
166 return default_value;
167 }
168 Int32Value getInt32(const String& str_value,Int32 default_value)
169 {
170 Int32 v = default_value;
171 if (!str_value.null()){
172 bool is_bad = builtInGetValue(v,str_value);
173 if (is_bad)
174 v = default_value;
175 }
176 return Int32Value(v);
177 }
178 void checkSet(Property<bool>& p,const String& str_value)
179 {
180 if (p.isValueSet())
181 return;
182 if (str_value.null())
183 return;
184 bool v = 0;
185 bool is_bad = builtInGetValue(v,str_value);
186 if (!is_bad)
187 p.setValue(v);
188 }
189 void checkSet(Property<Int32>& p,const String& str_value)
190 {
191 if (p.isValueSet())
192 return;
193 if (str_value.null())
194 return;
195 Int32 v = 0;
196 bool is_bad = builtInGetValue(v,str_value);
197 if (!is_bad)
198 p.setValue(v);
199 }
200 void checkSet(Property<StringList>& p,const String& str_value)
201 {
202 if (p.isValueSet())
203 return;
204 if (str_value.null())
205 return;
206 StringList s;
207 s.add(str_value);
208 p.setValue(s);
209 }
210 void checkSet(Property<StringList>& p,const StringList& str_values)
211 {
212 if (p.isValueSet())
213 return;
214 p.setValue(str_values);
215 }
216 void checkSet(Property<String>& p,const String& str_value)
217 {
218 if (p.isValueSet())
219 return;
220 if (str_value.null())
221 return;
222 p.setValue(str_value);
223 }
224 private:
225 String _searchParam(const String& param_name)
226 {
227 String v;
228 // Une option peut être présente plusieurs fois. Prend la dernière.
229 for( const auto& x : m_values ){
230 if (x.name==param_name)
231 v = x.value;
232 }
233 return v;
234 }
235};
236
237/*---------------------------------------------------------------------------*/
238/*---------------------------------------------------------------------------*/
239
240ApplicationBuildInfo::
241ApplicationBuildInfo()
242: m_p(new Impl())
243{
244}
245
246/*---------------------------------------------------------------------------*/
247/*---------------------------------------------------------------------------*/
248
249ApplicationBuildInfo::
250ApplicationBuildInfo(const ApplicationBuildInfo& rhs)
251: m_p(new Impl(*rhs.m_p))
252{
253}
254
255ApplicationBuildInfo& ApplicationBuildInfo::
256operator=(const ApplicationBuildInfo& rhs)
257{
258 if (&rhs!=this){
259 delete m_p;
260 m_p = new Impl(*(rhs.m_p));
261 }
262 return (*this);
263}
264
265/*---------------------------------------------------------------------------*/
266/*---------------------------------------------------------------------------*/
267
268ApplicationBuildInfo::
269~ApplicationBuildInfo()
270{
271 delete m_p;
272}
273
274/*---------------------------------------------------------------------------*/
275/*---------------------------------------------------------------------------*/
276
277void ApplicationBuildInfo::
278setDefaultValues()
279{
280 {
281 String str = m_p->getValue( { "ARCANE_NB_TASK" }, "T", String() );
282 m_p->checkSet(m_p->m_nb_task_thread,str);
283 }
284 {
285 String str = m_p->getValue( { "ARCANE_NB_THREAD" }, "S", String() );
286 m_p->checkSet(m_p->m_nb_shared_memory_sub_domain,str);
287 }
288 {
289 String str = m_p->getValue( { "ARCANE_NB_REPLICATION" }, "R", String() );
290 m_p->checkSet(m_p->m_nb_replication_sub_domain,str);
291 }
292 {
293 String str = m_p->getValue( { "ARCANE_NB_SUB_DOMAIN" }, "P", String() );
294 m_p->checkSet(m_p->m_nb_processus_sub_domain,str);
295 }
296 {
297 String str = m_p->getValue( { "ARCANE_OUTPUT_LEVEL" }, "OutputLevel",
298 String::fromNumber(Trace::UNSPECIFIED_VERBOSITY_LEVEL) );
299 m_p->checkSet(m_p->m_output_level,str);
300 }
301 {
302 String str = m_p->getValue( { "ARCANE_VERBOSITY_LEVEL", "ARCANE_VERBOSE_LEVEL" }, "VerbosityLevel",
303 String::fromNumber(Trace::UNSPECIFIED_VERBOSITY_LEVEL) );
304 m_p->checkSet(m_p->m_verbosity_level,str);
305 }
306 {
307 String str = m_p->getValue( { }, "MinimalVerbosityLevel",
308 String::fromNumber(Trace::UNSPECIFIED_VERBOSITY_LEVEL) );
309 m_p->checkSet(m_p->m_minimal_verbosity_level,str);
310 }
311 {
312 String str = m_p->getValue( { "ARCANE_MASTER_HAS_OUTPUT_FILE" }, "MasterHasOutputFile", "0" );
313 m_p->checkSet(m_p->m_is_master_has_output_file,str);
314 }
315 {
316 String str = m_p->getValue( { "ARCANE_OUTPUT_DIRECTORY" }, "OutputDirectory",
317 String() );
318 m_p->checkSet(m_p->m_output_directory,str);
319 }
320 {
321 String str = m_p->getValue( { }, "CaseDatasetFileName",
322 String() );
323 if (!str.null())
324 m_p->m_case_dataset_source.setFileName(str);
325 }
326 {
327 String str = m_p->getValue( { "ARCANE_THREAD_BINDING_STRATEGY" }, "ThreadBindingStrategy",
328 String() );
329 m_p->checkSet(m_p->m_thread_binding_strategy,str);
330 }
331}
332
333/*---------------------------------------------------------------------------*/
334/*---------------------------------------------------------------------------*/
335
336void ApplicationBuildInfo::
337setDefaultServices()
338{
339 bool has_shm = nbSharedMemorySubDomain()>0;
340 {
341 String str = m_p->getValue( { "ARCANE_TASK_IMPLEMENTATION" }, "TaskService", "TBB");
342 String service_name = str+"TaskImplementation";
343 m_p->checkSet(m_p->m_task_implementation_services,service_name);
344 }
345 {
346 StringList list1;
347 String thread_str = m_p->getValue( { "ARCANE_THREAD_IMPLEMENTATION" }, "ThreadService" ,"TBB");
348 list1.add(thread_str+"ThreadImplementationService");
349 list1.add("StdThreadImplementationService");
350 m_p->checkSet(m_p->m_thread_implementation_services,list1);
351 }
352 {
353 String def_name = (has_shm) ? "Thread" : "Sequential";
354 String default_service_name = def_name+"ParallelSuperMng";
355 // Positionne la valeur par défaut si ce n'est pas déjà fait.
356 if (m_p->m_default_message_passing_service.null())
357 m_p->m_default_message_passing_service = default_service_name;
358
359 String str = m_p->getValue( { "ARCANE_PARALLEL_SERVICE" }, "MessagePassingService", String() );
360 if (!str.null()){
361 String service_name = str+"ParallelSuperMng";
362 m_p->checkSet(m_p->m_message_passing_service,service_name);
363 }
364 }
365}
366
367/*---------------------------------------------------------------------------*/
368/*---------------------------------------------------------------------------*/
369
370void ApplicationBuildInfo::
371setMessagePassingService(const String& name)
372{
373 m_p->m_message_passing_service = name;
374}
375
376String ApplicationBuildInfo::
377messagePassingService() const
378{
379 return m_p->m_message_passing_service;
380}
381
382/*---------------------------------------------------------------------------*/
383/*---------------------------------------------------------------------------*/
384
385void ApplicationBuildInfo::
386setTaskImplementationService(const String& name)
387{
388 StringList s;
389 s.add(name);
390 m_p->m_task_implementation_services = s;
391}
392void ApplicationBuildInfo::
393setTaskImplementationServices(const StringList& names)
394{
395 m_p->m_task_implementation_services = names;
396}
397StringList ApplicationBuildInfo::
398taskImplementationServices() const
399{
400 return m_p->m_task_implementation_services;
401}
402
403/*---------------------------------------------------------------------------*/
404/*---------------------------------------------------------------------------*/
405
406void ApplicationBuildInfo::
407setThreadImplementationService(const String& name)
408{
409 StringList s;
410 s.add(name);
411 m_p->m_thread_implementation_services = s;
412}
413void ApplicationBuildInfo::
414setThreadImplementationServices(const StringList& names)
415{
416 m_p->m_thread_implementation_services = names;
417}
418StringList ApplicationBuildInfo::
419threadImplementationServices() const
420{
421 return m_p->m_thread_implementation_services;
422}
423
424/*---------------------------------------------------------------------------*/
425/*---------------------------------------------------------------------------*/
426
427Int32 ApplicationBuildInfo::
428nbTaskThread() const
429{
430 return m_p->m_nb_task_thread;
431}
432
433/*---------------------------------------------------------------------------*/
434/*---------------------------------------------------------------------------*/
435
436void ApplicationBuildInfo::
437setNbTaskThread(Int32 v)
438{
439 m_p->m_nb_task_thread = v;
440}
441
442/*---------------------------------------------------------------------------*/
443/*---------------------------------------------------------------------------*/
444
445Int32 ApplicationBuildInfo::
446nbSharedMemorySubDomain() const
447{
448 return m_p->m_nb_shared_memory_sub_domain;
449}
450
451/*---------------------------------------------------------------------------*/
452/*---------------------------------------------------------------------------*/
453
454void ApplicationBuildInfo::
455setNbSharedMemorySubDomain(Int32 v)
456{
457 m_p->m_nb_shared_memory_sub_domain = v;
458}
459
460/*---------------------------------------------------------------------------*/
461/*---------------------------------------------------------------------------*/
462
463Int32 ApplicationBuildInfo::
464nbReplicationSubDomain() const
465{
466 return m_p->m_nb_replication_sub_domain;
467}
468
469/*---------------------------------------------------------------------------*/
470/*---------------------------------------------------------------------------*/
471
472void ApplicationBuildInfo::
473setNbReplicationSubDomain(Int32 v)
474{
475 m_p->m_nb_replication_sub_domain = v;
476}
477
478/*---------------------------------------------------------------------------*/
479/*---------------------------------------------------------------------------*/
480
481Int32 ApplicationBuildInfo::
482nbProcessusSubDomain() const
483{
484 return m_p->m_nb_processus_sub_domain;
485}
486
487/*---------------------------------------------------------------------------*/
488/*---------------------------------------------------------------------------*/
489
490void ApplicationBuildInfo::
491setNbProcessusSubDomain(Int32 v)
492{
493 m_p->m_nb_processus_sub_domain = v;
494}
495
496/*---------------------------------------------------------------------------*/
497/*---------------------------------------------------------------------------*/
498
500configFileName() const
501{
502 return m_p->m_config_file_name;
503}
504
505/*---------------------------------------------------------------------------*/
506/*---------------------------------------------------------------------------*/
507
510{
511 m_p->m_config_file_name = v;
512}
513
514/*---------------------------------------------------------------------------*/
515/*---------------------------------------------------------------------------*/
516
517Int32 ApplicationBuildInfo::
518outputLevel() const
519{
520 return m_p->m_output_level;
521}
522
524setOutputLevel(Int32 v)
525{
526 m_p->m_output_level = v;
527}
528
529/*---------------------------------------------------------------------------*/
530/*---------------------------------------------------------------------------*/
531
532Int32 ApplicationBuildInfo::
533verbosityLevel() const
534{
535 return m_p->m_verbosity_level;
536}
537
539setVerbosityLevel(Int32 v)
540{
541 m_p->m_verbosity_level = v;
542}
543
544/*---------------------------------------------------------------------------*/
545/*---------------------------------------------------------------------------*/
546
547Int32 ApplicationBuildInfo::
548minimalVerbosityLevel() const
549{
550 return m_p->m_minimal_verbosity_level;
551}
552
553void ApplicationBuildInfo::
554setMinimalVerbosityLevel(Int32 v)
555{
556 m_p->m_minimal_verbosity_level = v;
557}
558
559/*---------------------------------------------------------------------------*/
560/*---------------------------------------------------------------------------*/
561
562bool ApplicationBuildInfo::
563isMasterHasOutputFile() const
564{
565 return m_p->m_is_master_has_output_file;
566}
567
568void ApplicationBuildInfo::
569setIsMasterHasOutputFile(bool v)
570{
571 m_p->m_is_master_has_output_file = v;
572}
573
574/*---------------------------------------------------------------------------*/
575/*---------------------------------------------------------------------------*/
576
577String ApplicationBuildInfo::
578outputDirectory() const
579{
580 return m_p->m_output_directory;
581}
582
583/*---------------------------------------------------------------------------*/
584/*---------------------------------------------------------------------------*/
585
588{
589 m_p->m_output_directory = v;
590}
591
592/*---------------------------------------------------------------------------*/
593/*---------------------------------------------------------------------------*/
594
597{
598 return m_p->m_thread_binding_strategy;
599}
600
603{
604 m_p->m_thread_binding_strategy = v;
605}
606
607/*---------------------------------------------------------------------------*/
608/*---------------------------------------------------------------------------*/
609
610void ApplicationBuildInfo::
611addParameter(const String& name,const String& value)
612{
613 m_p->m_values.add(Impl::NameValuePair(name,value));
614}
615
616/*---------------------------------------------------------------------------*/
617/*---------------------------------------------------------------------------*/
618
620parseArguments(const CommandLineArguments& command_line_args)
621{
622 // On ne récupère que les arguments du style:
623 // -A,x=b,y=c
624 StringList names;
625 StringList values;
626 command_line_args.fillParameters(names,values);
627 for( Integer i=0, n=names.count(); i<n; ++i ){
628 addParameter(names[i],values[i]);
629 }
630 setDefaultValues();
631}
632
633/*---------------------------------------------------------------------------*/
634/*---------------------------------------------------------------------------*/
635
636ApplicationInfo& ApplicationBuildInfo::
637_internalApplicationInfo()
638{
639 return m_p->m_app_info;
640}
641
642/*---------------------------------------------------------------------------*/
643/*---------------------------------------------------------------------------*/
644
645const ApplicationInfo& ApplicationBuildInfo::
646_internalApplicationInfo() const
647{
648 return m_p->m_app_info;
649}
650
651/*---------------------------------------------------------------------------*/
652/*---------------------------------------------------------------------------*/
653
656{
657 m_p->m_app_info.setApplicationName(v);
658}
660applicationName() const
661{
662 return m_p->m_app_info.applicationName();
663}
664
665/*---------------------------------------------------------------------------*/
666/*---------------------------------------------------------------------------*/
667
669setCodeVersion(const VersionInfo& version_info)
670{
671 m_p->m_app_info.setCodeVersion(version_info);
672}
673
675codeVersion() const
676{
677 return m_p->m_app_info.codeVersion();
678}
679
680/*---------------------------------------------------------------------------*/
681/*---------------------------------------------------------------------------*/
682
684setCodeName(const String& code_name)
685{
686 m_p->m_app_info.setCodeName(code_name);
687}
688
690codeName() const
691{
692 return m_p->m_app_info.codeName();
693}
694
695/*---------------------------------------------------------------------------*/
696/*---------------------------------------------------------------------------*/
697
700{
701 return m_p->m_case_dataset_source;
702}
703
705caseDatasetSource() const
706{
707 return m_p->m_case_dataset_source;
708}
709
710/*---------------------------------------------------------------------------*/
711/*---------------------------------------------------------------------------*/
712
714addDynamicLibrary(const String& lib_name)
715{
716 m_p->m_app_info.addDynamicLibrary(lib_name);
717}
718
719/*---------------------------------------------------------------------------*/
720/*---------------------------------------------------------------------------*/
721
724{
725 m_p->m_default_message_passing_service = name;
726}
727
728/*---------------------------------------------------------------------------*/
729/*---------------------------------------------------------------------------*/
730
731String ApplicationBuildInfo::
732internalDefaultMessagePassingService() const
733{
734 return m_p->m_default_message_passing_service;
735}
736
737/*---------------------------------------------------------------------------*/
738/*---------------------------------------------------------------------------*/
739
740} // End namespace Arcane
741
742/*---------------------------------------------------------------------------*/
743/*---------------------------------------------------------------------------*/
744
String getValue(const UniqueArray< String > &env_values, const String &param_name, const String &default_value)
Récupère la valeur d'une option.
void setVerbosityLevel(Int32 v)
Positionne le niveau de verbosité des messages des fichiers listings réduits.
void setOutputDirectory(const String &name)
Positionne le répertoire contenant les différentes sorties de la simulation.
VersionInfo codeVersion() const
Numéro de version.
void setOutputLevel(Int32 v)
Positionne le niveau de verbosité des messages sur la sortie standard.
String configFileName() const
Nom du fichier de configuration du code.
void addDynamicLibrary(const String &lib_name)
Ajoute la bibliothèque lib_name à la liste des bibliothèques chargées dynamiquements.
void internalSetDefaultMessagePassingService(const String &name)
Nom du gestionnaire de message par défaut. Ne doit être modifié que par Arcane.
void setCodeName(const String &code_name)
Positionne le nom du code.
String applicationName() const
Nom de l'application.
void parseArguments(const CommandLineArguments &args)
Analyse les arguments de args.
void setApplicationName(const String &v)
Positionne le nom de l'application.
String codeName() const
Retourne le nom du code.
CaseDatasetSource & caseDatasetSource()
Source du jeu de données.
void setConfigFileName(const String &name)
Positionne le fichier de configuration du code.
void setCodeVersion(const VersionInfo &version_info)
Positionne le numéro de version du code.
String threadBindingStrategy() const
Stratégie pour punaiser les threads des tâches.
Informations sur une application.
const String & codeName() const
Retourne le nom du code de calcul lié l'application.
void setCodeVersion(const VersionInfo &version_info)
Positionne le numéro de version.
const String & applicationName() const
Nom de l'application.
void addDynamicLibrary(const String &lib_name)
Ajoute la bibliothèque lib_name à la liste des bibliothèques chargées dynamiquements.
const VersionInfo & codeVersion() const
Numéro de version.
void setApplicationName(const String &v)
Positionne le nom de l'application.
void setCodeName(const String &code_name)
Positionne le nom du code.
Source d'un jeu de données d'un cas.
void setFileName(const String &name)
Positionne le nom du fichier du jeu de données.
Integer count() const
Nombre d'éléments de la collection.
Definition Collection.h:70
Arguments de la ligne de commande.
void fillParameters(StringList &param_names, StringList &values) const
Récupère la liste des paramètres et leur valeur.
Informations sur une version.
Definition VersionInfo.h:46
Chaîne de caractères unicode.
bool null() const
Retourne true si la chaîne est nulle.
Definition String.cc:304
Vecteur 1D de données avec sémantique par valeur (style STL).
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
List< String > StringList
Tableau de chaînes de caractères unicode.
Definition UtilsTypes.h:667