Arcane  v4.1.0.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
TaskFactory.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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/* TaskFactory.h (C) 2000-2025 */
9/* */
10/* Fabrique pour les tâches. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_CONCURRENCY_TASKFACTORY_H
13#define ARCCORE_CONCURRENCY_TASKFACTORY_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/base/ConcurrencyBase.h"
18#include "arccore/concurrency/Task.h"
19#include "arccore/concurrency/ITaskImplementation.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
33class ARCCORE_CONCURRENCY_EXPORT TaskFactory
34{
35 friend TaskFactoryInternal;
36
37 public:
38
39 TaskFactory() = delete;
40
41 public:
42
48 template <typename InstanceType> static ITask*
49 createTask(InstanceType* instance, void (InstanceType::*function)(const TaskContext& tc))
50 {
51 TaskFunctorWithContext<InstanceType> functor(instance, function);
52 return m_impl->createRootTask(&functor);
53 }
54
60 template <typename InstanceType> static ITask*
61 createTask(InstanceType* instance, void (InstanceType::*function)())
62 {
63 TaskFunctor<InstanceType> functor(instance, function);
64 return m_impl->createRootTask(&functor);
65 }
66
73 template <typename InstanceType> static ITask*
74 createChildTask(ITask* parent_task, InstanceType* instance, void (InstanceType::*function)(const TaskContext& tc))
75 {
76 ARCCORE_CHECK_POINTER(parent_task);
77 TaskFunctorWithContext<InstanceType> functor(instance, function);
78 return parent_task->_createChildTask(&functor);
79 }
80
87 template <typename InstanceType> static ITask*
88 createChildTask(ITask* parent_task, InstanceType* instance, void (InstanceType::*function)())
89 {
90 ARCCORE_CHECK_POINTER(parent_task);
91 TaskFunctor<InstanceType> functor(instance, function);
92 return parent_task->_createChildTask(&functor);
93 }
94
96 static void executeParallelFor(Integer begin, Integer size, const ParallelLoopOptions& options, IRangeFunctor* f)
97 {
98 m_impl->executeParallelFor(begin, size, options, f);
99 }
100
102 static void executeParallelFor(Integer begin, Integer size, Integer block_size, IRangeFunctor* f)
103 {
104 m_impl->executeParallelFor(begin, size, block_size, f);
105 }
106
108 static void executeParallelFor(Integer begin, Integer size, IRangeFunctor* f)
109 {
110 m_impl->executeParallelFor(begin, size, f);
111 }
112
114 static void executeParallelFor(const ParallelFor1DLoopInfo& loop_info)
115 {
116 m_impl->executeParallelFor(loop_info);
117 }
118
120 static void executeParallelFor(const ComplexForLoopRanges<1>& loop_ranges,
121 const ParallelLoopOptions& options,
122 IMDRangeFunctor<1>* functor)
123 {
124 m_impl->executeParallelFor(loop_ranges, ForLoopRunInfo(options), functor);
125 }
126
128 static void executeParallelFor(const ComplexForLoopRanges<1>& loop_ranges,
129 const ForLoopRunInfo& run_info,
130 IMDRangeFunctor<1>* functor)
131 {
132 m_impl->executeParallelFor(loop_ranges, run_info, functor);
133 }
134
136 static void executeParallelFor(const ComplexForLoopRanges<2>& loop_ranges,
137 const ParallelLoopOptions& options,
138 IMDRangeFunctor<2>* functor)
139 {
140 m_impl->executeParallelFor(loop_ranges, ForLoopRunInfo(options), functor);
141 }
142
144 static void executeParallelFor(const ComplexForLoopRanges<2>& loop_ranges,
145 const ForLoopRunInfo& run_info,
146 IMDRangeFunctor<2>* functor)
147 {
148 m_impl->executeParallelFor(loop_ranges, run_info, functor);
149 }
150
152 static void executeParallelFor(const ComplexForLoopRanges<3>& loop_ranges,
153 const ParallelLoopOptions& options,
154 IMDRangeFunctor<3>* functor)
155 {
156 m_impl->executeParallelFor(loop_ranges, ForLoopRunInfo(options), functor);
157 }
158
160 static void executeParallelFor(const ComplexForLoopRanges<3>& loop_ranges,
161 const ForLoopRunInfo& run_info,
162 IMDRangeFunctor<3>* functor)
163 {
164 m_impl->executeParallelFor(loop_ranges, run_info, functor);
165 }
166
168 static void executeParallelFor(const ComplexForLoopRanges<4>& loop_ranges,
169 const ParallelLoopOptions& options,
170 IMDRangeFunctor<4>* functor)
171 {
172 m_impl->executeParallelFor(loop_ranges, ForLoopRunInfo(options), functor);
173 }
174
176 static void executeParallelFor(const ComplexForLoopRanges<4>& loop_ranges,
177 const ForLoopRunInfo& run_info,
178 IMDRangeFunctor<4>* functor)
179 {
180 m_impl->executeParallelFor(loop_ranges, run_info, functor);
181 }
182
185
194 {
195 return m_impl->currentTaskThreadIndex();
196 }
197
212 {
213 return m_impl->currentTaskIndex();
214 }
215
216 public:
217
218 // TODO: rendre ces deux méthodes obsolètes et indiquer d'utiliser
219 // celles de ConcurrencyBase à la place.
220
226
232
233 public:
234
240 static bool isActive()
241 {
242 return m_impl->isActive();
243 }
244
251 static void printInfos(std::ostream& o)
252 {
253 return m_impl->printInfos(o);
254 }
255
264 ARCCORE_DEPRECATED_REASON("Y2024: This method is internal to Arcane. Do not use it")
265 static IObservable* createThreadObservable();
266
275 ARCCORE_DEPRECATED_REASON("Y2024: This method is internal to Arcane. Do not use it")
276 static IObservable* destroyThreadObservable();
277
283 static void terminate();
284
285 public:
286
288 static void setVerboseLevel(Integer v) { m_verbose_level = v; }
289
291 static Integer verboseLevel() { return m_verbose_level; }
292
293 public:
294
296 ARCCORE_DEPRECATED_REASON("Y2024: This method is internal to Arcane. "
297 "Use TaskFactoryInternal::setImplementation() instead")
298 static void _internalSetImplementation(ITaskImplementation* task_impl);
299
300 private:
301
302 static ITaskImplementation* m_impl;
303 static Int32 m_verbose_level;
304};
305
306/*---------------------------------------------------------------------------*/
307/*---------------------------------------------------------------------------*/
308
309} // End namespace Arcane
310
311/*---------------------------------------------------------------------------*/
312/*---------------------------------------------------------------------------*/
313
314#endif
static void setDefaultParallelLoopOptions(const ParallelLoopOptions &v)
Positionne les valeurs par défaut d'exécution d'une boucle parallèle.
static Int32 maxAllowedThread()
Nombre maximum de threads autorisés pour le multi-threading.
static const ParallelLoopOptions & defaultParallelLoopOptions()
Valeurs par défaut d'exécution d'une boucle parallèle.
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 fonctor sur un interval d'itération.
Implémentation d'une fabrique de tâches.
Interface d'une tâche concourante.
Definition Task.h:186
Caractéristiques d'un boucle 1D multi-thread.
Definition ParallelFor.h:34
Options d'exécution d'une boucle parallèle en multi-thread.
Contexte d'éxecution d'une tâche.
Definition Task.h:46
static Int32 currentTaskIndex()
Indice (entre 0 et nbAllowedThread()-1) de la tâche actuelle.
static void executeParallelFor(const ParallelFor1DLoopInfo &loop_info)
Exécute la boucle loop_info en concurrence.
static void setVerboseLevel(Integer v)
Positionne le niveau de verbosité (0 pour pas d'affichage qui est le défaut)
static Int32 nbAllowedThread()
Nombre de threads utilisés au maximum pour gérer les tâches.
static void executeParallelFor(Integer begin, Integer size, IRangeFunctor *f)
Exécute le fonctor f en concurrence.
static ITask * createTask(InstanceType *instance, void(InstanceType::*function)())
Créé une tâche. Lors de l'exécution, la tâche appellera la méthode function via l'instance instance.
Definition TaskFactory.h:61
static const ParallelLoopOptions & defaultParallelLoopOptions()
Valeurs par défaut d'exécution d'une boucle parallèle.
static void executeParallelFor(const ComplexForLoopRanges< 1 > &loop_ranges, const ParallelLoopOptions &options, IMDRangeFunctor< 1 > *functor)
Exécute une boucle simple.
static void executeParallelFor(const ComplexForLoopRanges< 1 > &loop_ranges, const ForLoopRunInfo &run_info, IMDRangeFunctor< 1 > *functor)
Exécute une boucle simple.
static void executeParallelFor(const ComplexForLoopRanges< 2 > &loop_ranges, const ForLoopRunInfo &run_info, IMDRangeFunctor< 2 > *functor)
Exécute une boucle 2D.
static Integer verboseLevel()
Niveau de verbosité
static void executeParallelFor(const ComplexForLoopRanges< 4 > &loop_ranges, const ParallelLoopOptions &options, IMDRangeFunctor< 4 > *functor)
Exécute une boucle 4D.
static void executeParallelFor(const ComplexForLoopRanges< 2 > &loop_ranges, const ParallelLoopOptions &options, IMDRangeFunctor< 2 > *functor)
Exécute une boucle 2D.
static void setDefaultParallelLoopOptions(const ParallelLoopOptions &v)
Positionne les valeurs par défaut d'exécution d'une boucle parallèle.
static void executeParallelFor(Integer begin, Integer size, const ParallelLoopOptions &options, IRangeFunctor *f)
Exécute le fonctor f en concurrence.
Definition TaskFactory.h:96
static void executeParallelFor(Integer begin, Integer size, Integer block_size, IRangeFunctor *f)
Exécute le fonctor f en concurrence.
static void executeParallelFor(const ComplexForLoopRanges< 3 > &loop_ranges, const ParallelLoopOptions &options, IMDRangeFunctor< 3 > *functor)
Exécute une boucle 3D.
static ITask * createChildTask(ITask *parent_task, InstanceType *instance, void(InstanceType::*function)(const TaskContext &tc))
Créé une tâche fille.
Definition TaskFactory.h:74
static Int32 currentTaskThreadIndex()
Indice (entre 0 et nbAllowedThread()-1) du thread exécutant la tâche actuelle.
static ITask * createChildTask(ITask *parent_task, InstanceType *instance, void(InstanceType::*function)())
Créé une tâche fille.
Definition TaskFactory.h:88
static bool isActive()
Indique si les tâches sont actives. Les tâches sont actives si une implémentation est disponible et s...
static ITask * createTask(InstanceType *instance, void(InstanceType::*function)(const TaskContext &tc))
Créé une tâche. Lors de l'exécution, la tâche appellera la méthode function via l'instance instance.
Definition TaskFactory.h:49
static void executeParallelFor(const ComplexForLoopRanges< 4 > &loop_ranges, const ForLoopRunInfo &run_info, IMDRangeFunctor< 4 > *functor)
Exécute une boucle 4D.
static void printInfos(std::ostream &o)
Affiche les informations sur l'implémentation.
static void executeParallelFor(const ComplexForLoopRanges< 3 > &loop_ranges, const ForLoopRunInfo &run_info, IMDRangeFunctor< 3 > *functor)
Exécute une boucle 3D.
Fonctor pour une tâche prenant un TaskContext en argument.
Definition Task.h:143
Fonctor sans argument pour une tâche.
Definition Task.h:98
-*- 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.