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_BASE_TASKFACTORY_H
13#define ARCCORE_BASE_TASKFACTORY_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/concurrency/Task.h"
18#include "arccore/concurrency/ITaskImplementation.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
32class ARCCORE_CONCURRENCY_EXPORT TaskFactory
33{
34 friend TaskFactoryInternal;
35
36 public:
37
38 TaskFactory() = delete;
39
40 public:
41
47 template <typename InstanceType> static ITask*
48 createTask(InstanceType* instance, void (InstanceType::*function)(const TaskContext& tc))
49 {
50 TaskFunctorWithContext<InstanceType> functor(instance, function);
51 return m_impl->createRootTask(&functor);
52 }
53
59 template <typename InstanceType> static ITask*
60 createTask(InstanceType* instance, void (InstanceType::*function)())
61 {
62 TaskFunctor<InstanceType> functor(instance, function);
63 return m_impl->createRootTask(&functor);
64 }
65
72 template <typename InstanceType> static ITask*
73 createChildTask(ITask* parent_task, InstanceType* instance, void (InstanceType::*function)(const TaskContext& tc))
74 {
75 ARCCORE_CHECK_POINTER(parent_task);
76 TaskFunctorWithContext<InstanceType> functor(instance, function);
77 return parent_task->_createChildTask(&functor);
78 }
79
86 template <typename InstanceType> static ITask*
87 createChildTask(ITask* parent_task, InstanceType* instance, void (InstanceType::*function)())
88 {
89 ARCCORE_CHECK_POINTER(parent_task);
90 TaskFunctor<InstanceType> functor(instance, function);
91 return parent_task->_createChildTask(&functor);
92 }
93
95 static void executeParallelFor(Integer begin, Integer size, const ParallelLoopOptions& options, IRangeFunctor* f)
96 {
97 m_impl->executeParallelFor(begin, size, options, f);
98 }
99
101 static void executeParallelFor(Integer begin, Integer size, Integer block_size, IRangeFunctor* f)
102 {
103 m_impl->executeParallelFor(begin, size, block_size, f);
104 }
105
107 static void executeParallelFor(Integer begin, Integer size, IRangeFunctor* f)
108 {
109 m_impl->executeParallelFor(begin, size, f);
110 }
111
113 static void executeParallelFor(const ParallelFor1DLoopInfo& loop_info)
114 {
115 m_impl->executeParallelFor(loop_info);
116 }
117
119 static void executeParallelFor(const ComplexForLoopRanges<1>& loop_ranges,
120 const ParallelLoopOptions& options,
121 IMDRangeFunctor<1>* functor)
122 {
123 m_impl->executeParallelFor(loop_ranges, ForLoopRunInfo(options), functor);
124 }
125
127 static void executeParallelFor(const ComplexForLoopRanges<1>& loop_ranges,
128 const ForLoopRunInfo& run_info,
129 IMDRangeFunctor<1>* functor)
130 {
131 m_impl->executeParallelFor(loop_ranges, run_info, functor);
132 }
133
135 static void executeParallelFor(const ComplexForLoopRanges<2>& loop_ranges,
136 const ParallelLoopOptions& options,
137 IMDRangeFunctor<2>* functor)
138 {
139 m_impl->executeParallelFor(loop_ranges, ForLoopRunInfo(options), functor);
140 }
141
143 static void executeParallelFor(const ComplexForLoopRanges<2>& loop_ranges,
144 const ForLoopRunInfo& run_info,
145 IMDRangeFunctor<2>* functor)
146 {
147 m_impl->executeParallelFor(loop_ranges, run_info, functor);
148 }
149
151 static void executeParallelFor(const ComplexForLoopRanges<3>& loop_ranges,
152 const ParallelLoopOptions& options,
153 IMDRangeFunctor<3>* functor)
154 {
155 m_impl->executeParallelFor(loop_ranges, ForLoopRunInfo(options), functor);
156 }
157
159 static void executeParallelFor(const ComplexForLoopRanges<3>& loop_ranges,
160 const ForLoopRunInfo& run_info,
161 IMDRangeFunctor<3>* functor)
162 {
163 m_impl->executeParallelFor(loop_ranges, run_info, functor);
164 }
165
167 static void executeParallelFor(const ComplexForLoopRanges<4>& loop_ranges,
168 const ParallelLoopOptions& options,
169 IMDRangeFunctor<4>* functor)
170 {
171 m_impl->executeParallelFor(loop_ranges, ForLoopRunInfo(options), functor);
172 }
173
175 static void executeParallelFor(const ComplexForLoopRanges<4>& loop_ranges,
176 const ForLoopRunInfo& run_info,
177 IMDRangeFunctor<4>* functor)
178 {
179 m_impl->executeParallelFor(loop_ranges, run_info, functor);
180 }
181
184 {
185 return m_impl->nbAllowedThread();
186 }
187
196 {
197 return m_impl->currentTaskThreadIndex();
198 }
199
214 {
215 return m_impl->currentTaskIndex();
216 }
217
218 public:
219
222 {
223 m_default_loop_options = v;
224 }
225
228 {
229 return m_default_loop_options;
230 }
231
232 public:
233
239 static bool isActive()
240 {
241 return m_impl->isActive();
242 }
243
250 static void printInfos(std::ostream& o)
251 {
252 return m_impl->printInfos(o);
253 }
254
263 ARCCORE_DEPRECATED_REASON("Y2024: This method is internal to Arcane. Do not use it")
264 static IObservable* createThreadObservable();
265
274 ARCCORE_DEPRECATED_REASON("Y2024: This method is internal to Arcane. Do not use it")
275 static IObservable* destroyThreadObservable();
276
282 static void terminate();
283
284 public:
285
287 static void setVerboseLevel(Integer v) { m_verbose_level = v; }
288
290 static Integer verboseLevel() { return m_verbose_level; }
291
292 public:
293
295 ARCCORE_DEPRECATED_REASON("Y2024: This method is internal to Arcane. "
296 "Use TaskFactoryInternal::setImplementation() instead")
297 static void _internalSetImplementation(ITaskImplementation* task_impl);
298
299 private:
300
301 static ITaskImplementation* m_impl;
302 static Int32 m_verbose_level;
303 static ParallelLoopOptions m_default_loop_options;
304};
305
306/*---------------------------------------------------------------------------*/
307/*---------------------------------------------------------------------------*/
308
309} // End namespace Arcane
310
311/*---------------------------------------------------------------------------*/
312/*---------------------------------------------------------------------------*/
313
314#endif
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:187
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:47
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:60
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:95
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:73
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:87
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:48
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:144
Fonctor sans argument pour une tâche.
Definition Task.h:99
-*- 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.