Arcane  v3.14.10.0
Documentation développeur
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/*---------------------------------------------------------------------------*/
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/*---------------------------------------------------------------------------*/
76template <typename LambdaType> inline void
91
92/*---------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
94
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
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
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
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
150template <typename LambdaType> inline void
156
162template <typename LambdaType> inline void
168
174template <typename LambdaType> inline void
179
185template <typename LambdaType> inline void
190
191/*---------------------------------------------------------------------------*/
192/*---------------------------------------------------------------------------*/
198template <typename InstanceType> inline void
199arcaneParallelFor(Integer i0, Integer size, InstanceType* itype,
200 void (InstanceType::*lambda_function)(Integer i0, Integer size))
201{
205}
206
212template <typename LambdaType> inline void
220
226template <typename LambdaType> inline void
227arcaneParallelFor(Integer i0, Integer size, const ParallelLoopOptions& options,
229{
231}
232
237template <typename LambdaType> inline void
244
245/*---------------------------------------------------------------------------*/
246/*---------------------------------------------------------------------------*/
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/*---------------------------------------------------------------------------*/
276namespace Parallel
277{
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
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
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
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
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
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
352 template <typename LambdaType>
353 [[deprecated("Year2021: Use Arcane::arcaneParallelForeach() instead")]] inline void
359
363 template <typename LambdaType>
364 [[deprecated("Year2021: Use Arcane::arcaneParallelForeach() instead")]] inline void
366 {
368 }
369
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
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
396 template <typename LambdaType> ARCANE_DEPRECATED_122 inline void
402
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
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
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.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
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.
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 -*-