Arcane  4.2.3.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
ConcurrencyApplication.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/* ConcurrencyApplication.h (C) 2000-2026 */
9/* */
10/* Gestion des services de multi-threading d'une application Arccore. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arccore/concurrency/internal/ConcurrencyApplication.h"
15
16#include "arccore/base/CheckedConvert.h"
17#include "arccore/base/PlatformUtils.h"
18#include "arccore/base/FatalErrorException.h"
19#include "arccore/base/IStackTraceService.h"
20#include "arccore/base/internal/DependencyInjection.h"
21
22#include "arccore/trace/ITraceMng.h"
23
24#include "arccore/concurrency/ITaskImplementation.h"
25#include "arccore/concurrency/IThreadImplementation.h"
26#include "arccore/concurrency/IThreadImplementationService.h"
27#include "arccore/concurrency/TaskFactory.h"
28#include "arccore/concurrency/internal/TaskFactoryInternal.h"
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33namespace Arcane
34{
35
36/*!
37 * Essaie d'instancier un service implémentant \a InterfaceType avec
38 * la liste de nom de services \a names. Retourne l'instance trouvée
39 * si elle existe et remplit \a found_name (si non nul) avec le nom de
40 * l'instance. Dès qu'une instance est trouvée, on la retourne.
41 * Retourne \a nullptr si aucune instance n'est disponible.
42 */
43template <typename InterfaceType> Ref<InterfaceType> ConcurrencyApplication::
44tryCreateServiceUsingInjector(ConstArrayView<String> names, String* found_name, bool has_trace)
45{
46 DependencyInjection::Injector injector;
47 injector.fillWithGlobalFactories();
48 // Ajoute une instance de ITraceMng* pour les services qui en ont besoin
49 if (has_trace)
50 injector.bind(m_trace.get());
51
52 if (found_name)
53 (*found_name) = String();
54 for (String s : names) {
55 auto t = injector.createInstance<InterfaceType>(s, true);
56 if (t.get()) {
57 if (found_name)
58 (*found_name) = s;
59 return t;
60 }
61 }
62 return {};
63}
64
65/*---------------------------------------------------------------------------*/
66/*---------------------------------------------------------------------------*/
67
68void ConcurrencyApplication::
69setCoreServices(const ConcurrencyApplicationBuildInfo& build_info)
70{
71
72 // Recherche le service utilisé pour connaitre la pile d'appel
73 bool has_dbghelp = false;
74 {
75 String dbghelp_service_name = "DbgHelpStackTraceService";
77 String found_name;
79 const auto v = Convert::Type<Int32>::tryParseFromEnvironment("ARCANE_USE_BACKWARDCPP", true);
80 if (v && v.value() != 0) {
81 names.add("BackwardCppStackTraceService");
82 }
83 names.add("LibUnwind");
84 names.add("DbgHelpStackTraceService");
85 sv = tryCreateServiceUsingInjector<IStackTraceService>(names.constView(), &found_name, true);
86 if (found_name == dbghelp_service_name)
87 has_dbghelp = true;
88 if (sv.get()) {
89 sv->build();
90 m_stack_trace_service = sv;
92 }
93 }
94
95 // Recherche le service utilisé pour connaitre les infos sur les symboles
96 // du code source. Pour l'instant, on ne supporte que LLVM et on n'active ce service
97 // que si la variable d'environnement ARCANE_LLVMSYMBOLIZER_PATH est définie.
98 {
100 String found_name;
102
103 if (!platform::getEnvironmentVariable("ARCANE_LLVMSYMBOLIZER_PATH").null())
104 names.add("LLVMSymbolizer");
105 if (has_dbghelp)
106 names.add("DbgHelpSymbolizerService");
107 sv = tryCreateServiceUsingInjector<ISymbolizerService>(names.constView(), &found_name, true);
108 if (sv.get()) {
109 m_symbolizer_service = sv;
111 }
112 }
113
114 // Recherche le service implémentant le support du multi-threading.
115 {
116 ConstArrayView<String> names = build_info.threadImplementationServices();
117 String found_name;
118 auto sv = tryCreateServiceUsingInjector<IThreadImplementationService>(names, &found_name, false);
119 if (!sv.get())
120 ARCCORE_FATAL("Can not find implementation for 'IThreadImplementation' (names='{0}').", names);
121 m_thread_implementation_service = sv;
122 m_thread_implementation = sv->createImplementation();
123 Arccore::Concurrency::setThreadImplementation(m_thread_implementation.get());
124 m_thread_implementation->initialize();
125 m_used_thread_service_name = found_name;
126 }
127
128 // Le gestionnaire de thread a pu changer et il faut donc
129 // reinitialiser le gestionnaire de trace.
130 m_trace->resetThreadStatus();
131
132 // Recherche le service utilisé pour gérer les tâches
133 {
134 Integer nb_task_thread = build_info.nbTaskThread();
135 if (nb_task_thread >= 0) {
136
137 ConstArrayView<String> names = build_info.taskImplementationServices();
138 String found_name;
139 auto sv = tryCreateServiceUsingInjector<ITaskImplementation>(names, &found_name, false);
140 if (sv.get()) {
141 TaskFactoryInternal::setImplementation(sv.get());
142 sv->initialize(nb_task_thread);
143 m_used_task_service_name = found_name;
144 m_task_implementation = sv;
145 }
146 else
147 ARCCORE_FATAL("Can not find task implementation service (names='{0}')."
148 " Please check if Arcane is configured with Intel TBB library",
149 names);
150 }
151
152 if (auto v = Convert::Type<Int32>::tryParseFromEnvironment("ARCANE_TASK_VERBOSE_LEVEL", true))
154 }
155}
156
157/*---------------------------------------------------------------------------*/
158/*---------------------------------------------------------------------------*/
159
160} // namespace Arcane
161
162/*---------------------------------------------------------------------------*/
163/*---------------------------------------------------------------------------*/
#define ARCCORE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Vue constante d'un tableau de type T.
Classe template pour convertir un type.
Référence à une instance.
Chaîne de caractères unicode.
static void setVerboseLevel(Integer v)
Positionne le niveau de verbosité (0 pour pas d'affichage qui est le défaut).
IStackTraceService * setStackTraceService(IStackTraceService *service)
Positionne le service utilisé pour obtenir la pile d'appel.
ISymbolizerService * setSymbolizerService(ISymbolizerService *service)
Positionne le service pour obtenir des informations sur les symboles du code source.
String getEnvironmentVariable(const String &name)
Variable d'environnement du nom name.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type représentant un entier.