Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
MatConcurrency.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* MatConcurrency.h (C) 2000-2021 */
9/* */
10/* Classes managing concurrency for materials. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_MATERIALS_MATCONCURRENCY_H
13#define ARCANE_MATERIALS_MATCONCURRENCY_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18#include "arcane/utils/RangeFunctor.h"
19#include "arcane/utils/FatalErrorException.h"
20
22
23#include "arcane/materials/MatItemEnumerator.h"
24#include "arcane/materials/ComponentItemVectorView.h"
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane::Materials
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35/*!
36 * \brief Functor over an iteration interval instantiated via a lambda function.
37 *
38 * The type \a ViewType must be chosen from ComponentItemVectorView,
39 * MatItemVectorView or EnvItemVectorView.
40 */
41template <typename ViewType, typename LambdaType>
42class LambdaMatItemRangeFunctorT
43: public IRangeFunctor
44{
45 public:
46
47 LambdaMatItemRangeFunctorT(ViewType items_view, const LambdaType& lambda_function)
48 : m_items(items_view)
49 , m_lambda_function(lambda_function)
50 {
51 }
52
53 public:
54
55 virtual void executeFunctor(Integer begin, Integer size)
56 {
57 ViewType sub_view(m_items._subView(begin, size));
58 m_lambda_function(sub_view);
59 }
60
61 private:
62
63 ViewType m_items;
64 const LambdaType& m_lambda_function;
65};
66
67/*---------------------------------------------------------------------------*/
68/*---------------------------------------------------------------------------*/
69
70} // End namespace Arcane::Materials
71
72/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74
75namespace Arcane
76{
77using namespace Materials;
78
79/*---------------------------------------------------------------------------*/
80/*---------------------------------------------------------------------------*/
81
82/*!
83 * \brief Applies the lambda function \a lambda_function
84 * \a instance concurrently on the component view \a items_view.
85 * \ingroup Concurrency
86 */
87template <typename LambdaType> inline void
88arcaneParallelForeach(const ComponentItemVectorView& items_view, const LambdaType& lambda_function)
89{
91 TaskFactory::executeParallelFor(0, items_view.nbItem(), &ipf);
92}
93
94/*!
95 * \brief Applies the lambda function \a lambda_function
96 * \a instance concurrently on the component view \a items_view with the options \a options.
97 * \ingroup Concurrency
98 */
99template <typename LambdaType> inline void
101 const LambdaType& lambda_function)
102{
104 TaskFactory::executeParallelFor(0, items_view.nbItem(), options, &ipf);
105}
106
107/*!
108 * \brief Applies the lambda function \a lambda_function
109 * \a instance concurrently on the environment view \a items_view.
110 * \ingroup Concurrency
111 */
112template <typename LambdaType> inline void
113arcaneParallelForeach(const EnvItemVectorView& items_view, const LambdaType& lambda_function)
114{
115 LambdaMatItemRangeFunctorT<EnvItemVectorView, LambdaType> ipf(items_view, lambda_function);
116 TaskFactory::executeParallelFor(0, items_view.nbItem(), &ipf);
117}
118
119/*!
120 * \brief Applies the lambda function \a lambda_function
121 * \a instance concurrently on the environment view \a items_view with the options \a options.
122 * \ingroup Concurrency
123 */
124template <typename LambdaType> inline void
126 const LambdaType& lambda_function)
127{
128 LambdaMatItemRangeFunctorT<EnvItemVectorView, LambdaType> ipf(items_view, lambda_function);
129 TaskFactory::executeParallelFor(0, items_view.nbItem(), options, &ipf);
130}
131
132/*!
133 * \brief Applies the lambda function \a lambda_function
134 * \a instance concurrently on the material view \a items_view.
135 * \ingroup Concurrency
136 */
137template <typename LambdaType> inline void
138arcaneParallelForeach(const MatItemVectorView& items_view, const LambdaType& lambda_function)
139{
140 LambdaMatItemRangeFunctorT<MatItemVectorView, LambdaType> ipf(items_view, lambda_function);
141 TaskFactory::executeParallelFor(0, items_view.nbItem(), &ipf);
142}
143
144/*!
145 * \brief Applies the lambda function \a lambda_function
146 * \a instance concurrently on the material view \a items_view with the options \a options.
147 * \ingroup Concurrency
148 */
149template <typename LambdaType> inline void
151 const LambdaType& lambda_function)
152{
153 LambdaMatItemRangeFunctorT<MatItemVectorView, LambdaType> ipf(items_view, lambda_function);
154 TaskFactory::executeParallelFor(0, items_view.nbItem(), options, &ipf);
155}
156} // End namespace Arcane
157
158/*---------------------------------------------------------------------------*/
159/*---------------------------------------------------------------------------*/
160
161namespace Arcane::Parallel
162{
163using namespace Materials;
164using namespace Arcane;
165
166/*!
167 * \brief Applies the lambda function \a lambda_function
168 * \a instance concurrently on the component view \a items_view.
169 * \ingroup Concurrency
170 */
171template <typename LambdaType> inline void
172Foreach(const ComponentItemVectorView& items_view, const LambdaType& lambda_function)
173{
174 arcaneParallelForeach(items_view, lambda_function);
175}
176
177/*!
178 * \brief Applies the lambda function \a lambda_function
179 * \a instance concurrently on the component view \a items_view with the options \a options.
180 * \ingroup Concurrency
181 */
182template <typename LambdaType> inline void
183Foreach(const ComponentItemVectorView& items_view, const ParallelLoopOptions& options,
184 const LambdaType& lambda_function)
185{
186 arcaneParallelForeach(items_view, options, lambda_function);
187}
188
189/*!
190 * \brief Applies the lambda function \a lambda_function
191 * \a instance concurrently on the environment view \a items_view.
192 * \ingroup Concurrency
193 */
194template <typename LambdaType> inline void
195Foreach(const EnvItemVectorView& items_view, const LambdaType& lambda_function)
196{
197 arcaneParallelForeach(items_view, lambda_function);
198}
199
200/*!
201 * \brief Applies the lambda function \a lambda_function
202 * \a instance concurrently on the environment view \a items_view with the options \a options.
203 * \ingroup Concurrency
204 */
205template <typename LambdaType> inline void
206Foreach(const EnvItemVectorView& items_view, const ParallelLoopOptions& options,
207 const LambdaType& lambda_function)
208{
209 arcaneParallelForeach(items_view, options, lambda_function);
210}
211
212/*!
213 * \brief Applies the lambda function \a lambda_function
214 * \a instance concurrently on the material view \a items_view.
215 * \ingroup Concurrency
216 */
217template <typename LambdaType> inline void
218Foreach(const MatItemVectorView& items_view, const LambdaType& lambda_function)
219{
220 arcaneParallelForeach(items_view, lambda_function);
221}
222
223/*!
224 * \brief Applies the lambda function \a lambda_function
225 * \a instance concurrently on the material view \a items_view with the options \a options.
226 * \ingroup Concurrency
227 */
228template <typename LambdaType> inline void
229Foreach(const MatItemVectorView& items_view, const ParallelLoopOptions& options,
230 const LambdaType& lambda_function)
231{
232 arcaneParallelForeach(items_view, options, lambda_function);
233}
234
235/*---------------------------------------------------------------------------*/
236/*---------------------------------------------------------------------------*/
237
238} // End namespace Arcane::Parallel
239
240/*---------------------------------------------------------------------------*/
241/*---------------------------------------------------------------------------*/
242
243#endif
Classes, Types, and macros for managing concurrency.
Declarations of types used in Arcane.
Interface of a functor on an iteration interval.
View over a vector of entities of a component.
Integer nbItem() const
Number of entities in the view.
View over a vector of entities of an environment.
Functor over an iteration interval instantiated via a lambda function.
virtual void executeFunctor(Integer begin, Integer size)
Executes the associated method.
View over a vector of entities of a material.
Execution options for a parallel loop in multi-threading.
static void executeParallelFor(Integer begin, Integer size, const ParallelLoopOptions &options, IRangeFunctor *f)
Executes the functor f in parallel.
Definition TaskFactory.h:97
void arcaneParallelForeach(const ItemVectorView &items_view, const ForLoopRunInfo &run_info, InstanceType *instance, void(InstanceType::*function)(ItemVectorViewT< ItemType > items))
Applies the method function of the instance instance concurrently on the view items_view with the opt...
Definition Concurrency.h:57
Always enables tracing in Arcane parts concerning materials.
Concurrency implementation.
void Foreach(const ItemVectorView &items_view, const ParallelLoopOptions &options, InstanceType *instance, void(InstanceType::*function)(ItemVectorViewT< ItemType > items))
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
Set of classes ensuring the management of materials and media.