Arcane  v3.15.0.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ForLoopRanges.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/* ForLoopRanges.h (C) 2000-2025 */
9/* */
10/* Intervalles d'itérations pour les boucles. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_FORLOOPRANGES_H
13#define ARCANE_UTILS_FORLOOPRANGES_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/ArrayBounds.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane::impl
23{
28{
29 public:
30
32 template <typename... ReducerArgs> static inline void
34 {
35 // Applique les réductions
36 (reducer_args._internalReduceHost(), ...);
37 }
38};
39}
40
41namespace Arcane
42{
43
44/*---------------------------------------------------------------------------*/
45/*---------------------------------------------------------------------------*/
50{
51 public:
52
54 ForLoopRange(Int32 lower_bound, Int32 size)
55 : m_lower_bound(lower_bound)
56 , m_size(size)
57 {}
59 ForLoopRange(Int32 size)
60 : m_lower_bound(0)
61 , m_size(size)
62 {}
63
64 public:
65
66 constexpr Int32 lowerBound() const { return m_lower_bound; }
67 constexpr Int32 size() const { return m_size; }
68 constexpr Int32 upperBound() const { return m_lower_bound + m_size; }
69
70 private:
71
72 Int32 m_lower_bound;
73 Int32 m_size;
74};
75
76/*---------------------------------------------------------------------------*/
77/*---------------------------------------------------------------------------*/
83template <int N, typename IndexType_>
85{
86 friend class ComplexForLoopRanges<N>;
87
88 public:
89
91 using ArrayIndexType = typename ArrayBoundsType::IndexType;
92 using IndexType = ArrayIndexType;
93
94 public:
95
96 explicit SimpleForLoopRanges(std::array<Int32, N> b)
97 : m_bounds(b)
98 {}
100 : m_bounds(b)
101 {}
102
103 public:
104
105 template <Int32 I> constexpr Int32 lowerBound() const { return 0; }
106 template <Int32 I> constexpr Int32 upperBound() const { return m_bounds.template constExtent<I>(); }
107 template <Int32 I> constexpr Int32 extent() const { return m_bounds.template constExtent<I>(); }
108 constexpr Int64 nbElement() const { return m_bounds.nbElement(); }
109 constexpr ArrayIndexType getIndices(Int32 i) const { return m_bounds.getIndices(i); }
110
111 private:
112
113 ArrayBoundsType m_bounds;
114};
115
116/*---------------------------------------------------------------------------*/
117/*---------------------------------------------------------------------------*/
125template <int N, typename IndexType_>
127{
128 public:
129
131 using ArrayIndexType = typename ArrayBoundsType::IndexType;
132 using IndexType = ArrayIndexType;
133
134 public:
135
137 : m_lower_bounds(lower.asStdArray())
138 , m_extents(extents)
139 {}
141 : m_extents(bounds.m_bounds)
142 {}
143
144 public:
145
146 template <Int32 I> constexpr Int32 lowerBound() const { return m_lower_bounds[I]; }
147 template <Int32 I> constexpr Int32 upperBound() const { return m_lower_bounds[I] + m_extents.template constExtent<I>(); }
148 template <Int32 I> constexpr Int32 extent() const { return m_extents.template constExtent<I>(); }
149 constexpr Int64 nbElement() const { return m_extents.nbElement(); }
150 constexpr ArrayIndexType getIndices(Int32 i) const
151 {
152 auto x = m_extents.getIndices(i);
153 x.add(m_lower_bounds);
154 return x;
155 }
156 constexpr ArrayBoundsType extents() const { return m_extents; }
157
158 private:
159
160 ArrayIndexType m_lower_bounds;
161 ArrayBoundsType m_extents;
162};
163
164/*---------------------------------------------------------------------------*/
165/*---------------------------------------------------------------------------*/
169{
171 using ArrayExtentType = typename BoundsType::ArrayExtentType;
172
173 return BoundsType(ArrayExtentType(n1));
174}
175
177inline SimpleForLoopRanges<2>
178makeLoopRanges(Int32 n1, Int32 n2)
179{
181 using ArrayExtentType = typename BoundsType::ArrayExtentType;
182
183 return BoundsType(ArrayExtentType(n1, n2));
184}
185
187inline SimpleForLoopRanges<3>
188makeLoopRanges(Int32 n1, Int32 n2, Int32 n3)
189{
191 using ArrayExtentType = typename BoundsType::ArrayExtentType;
192
193 return BoundsType(ArrayExtentType(n1, n2, n3));
194}
195
197inline SimpleForLoopRanges<4>
198makeLoopRanges(Int32 n1, Int32 n2, Int32 n3, Int32 n4)
199{
201 using ArrayExtentType = typename BoundsType::ArrayExtentType;
202
203 return BoundsType(ArrayExtentType(n1, n2, n3, n4));
204}
205
207inline ComplexForLoopRanges<1>
209{
211 using ArrayExtentType = typename BoundsType::ArrayExtentType;
212
213 BoundsType lower_bounds(ArrayExtentType(n1.lowerBound()));
214 BoundsType sizes(ArrayExtentType(n1.size()));
215 return { lower_bounds, sizes };
216}
217
219inline ComplexForLoopRanges<2>
221{
223 using ArrayExtentType = typename BoundsType::ArrayExtentType;
224
225 BoundsType lower_bounds(ArrayExtentType(n1.lowerBound(), n2.lowerBound()));
226 BoundsType sizes(ArrayExtentType(n1.size(), n2.size()));
227 return { lower_bounds, sizes };
228}
229
231inline ComplexForLoopRanges<3>
233{
235 using ArrayExtentType = typename BoundsType::ArrayExtentType;
236
237 BoundsType lower_bounds(ArrayExtentType(n1.lowerBound(), n2.lowerBound(), n3.lowerBound()));
238 BoundsType sizes(ArrayExtentType(n1.size(), n2.size(), n3.size()));
239 return { lower_bounds, sizes };
240}
241
243inline ComplexForLoopRanges<4>
245{
247 using ArrayExtentType = typename BoundsType::ArrayExtentType;
248
249 BoundsType lower_bounds(ArrayExtentType(n1.lowerBound(), n2.lowerBound(), n3.lowerBound(), n4.lowerBound()));
250 BoundsType sizes(ArrayExtentType(n1.size(), n2.size(), n3.size(), n4.size()));
251 return { lower_bounds, sizes };
252}
253
254/*---------------------------------------------------------------------------*/
255/*---------------------------------------------------------------------------*/
257template <typename IndexType, template <int T, typename> class LoopBoundType,
258 typename Lambda, typename... ReducerArgs>
259inline void
266
268template <typename IndexType, template <int T, typename> class LoopBoundType, typename Lambda> inline void
270{
271 for (Int32 i0 = bounds.template lowerBound<0>(); i0 < bounds.template upperBound<0>(); ++i0)
272 for (Int32 i1 = bounds.template lowerBound<1>(); i1 < bounds.template upperBound<1>(); ++i1)
273 func(MDIndex<2>(i0, i1));
274}
275
277template <typename IndexType, template <int T, typename> class LoopBoundType, typename Lambda> inline void
279{
280 for (Int32 i0 = bounds.template lowerBound<0>(); i0 < bounds.template upperBound<0>(); ++i0)
281 for (Int32 i1 = bounds.template lowerBound<1>(); i1 < bounds.template upperBound<1>(); ++i1)
282 for (Int32 i2 = bounds.template lowerBound<2>(); i2 < bounds.template upperBound<2>(); ++i2)
283 func(MDIndex<3>(i0, i1, i2));
284}
285
287template <typename IndexType, template <int, typename> class LoopBoundType, typename Lambda> inline void
289{
290 for (Int32 i0 = bounds.template lowerBound<0>(); i0 < bounds.template upperBound<0>(); ++i0)
291 for (Int32 i1 = bounds.template lowerBound<1>(); i1 < bounds.template upperBound<1>(); ++i1)
292 for (Int32 i2 = bounds.template lowerBound<2>(); i2 < bounds.template upperBound<2>(); ++i2)
293 for (Int32 i3 = bounds.template lowerBound<3>(); i3 < bounds.template upperBound<3>(); ++i3)
294 func(MDIndex<4>(i0, i1, i2, i3));
295}
296
297/*---------------------------------------------------------------------------*/
298/*---------------------------------------------------------------------------*/
299
300} // End namespace Arcane
301
302/*---------------------------------------------------------------------------*/
303/*---------------------------------------------------------------------------*/
304
305#endif
Interval d'itération complexe.
Intervalle d'itération pour une boucle.
ForLoopRange(Int32 size)
Créé un interval entre *[0,size[*.
ForLoopRange(Int32 lower_bound, Int32 size)
Créé un interval entre *[lower_bound,lower_bound+size[*.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:149
Interval d'itération simple.
Classe pour appliquer la finalisation des réductions.
static void applyReducerArgs(ReducerArgs &... reducer_args)
Applique les fonctors des arguments additionnels.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
void arcaneSequentialFor(LoopBoundType< 1, IndexType > bounds, const Lambda &func, ReducerArgs... reducer_args)
Applique le fonctor func sur une boucle 1D.
SimpleForLoopRanges< 1 > makeLoopRanges(Int32 n1)
Créé un intervalle d'itération [0,n1[.