14#include "arccore/concurrency/ITaskImplementation.h"
16#include "arccore/concurrency/Task.h"
17#include "arccore/concurrency/ParallelFor.h"
18#include "arccore/concurrency/internal/TaskFactoryInternal.h"
20#include "arccore/base/Observable.h"
42 static const int FUNCTOR_CLASS_SIZE =
sizeof(TaskType);
54 m_functor = f->clone(functor_buf, FUNCTOR_CLASS_SIZE);
72 tasks[i]->launchAndWait();
81 ITaskFunctor* m_functor;
82 char functor_buf[FUNCTOR_CLASS_SIZE];
124 loop_info.functor()->
executeFunctor(loop_info.beginIndex(), loop_info.size());
130 functor->executeFunctor(loop_ranges);
136 functor->executeFunctor(loop_ranges);
142 functor->executeFunctor(loop_ranges);
148 functor->executeFunctor(loop_ranges);
165 o <<
"NullTaskImplementation";
172NullTaskImplementation NullTaskImplementation::singleton;
173ITaskImplementation* TaskFactory::m_impl = &NullTaskImplementation::singleton;
174Int32 TaskFactory::m_verbose_level = 0;
181 IObservable* global_created_thread_observable = 0;
182 IObservable* global_destroyed_thread_observable = 0;
183 std::mutex global_observable_mutex;
186 _checkCreateGlobalThreadObservable()
188 if (!global_created_thread_observable)
189 global_created_thread_observable =
new Observable();
190 return global_created_thread_observable;
197void TaskFactoryInternal::
200 if (TaskFactory::m_impl && TaskFactory::m_impl != &NullTaskImplementation::singleton)
201 ARCCORE_FATAL(
"TaskFactory already has an implementation");
202 TaskFactory::m_impl = task_impl;
208 std::scoped_lock slock(global_observable_mutex);
209 _checkCreateGlobalThreadObservable();
210 global_created_thread_observable->attachObserver(o);
216 std::scoped_lock slock(global_observable_mutex);
217 _checkCreateGlobalThreadObservable();
218 global_created_thread_observable->detachObserver(o);
224 std::scoped_lock slock(global_observable_mutex);
225 if (global_created_thread_observable)
226 global_created_thread_observable->notifyAllObservers();
238 TaskFactoryInternal::setImplementation(task_impl);
247 std::scoped_lock slock(global_observable_mutex);
248 return _checkCreateGlobalThreadObservable();
257 if (!global_destroyed_thread_observable)
258 global_destroyed_thread_observable =
new Observable();
259 return global_destroyed_thread_observable;
269 if (m_impl == &NullTaskImplementation::singleton)
273 m_impl = &NullTaskImplementation::singleton;
Interval d'itération complexe.
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 observateur.
Interface d'un fonctor sur un interval d'itération.
virtual void executeFunctor(Int32 begin, Int32 size)=0
Exécute la méthode associée.
Interface d'un fonctor pour une tâche.
virtual void executeFunctor(const TaskContext &tc)=0
Exécute la méthode associé
Implémentation d'une fabrique de tâches.
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()
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.
void terminate() override
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.
void initialize(Int32 nb_thread) override
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 void removeThreadCreateObserver(IObserver *o)
Supprime un observateur pour la création de thread.
static void notifyThreadCreated()
Notifie tous les observateurs de création de thread.
static void addThreadCreateObserver(IObserver *o)
Ajoute un observateur pour la création de thread.
static IObservable * destroyThreadObservable()
Observable appelé lors de la destruction d'un thread pour une tâche.
static void terminate()
Indique qu'on n'utilisera plus les threads. Cette méthode ne doit pas être appelée lorsque des tâches...
static IObservable * createThreadObservable()
Observable appelé lors de la création d'un thread pour une tâche.
static void _internalSetImplementation(ITaskImplementation *task_impl)
Fonctor sans argument 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.