12#ifndef ARCANE_UTILS_FORLOOPRANGES_H
13#define ARCANE_UTILS_FORLOOPRANGES_H
17#include "arcane/utils/ArrayBounds.h"
32 template <
typename... ReducerArgs>
static inline void
36 (reducer_args._internalReduceHost(), ...);
55 : m_lower_bound(lower_bound)
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; }
83template <
int N,
typename IndexType_>
91 using ArrayIndexType =
typename ArrayBoundsType::IndexType;
92 using IndexType = ArrayIndexType;
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 constexpr Int64 nbElement()
const {
return m_bounds.nbElement(); }
108 constexpr ArrayIndexType getIndices(Int32 i)
const {
return m_bounds.getIndices(i); }
124template <
int N,
typename IndexType_>
130 using ArrayIndexType =
typename ArrayBoundsType::IndexType;
131 using IndexType = ArrayIndexType;
136 : m_lower_bounds(lower.asStdArray())
140 : m_extents(bounds.m_bounds)
145 template <Int32 I>
constexpr Int32 lowerBound()
const {
return m_lower_bounds[I]; }
146 template <Int32 I>
constexpr Int32 upperBound()
const {
return m_lower_bounds[I] + m_extents.template constExtent<I>(); }
147 constexpr Int64 nbElement()
const {
return m_extents.nbElement(); }
148 constexpr ArrayIndexType getIndices(Int32 i)
const
150 auto x = m_extents.getIndices(i);
151 x.add(m_lower_bounds);
157 ArrayIndexType m_lower_bounds;
168 using ArrayExtentType =
typename BoundsType::ArrayExtentType;
170 return BoundsType(ArrayExtentType(n1));
174inline SimpleForLoopRanges<2>
178 using ArrayExtentType =
typename BoundsType::ArrayExtentType;
180 return BoundsType(ArrayExtentType(n1, n2));
184inline SimpleForLoopRanges<3>
188 using ArrayExtentType =
typename BoundsType::ArrayExtentType;
190 return BoundsType(ArrayExtentType(n1, n2, n3));
194inline SimpleForLoopRanges<4>
198 using ArrayExtentType =
typename BoundsType::ArrayExtentType;
200 return BoundsType(ArrayExtentType(n1, n2, n3, n4));
204inline ComplexForLoopRanges<1>
208 using ArrayExtentType =
typename BoundsType::ArrayExtentType;
210 BoundsType lower_bounds(ArrayExtentType(n1.lowerBound()));
211 BoundsType sizes(ArrayExtentType(n1.size()));
212 return { lower_bounds, sizes };
216inline ComplexForLoopRanges<2>
220 using ArrayExtentType =
typename BoundsType::ArrayExtentType;
222 BoundsType lower_bounds(ArrayExtentType(n1.lowerBound(), n2.lowerBound()));
223 BoundsType sizes(ArrayExtentType(n1.size(), n2.size()));
224 return { lower_bounds, sizes };
228inline ComplexForLoopRanges<3>
232 using ArrayExtentType =
typename BoundsType::ArrayExtentType;
234 BoundsType lower_bounds(ArrayExtentType(n1.lowerBound(), n2.lowerBound(), n3.lowerBound()));
235 BoundsType sizes(ArrayExtentType(n1.size(), n2.size(), n3.size()));
236 return { lower_bounds, sizes };
240inline ComplexForLoopRanges<4>
244 using ArrayExtentType =
typename BoundsType::ArrayExtentType;
246 BoundsType lower_bounds(ArrayExtentType(n1.lowerBound(), n2.lowerBound(), n3.lowerBound(), n4.lowerBound()));
247 BoundsType sizes(ArrayExtentType(n1.size(), n2.size(), n3.size(), n4.size()));
248 return { lower_bounds, sizes };
254template <
typename IndexType,
template <
int T,
typename>
class LoopBoundType,
255 typename Lambda,
typename... ReducerArgs>
259 for (Int32 i0 = bounds.template lowerBound<0>(); i0 < bounds.template upperBound<0>(); ++i0)
265template <
typename IndexType,
template <
int T,
typename>
class LoopBoundType,
typename Lambda>
inline void
268 for (Int32 i0 = bounds.template lowerBound<0>(); i0 < bounds.template upperBound<0>(); ++i0)
269 for (Int32 i1 = bounds.template lowerBound<1>(); i1 < bounds.template upperBound<1>(); ++i1)
274template <
typename IndexType,
template <
int T,
typename>
class LoopBoundType,
typename Lambda>
inline void
277 for (Int32 i0 = bounds.template lowerBound<0>(); i0 < bounds.template upperBound<0>(); ++i0)
278 for (Int32 i1 = bounds.template lowerBound<1>(); i1 < bounds.template upperBound<1>(); ++i1)
279 for (Int32 i2 = bounds.template lowerBound<2>(); i2 < bounds.template upperBound<2>(); ++i2)
284template <
typename IndexType,
template <
int,
typename>
class LoopBoundType,
typename Lambda>
inline void
287 for (Int32 i0 = bounds.template lowerBound<0>(); i0 < bounds.template upperBound<0>(); ++i0)
288 for (Int32 i1 = bounds.template lowerBound<1>(); i1 < bounds.template upperBound<1>(); ++i1)
289 for (Int32 i2 = bounds.template lowerBound<2>(); i2 < bounds.template upperBound<2>(); ++i2)
290 for (Int32 i3 = bounds.template lowerBound<3>(); i3 < bounds.template upperBound<3>(); ++i3)
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[*.
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[.