Arcane  4.1.15.0
Developer documentation
Loading...
Searching...
No Matches
SequentialFor.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/* SequentialFor.h (C) 2000-2026 */
9/* */
10/* Handling of sequential for loops. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_COMMON_SEQUENTIALFOR_H
13#define ARCCORE_COMMON_SEQUENTIALFOR_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/common/HostKernelRemainingArgsHelper.h"
18#include "arccore/base/ForLoopRanges.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
30template <typename IndexType, template <int T, typename> class LoopBoundType,
31 typename Lambda, typename... RemainingArgs>
32void arccoreSequentialFor(LoopBoundType<1, IndexType> bounds, Lambda func,
33 RemainingArgs... remaining_args)
34{
36 for (IndexType i0 = bounds.template lowerBound<0>(); i0 < bounds.template upperBound<0>(); ++i0)
37 func(MDIndex<1, IndexType>(i0), remaining_args...);
39}
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
43
45template <typename IndexType, template <int T, typename> class LoopBoundType, typename Lambda> void
46arccoreSequentialFor(LoopBoundType<2, IndexType> bounds, Lambda func)
47{
48 for (IndexType i0 = bounds.template lowerBound<0>(); i0 < bounds.template upperBound<0>(); ++i0)
49 for (IndexType i1 = bounds.template lowerBound<1>(); i1 < bounds.template upperBound<1>(); ++i1)
50 func(MDIndex<2, IndexType>(i0, i1));
51}
52
53/*---------------------------------------------------------------------------*/
54/*---------------------------------------------------------------------------*/
55
57template <typename IndexType, template <int T, typename> class LoopBoundType, typename Lambda> void
58arccoreSequentialFor(LoopBoundType<3, IndexType> bounds, Lambda func)
59{
60 for (IndexType i0 = bounds.template lowerBound<0>(); i0 < bounds.template upperBound<0>(); ++i0)
61 for (IndexType i1 = bounds.template lowerBound<1>(); i1 < bounds.template upperBound<1>(); ++i1)
62 for (IndexType i2 = bounds.template lowerBound<2>(); i2 < bounds.template upperBound<2>(); ++i2)
63 func(MDIndex<3, IndexType>(i0, i1, i2));
64}
65
66/*---------------------------------------------------------------------------*/
67/*---------------------------------------------------------------------------*/
68
70template <typename IndexType, template <int, typename> class LoopBoundType, typename Lambda> void
71arccoreSequentialFor(LoopBoundType<4, IndexType> bounds, Lambda func)
72{
73 for (IndexType i0 = bounds.template lowerBound<0>(); i0 < bounds.template upperBound<0>(); ++i0)
74 for (IndexType i1 = bounds.template lowerBound<1>(); i1 < bounds.template upperBound<1>(); ++i1)
75 for (IndexType i2 = bounds.template lowerBound<2>(); i2 < bounds.template upperBound<2>(); ++i2)
76 for (IndexType i3 = bounds.template lowerBound<3>(); i3 < bounds.template upperBound<3>(); ++i3)
77 func(MDIndex<4, IndexType>(i0, i1, i2, i3));
78}
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
82
83} // End namespace Arcane
84
85/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
87
88#endif
static void applyAtEnd(RemainingArgs &... remaining_args)
Applies the functors of additional arguments at the end of the iteration.
static void applyAtBegin(RemainingArgs &... remaining_args)
Applies the functors of additional arguments at the beginning of the iteration.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
void arccoreSequentialFor(LoopBoundType< 1, IndexType > bounds, Lambda func, RemainingArgs... remaining_args)
Applies the functor func over a 1D loop.