16#include "arcane/utils/internal/TaskFactoryInternal.h"
17#include "arcane/utils/TraceInfo.h"
18#include "arcane/utils/Observable.h"
37 static const int FUNCTOR_CLASS_SIZE =
sizeof(TaskType);
47 m_functor = f->clone(functor_buf,FUNCTOR_CLASS_SIZE);
63 tasks[i]->launchAndWait();
70 ITaskFunctor* m_functor;
71 char functor_buf[FUNCTOR_CLASS_SIZE];
83 void initialize([[maybe_unused]]
Int32 nb_thread)
override
86 void terminate()
override
107 loop_info.functor()->
executeFunctor(loop_info.beginIndex(),loop_info.size());
113 functor->executeFunctor(loop_ranges);
119 functor->executeFunctor(loop_ranges);
125 functor->executeFunctor(loop_ranges);
131 functor->executeFunctor(loop_ranges);
152 o <<
"NullTaskImplementation";
159NullTaskImplementation NullTaskImplementation::singleton;
160ITaskImplementation* TaskFactory::m_impl = &NullTaskImplementation::singleton;
161Int32 TaskFactory::m_verbose_level = 0;
162ParallelLoopOptions TaskFactory::m_default_loop_options;
173IObservable* global_created_thread_observable = 0;
174IObservable* global_destroyed_thread_observable = 0;
175std::mutex global_observable_mutex;
178_checkCreateGlobalThreadObservable()
180 if (!global_created_thread_observable)
181 global_created_thread_observable =
new Observable();
182 return global_created_thread_observable;
193void TaskFactoryInternal::
196 if (TaskFactory::m_impl && TaskFactory::m_impl!=&NullTaskImplementation::singleton)
197 ARCANE_FATAL(
"TaskFactory already has an implementation");
198 TaskFactory::m_impl = task_impl;
201void TaskFactoryInternal::
204 std::scoped_lock slock(global_observable_mutex);
205 _checkCreateGlobalThreadObservable();
206 global_created_thread_observable->attachObserver(o);
209void TaskFactoryInternal::
212 std::scoped_lock slock(global_observable_mutex);
213 _checkCreateGlobalThreadObservable();
214 global_created_thread_observable->detachObserver(o);
217void TaskFactoryInternal::
220 std::scoped_lock slock(global_observable_mutex);
221 if (global_created_thread_observable)
222 global_created_thread_observable->notifyAllObservers();
234 TaskFactoryInternal::setImplementation(task_impl);
243 std::scoped_lock slock(global_observable_mutex);
244 return _checkCreateGlobalThreadObservable();
253 if (!global_destroyed_thread_observable)
254 global_destroyed_thread_observable =
new Observable();
255 return global_destroyed_thread_observable;
265 if (m_impl==&NullTaskImplementation::singleton)
269 m_impl = &NullTaskImplementation::singleton;
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Classes, Types et macros pour gérer la concurrence.
Vue constante d'un tableau de type T.
constexpr Integer size() const noexcept
Nombre d'éléments du tableau.
Informations d'exécution d'une boucle.
Interface d'un fonctor sur un interval d'itération multi-dimensionnel de dimension RankValue.
Interface d'un observable.
Interface d'un fonctor sur un interval d'itération.
virtual void executeFunctor(Integer begin, Integer size)=0
Exécute la méthode associée.
virtual void executeFunctor(const TaskContext &tc)=0
Exécute la méthode associé
Interface d'une tâche concourante.
void executeParallelFor(const ComplexForLoopRanges< 4 > &loop_ranges, const ForLoopRunInfo &run_info, IMDRangeFunctor< 4 > *functor) override
Exécute une boucle 4D en concurrence.
void printInfos(std::ostream &o) const final
Affiche les informations sur le runtime utilisé
Int32 currentTaskIndex() const override
Implémentation de TaskFactory::currentTaskIndex()
Int32 nbAllowedThread() const override
Nombre de threads utilisés au maximum pour gérer les tâches.
void executeParallelFor(Integer begin, Integer size, IRangeFunctor *f) override
Exécute le fonctor f en concurrence.
void executeParallelFor(const ComplexForLoopRanges< 3 > &loop_ranges, const ForLoopRunInfo &run_info, IMDRangeFunctor< 3 > *functor) override
Exécute une boucle 3D en concurrence.
void executeParallelFor(const ComplexForLoopRanges< 1 > &loop_ranges, const ForLoopRunInfo &run_info, IMDRangeFunctor< 1 > *functor) override
Exécute une boucle 1D en concurrence.
void executeParallelFor(const ComplexForLoopRanges< 2 > &loop_ranges, const ForLoopRunInfo &run_info, IMDRangeFunctor< 2 > *functor) override
Exécute une boucle 2D en concurrence.
void executeParallelFor(const ParallelFor1DLoopInfo &loop_info) override
Exécute la boucle loop_info en concurrence.
ITask * createRootTask(ITaskFunctor *f) override
Créé une tâche racine. L'implémentation doit recopier la valeur de f qui est soit un TaskFunctor,...
bool isActive() const override
Indique si l'implémentation est active.
void executeParallelFor(Integer begin, Integer size, Integer block_size, IRangeFunctor *f) override
Exécute le fonctor f en concurrence.
Int32 currentTaskThreadIndex() const override
Implémentation de TaskFactory::currentTaskThreadIndex()
void executeParallelFor(Integer begin, Integer size, const ParallelLoopOptions &options, IRangeFunctor *f) override
Exécute le fonctor f en concurrence.
Classe de base d'un observable.
Caractéristiques d'un boucle 1D multi-thread.
Options d'exécution d'une boucle parallèle en multi-thread.
void launchAndWait() override
Lance la tâche et bloque jusqu'à ce qu'elle se termine.
void launchAndWait(ConstArrayView< ITask * > tasks) override
Lance les tâches filles tasks et bloque jusqu'à ce qu'elles se terminent.
Contexte d'éxecution d'une tâche.
static IObservable * destroyThreadObservable()
Observable appelé lors de la destruction d'un thread pour une tâche.
static IObservable * createThreadObservable()
Observable appelé lors de la création d'un thread pour une tâche.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Int32 Integer
Type représentant un entier.
std::int32_t Int32
Type entier signé sur 32 bits.