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 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); }
125template <
int N,
typename IndexType_>
131 using ArrayIndexType =
typename ArrayBoundsType::IndexType;
132 using IndexType = ArrayIndexType;
137 : m_lower_bounds(lower.asStdArray())
141 : m_extents(bounds.m_bounds)
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
152 auto x = m_extents.getIndices(i);
153 x.add(m_lower_bounds);
160 ArrayIndexType m_lower_bounds;
171 using ArrayExtentType =
typename BoundsType::ArrayExtentType;
173 return BoundsType(ArrayExtentType(n1));
177inline SimpleForLoopRanges<2>
181 using ArrayExtentType =
typename BoundsType::ArrayExtentType;
183 return BoundsType(ArrayExtentType(n1, n2));
187inline SimpleForLoopRanges<3>
191 using ArrayExtentType =
typename BoundsType::ArrayExtentType;
193 return BoundsType(ArrayExtentType(n1, n2, n3));
197inline SimpleForLoopRanges<4>
201 using ArrayExtentType =
typename BoundsType::ArrayExtentType;
203 return BoundsType(ArrayExtentType(n1, n2, n3, n4));
207inline ComplexForLoopRanges<1>
211 using ArrayExtentType =
typename BoundsType::ArrayExtentType;
213 BoundsType lower_bounds(ArrayExtentType(n1.lowerBound()));
214 BoundsType sizes(ArrayExtentType(n1.size()));
215 return { lower_bounds, sizes };
219inline ComplexForLoopRanges<2>
223 using ArrayExtentType =
typename BoundsType::ArrayExtentType;
225 BoundsType lower_bounds(ArrayExtentType(n1.lowerBound(), n2.lowerBound()));
226 BoundsType sizes(ArrayExtentType(n1.size(), n2.size()));
227 return { lower_bounds, sizes };
231inline ComplexForLoopRanges<3>
235 using ArrayExtentType =
typename BoundsType::ArrayExtentType;
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 };
243inline ComplexForLoopRanges<4>
247 using ArrayExtentType =
typename BoundsType::ArrayExtentType;
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 };
257template <
typename IndexType,
template <
int T,
typename>
class LoopBoundType,
258 typename Lambda,
typename... ReducerArgs>
262 for (Int32 i0 = bounds.template lowerBound<0>(); i0 < bounds.template upperBound<0>(); ++i0)
268template <
typename IndexType,
template <
int T,
typename>
class LoopBoundType,
typename Lambda>
inline void
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)
277template <
typename IndexType,
template <
int T,
typename>
class LoopBoundType,
typename Lambda>
inline void
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)
287template <
typename IndexType,
template <
int,
typename>
class LoopBoundType,
typename Lambda>
inline void
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)
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[.