Arcane  v3.15.3.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
Concurrency.h
Aller à la documentation de ce fichier.
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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/* Concurrency.h (C) 2000-2024 */
9/* */
10/* Classes gérant la concurrence (tâches, boucles parallèles, ...) */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_CONCURRENCY_H
13#define ARCANE_CORE_CONCURRENCY_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19#include "arcane/core/Item.h"
20#include "arcane/core/ItemFunctor.h"
21#include "arcane/core/ItemGroup.h"
22
23#include <arcane/core/materials/MatItem.h>
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane::impl
29{
30inline Int32
31adaptGrainSize(const ForLoopRunInfo& run_info)
32{
33 const std::optional<ParallelLoopOptions>& options = run_info.options();
34 Int32 grain_size = AbstractItemRangeFunctor::DEFAULT_GRAIN_SIZE;
35 if (options.has_value())
36 if (options.value().hasGrainSize())
37 grain_size = options.value().grainSize();
38 return grain_size;
39}
40} // namespace Arcane::impl
41
42namespace Arcane
43{
44
45/*---------------------------------------------------------------------------*/
46/*---------------------------------------------------------------------------*/
47/*!
48 * \ingroup Concurrency
49 *
50 * \brief Applique en concurrence la méthode \a function de l'instance
51 * \a instance sur la vue \a items_view avec les options \a options.
52 */
53template <typename InstanceType, typename ItemType> inline void
55 InstanceType* instance, void (InstanceType::*function)(ItemVectorViewT<ItemType> items))
56{
57 Int32 grain_size = impl::adaptGrainSize(run_info);
59
62 loop_opt.setGrainSize(ipf.blockGrainSize());
63 adapted_run_info.addOptions(loop_opt);
64
67}
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71/*!
72 * \brief Applique en concurrence la fonction lambda \a lambda_function
73 * \a instance sur la vue \a items_view avec les options \a options
74 * \ingroup Concurrency
75 */
76template <typename LambdaType> inline void
91
92/*---------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
94
95/*!
96 * \ingroup Concurrency
97 *
98 * \brief Applique en concurrence la méthode \a function de l'instance
99 * \a instance sur la vue \a items_view avec les options \a options.
100 */
101template <typename InstanceType, typename ItemType> inline void
103 InstanceType* instance, void (InstanceType::*function)(ItemVectorViewT<ItemType> items))
104{
105 arcaneParallelForeach(items_view, ForLoopRunInfo(options), instance, function);
106}
107
108/*!
109 * \ingroup Concurrency
110 *
111 * \brief Applique en concurrence la méthode \a function de l'instance
112 * \a instance sur le groupe \a items avec les options \a options.
113 */
114template <typename InstanceType, typename ItemType> inline void
116 InstanceType* instance, void (InstanceType::*function)(ItemVectorViewT<ItemType> items))
117{
118 arcaneParallelForeach(items._paddedView(), run_info, instance, function);
119}
120
121/*!
122 * \ingroup Concurrency
123 * \brief Applique en concurrence la méthode \a function de l'instance
124 * \a instance sur la vue \a items_view.
125 */
126template <typename InstanceType, typename ItemType> inline void
128 InstanceType* instance, void (InstanceType::*function)(ItemVectorViewT<ItemType> items))
129{
130 arcaneParallelForeach(items_view, ForLoopRunInfo(), instance, function);
131}
132
133/*!
134 * \ingroup Concurrency
135 * \brief Applique en concurrence la méthode \a function de l'instance
136 * \a instance sur le groupe \a items.
137 */
138template <typename InstanceType, typename ItemType> inline void
140 InstanceType* instance, void (InstanceType::*function)(ItemVectorViewT<ItemType> items))
141{
142 arcaneParallelForeach(items._paddedView(), ForLoopRunInfo(), instance, function);
143}
144
145/*!
146 * \brief Applique en concurrence la fonction lambda \a lambda_function
147 * \a instance sur la vue \a items_view avec les options \a options
148 * \ingroup Concurrency
149 */
150template <typename LambdaType> inline void
156
157/*!
158 * \brief Applique en concurrence la fonction lambda \a lambda_function
159 * sur le groupe \a items avec les options \a options
160 * \ingroup Concurrency
161 */
162template <typename LambdaType> inline void
168
169/*!
170 * \ingroup Concurrency
171 * \brief Applique en concurrence la fonction lambda \a lambda_function
172 * \a instance sur la vue \a items_view.
173 */
174template <typename LambdaType> inline void
179
180/*!
181 * \ingroup Concurrency
182 * \brief Applique en concurrence la fonction lambda \a lambda_function
183 * sur le groupe \a items.
184 */
185template <typename LambdaType> inline void
190
191/*---------------------------------------------------------------------------*/
192/*---------------------------------------------------------------------------*/
193/*!
194 * \ingroup Concurrency
195 * \brief Applique en concurrence la fonction lambda \a lambda_function
196 * sur l'intervalle d'itération [i0,i0+size].
197 */
198template <typename InstanceType> inline void
199arcaneParallelFor(Integer i0, Integer size, InstanceType* itype,
200 void (InstanceType::*lambda_function)(Integer i0, Integer size))
201{
205}
206
207/*!
208 * \ingroup Concurrency
209 * \brief Applique en concurrence la fonction lambda \a lambda_function
210 * sur l'intervalle d'itération [i0,i0+size] avec les options \a options.
211 */
212template <typename LambdaType> inline void
220
221/*!
222 * \ingroup Concurrency
223 * \brief Applique en concurrence la fonction lambda \a lambda_function
224 * sur l'intervalle d'itération [i0,i0+size] avec les options \a options.
225 */
226template <typename LambdaType> inline void
227arcaneParallelFor(Integer i0, Integer size, const ParallelLoopOptions& options,
229{
231}
232
233/*!
234 * \brief Applique en concurrence la fonction lambda \a lambda_function
235 * sur l'intervalle d'itération [i0,i0+size]
236 */
237template <typename LambdaType> inline void
244
245/*---------------------------------------------------------------------------*/
246/*---------------------------------------------------------------------------*/
247/*!
248 * \brief Applique en concurrence la fonction lambda \a lambda_function
249 * \a instance sur les vues des containers \a views avec les options \a options
250 * \ingroup Concurrency
251 */
252template <typename LambdaType, typename... Views> inline void
254{
255 // Asserting every views have the size
256 typename std::tuple_element_t<0, std::tuple<Views...>>::size_type sizes[] = {views.size()...};
257 if (!std::all_of(std::begin(sizes), std::end(sizes),[&sizes](auto cur){return cur == sizes[0];}))
258 ARCANE_FATAL("Every views must have the same size");
259
261
264}
265
266/*---------------------------------------------------------------------------*/
267/*---------------------------------------------------------------------------*/
268/*!
269 * \brief Implémentation de la concurrence.
270 *
271 * Les méthodes de ce namespace sont obsolètes et doivent être remplacées
272 * par les méthodes équivalentes dans le namespace Arcane.
273 * Par exemple Arcane::Parallel::For() doit être remplacé par Arcane::arcaneParallelFor()
274 * et Arcane::Parallel::Foreach() par Arcane::arcaneParallelForeach().
275 */
276namespace Parallel
277{
278 /*!
279 * \deprecated Use Arcane::arcaneParallelForeach() instead.
280 */
281 template <typename InstanceType, typename ItemType>
282 [[deprecated("Year2021: Use Arcane::arcaneParallelForeach() instead")]] inline void
284 InstanceType* instance, void (InstanceType::*function)(ItemVectorViewT<ItemType> items))
285 {
287 // Recopie \a options et utilise la valeur de 'grain_size' retournée par \a ifp
289 loop_opt.setGrainSize(ipf.blockGrainSize());
291 }
292
293 /*!
294 * \deprecated Use Arcane::arcaneParallelForeach() instead.
295 */
296 template <typename InstanceType, typename ItemType>
297 [[deprecated("Year2021: Use Arcane::arcaneParallelForeach() instead")]] inline void
298 Foreach(const ItemGroup& items, const ParallelLoopOptions& options, InstanceType* instance,
299 void (InstanceType::*function)(ItemVectorViewT<ItemType> items))
300 {
301 Foreach(items._paddedView(), options, instance, function);
302 }
303
304 /*!
305 * \deprecated Use Arcane::arcaneParallelForeach() instead.
306 */
307 template <typename InstanceType, typename ItemType>
308 [[deprecated("Year2021: Use Arcane::arcaneParallelForeach() instead")]] inline void
309 Foreach(const ItemVectorView& items_view, InstanceType* instance, void (InstanceType::*function)(ItemVectorViewT<ItemType> items))
310 {
312 TaskFactory::executeParallelFor(0, ipf.nbBlock(), ipf.blockGrainSize(), &ipf);
313 }
314
315 /*!
316 * \deprecated Use Arcane::arcaneParallelForeach() instead.
317 */
318 template <typename InstanceType, typename ItemType>
319 [[deprecated("Year2021: Use Arcane::arcaneParallelForeach() instead")]] inline void
320 Foreach(const ItemGroup& items, InstanceType* instance, void (InstanceType::*function)(ItemVectorViewT<ItemType> items))
321 {
322 Foreach(items._paddedView(), instance, function);
323 }
324
325 /*!
326 * \deprecated Use Arcane::arcaneParallelForeach() instead.
327 */
328 template <typename LambdaType>
329 [[deprecated("Year2021: Use Arcane::arcaneParallelForeach() instead")]] inline void
331 {
333 // Recopie \a options et utilise la valeur de 'grain_size' retournée par \a ifp
335 loop_opt.setGrainSize(ipf.blockGrainSize());
337 }
338
339 /*!
340 * \deprecated Use Arcane::arcaneParallelForeach() instead.
341 */
342 template <typename LambdaType>
343 [[deprecated("Year2021: Use Arcane::arcaneParallelForeach() instead")]] inline void
344 Foreach(const ItemGroup& items, const ParallelLoopOptions& options, const LambdaType& lambda_function)
345 {
346 Foreach(items._paddedView(), options, lambda_function);
347 }
348
349 /*!
350 * \deprecated Use Arcane::arcaneParallelForeach() instead.
351 */
352 template <typename LambdaType>
353 [[deprecated("Year2021: Use Arcane::arcaneParallelForeach() instead")]] inline void
359
360 /*!
361 * \deprecated Use Arcane::arcaneParallelForeach() instead.
362 */
363 template <typename LambdaType>
364 [[deprecated("Year2021: Use Arcane::arcaneParallelForeach() instead")]] inline void
366 {
368 }
369
370 /*!
371 * \deprecated Utiliser la surcharge For avec ParallelLoopOptions en argument.
372 */
373 template <typename InstanceType> ARCANE_DEPRECATED_122 inline void
374 For(Integer i0, Integer size, Integer grain_size, InstanceType* itype,
375 void (InstanceType::*lambda_function)(Integer i0, Integer size))
376 {
379 }
380
381 /*!
382 * \deprecated Use Arcane::arcaneParallelFor() instead.
383 */
384 template <typename InstanceType>
385 [[deprecated("Year2021: Use Arcane::arcaneParallelFor() instead")]] inline void
386 For(Integer i0, Integer size, const ParallelLoopOptions& options, InstanceType* itype,
387 void (InstanceType::*lambda_function)(Integer i0, Integer size))
388 {
390 TaskFactory::executeParallelFor(i0, size, options, &ipf);
391 }
392
393 /*!
394 * \deprecated Utiliser la surcharge For avec ParallelLoopOptions en argument.
395 */
396 template <typename LambdaType> ARCANE_DEPRECATED_122 inline void
402
403 /*!
404 * \deprecated Use Arcane::arcaneParallelFor() instead.
405 */
406 template <typename InstanceType>
407 [[deprecated("Year2021: Use Arcane::arcaneParallelFor() instead")]] inline void
408 For(Integer i0, Integer size, InstanceType* itype,
409 void (InstanceType::*lambda_function)(Integer i0, Integer size))
410 {
413 }
414
415 /*!
416 * \deprecated Use Arcane::arcaneParallelFor() instead.
417 */
418 template <typename LambdaType>
419 [[deprecated("Year2021: Use Arcane::arcaneParallelFor() instead")]] inline void
420 For(Integer i0, Integer size, const ParallelLoopOptions& options, const LambdaType& lambda_function)
421 {
423 TaskFactory::executeParallelFor(i0, size, options, &ipf);
424 }
425
426 /*!
427 * \deprecated Use Arcane::arcaneParallelFor() instead.
428 */
429 template <typename LambdaType>
430 [[deprecated("Year2021: Use Arcane::arcaneParallelFor() instead")]] inline void
436
437} // End namespace Parallel
438
439/*---------------------------------------------------------------------------*/
440/*---------------------------------------------------------------------------*/
441
442} // End namespace Arcane
443
444/*---------------------------------------------------------------------------*/
445/*---------------------------------------------------------------------------*/
446
447#endif
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Classes, Types et macros pour gérer la concurrence.
Informations d'exécution d'une boucle.
Groupe d'entités de maillage.
Definition ItemGroup.h:49
ItemVectorView _paddedView() const
Vue sur les entités du groupe avec padding pour la vectorisation.
Definition ItemGroup.cc:591
Vue sur un tableau typé d'entités.
Vue sur un vecteur d'entités.
Fonctor sur un interval d'itération instancié via une lambda fonction.
Caractéristiques d'un boucle 1D multi-thread.
Options d'exécution d'une boucle parallèle en multi-thread.
Integer grainSize() const
Taille d'un intervalle d'itération.
static const ParallelLoopOptions & defaultParallelLoopOptions()
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.
Référence à une instance.
void arcaneParallelForeach(const ItemVectorView &items_view, const ForLoopRunInfo &run_info, InstanceType *instance, void(InstanceType::*function)(ItemVectorViewT< ItemType > items))
Applique en concurrence la méthode function de l'instance instance sur la vue items_view avec les opt...
Definition Concurrency.h:54
void arcaneParallelForVa(const ForLoopRunInfo &run_info, const LambdaType &lambda_function, Views... views)
Applique en concurrence la fonction lambda lambda_function instance sur les vues des containers views...
void arcaneParallelFor(Integer i0, Integer size, InstanceType *itype, void(InstanceType::*lambda_function)(Integer i0, Integer size))
Applique en concurrence la fonction lambda lambda_function sur l'intervalle d'itération [i0,...
void Foreach(const ItemVectorView &items_view, const ParallelLoopOptions &options, InstanceType *instance, void(InstanceType::*function)(ItemVectorViewT< ItemType > items))
ARCANE_DEPRECATED_122 void For(Integer i0, Integer size, Integer grain_size, InstanceType *itype, void(InstanceType::*lambda_function)(Integer i0, Integer size))
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-