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];
97 void initialize([[maybe_unused]]
Int32 nb_thread)
override
100 void terminate()
override
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)
202 TaskFactory::m_impl = task_impl;
205void TaskFactoryInternal::
208 std::scoped_lock slock(global_observable_mutex);
209 _checkCreateGlobalThreadObservable();
210 global_created_thread_observable->attachObserver(o);
213void TaskFactoryInternal::
216 std::scoped_lock slock(global_observable_mutex);
217 _checkCreateGlobalThreadObservable();
218 global_created_thread_observable->detachObserver(o);
221void TaskFactoryInternal::
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;
#define ARCCORE_FATAL(...)
Macro throwing a FatalErrorException.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
Loop execution information.
Interface of a functor on a multi-dimensional iteration interval of dimension RankValue.
Interface of an observable.
Interface of a functor on an iteration interval.
virtual void executeFunctor(Int32 begin, Int32 size)=0
Executes the associated method.
virtual void executeFunctor(const TaskContext &tc)=0
Executes the associated method.
Interface for a concurrent task.
void executeParallelFor(const ComplexForLoopRanges< 4 > &loop_ranges, const ForLoopRunInfo &run_info, IMDRangeFunctor< 4 > *functor) override
Executes a 4D loop in parallel.
void printInfos(std::ostream &o) const final
Prints information about the runtime used.
Int32 currentTaskIndex() const override
Implementation of TaskFactory::currentTaskIndex().
void executeParallelFor(Integer begin, Integer size, IRangeFunctor *f) override
Executes the functor f in parallel.
void executeParallelFor(const ComplexForLoopRanges< 3 > &loop_ranges, const ForLoopRunInfo &run_info, IMDRangeFunctor< 3 > *functor) override
Executes a 3D loop in parallel.
void executeParallelFor(const ComplexForLoopRanges< 1 > &loop_ranges, const ForLoopRunInfo &run_info, IMDRangeFunctor< 1 > *functor) override
Executes a 1D loop in parallel.
void executeParallelFor(const ComplexForLoopRanges< 2 > &loop_ranges, const ForLoopRunInfo &run_info, IMDRangeFunctor< 2 > *functor) override
Executes a 2D loop in parallel.
void executeParallelFor(const ParallelFor1DLoopInfo &loop_info) override
Executes the loop loop_info in parallel.
ITask * createRootTask(ITaskFunctor *f) override
Creates a root task. The implementation must copy the value of f, which is either a TaskFunctor or a ...
bool isActive() const override
Indicates if the implementation is active.
void executeParallelFor(Integer begin, Integer size, Integer block_size, IRangeFunctor *f) override
Executes the functor f in parallel.
Int32 currentTaskThreadIndex() const override
Implementation of TaskFactory::currentTaskThreadIndex().
void executeParallelFor(Integer begin, Integer size, const ParallelLoopOptions &options, IRangeFunctor *f) override
Executes the functor f in parallel.
Base class of an observable.
Characteristics of a multi-thread 1D loop.
Execution options for a parallel loop in multi-threading.
void launchAndWait() override
Launches the task and blocks until it finishes.
void launchAndWait(ConstArrayView< ITask * > tasks) override
Launches the child tasks tasks and blocks until they finish.
Execution context of a task.
static IObservable * destroyThreadObservable()
Observable called when a thread is destroyed for a task.
static IObservable * createThreadObservable()
Observable called when a thread is created for a task.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
std::int32_t Int32
Signed integer type of 32 bits.