Peano
Loading...
Searching...
No Matches
Loop.h
Go to the documentation of this file.
1// This file is part of the Peano project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3//
4// Included by peano4/utils/Loop.h. Do not use directly
5//
6
7// holds for_each
8#include <algorithm>
9
10// holds execution policies
11#include <execution>
12
13// holds cartesian product
14#include <ranges>
15
16// holds iota
17#include <numeric>
18
19
20//using std::iota;
21//using std::ranges::cartesian_product;
22using std::ranges::views::iota;
24
25
26namespace {
30/*
31 inline constexpr auto translateIntoCPPExecutionPolicyForParallelLoop( peano4::utils::LoopPlacement placement ) {
32 return placement==peano4::utils::LoopPlacement::Serial ? std::execution::seq : std::execution::par;
33 }
34*/
35 #define translateIntoCPPExecutionPolicyForParallelLoop( placement ) \
36 placement==peano4::utils::LoopPlacement::Serial ? std::execution::seq : std::execution::par
37
38 #define translateIntoCPPExecutionPolicyForSimtLoop( placement ) \
39 std::execution::seq;
40/*
41 inline constexpr auto translateIntoCPPExecutionPolicyForSimtLoop( peano4::utils::LoopPlacement placement ) {
42 if (placement==peano4::utils::LoopPlacement::Serial)
43 return std::execution::seq;
44 else if (placement==peano4::utils::LoopPlacement::Nested)
45 return std::execution::unseq;
46 else
47 return std::execution::par_unseq;
48 }
49*/
50}
51
52
53#define parallelForWithSchedulerInstructions(counter, max, loopParallelism) \
54 { \
55 auto counter##Range = iota(0, max); \
56 std::for_each( std::execution::par_unseq, counter##Range, [&]( const int counter ) {
57
58
63#define endParallelFor \
64 })); \
65 }
66
67
68#define parallelDforWithSchedulerInstructions2d(counter, max, loopParallelism) \
69 { \
70 tarch::la::Vector<2, int> counter##Max(max); \
71 auto counter##Range0 = iota(0, counter##Max(0)); \
72 auto counter##Range1 = iota(0, counter##Max(1)); \
73 std::for_each( std::execution::par, cartesian_product( counter##Range0, counter##Range1 ), [&]( auto counter##Native ) { \
74 tarch::la::Vector<2, int> counter = { counter##Native[0], counter##Native[1] };
75
76
77#define parallelDforWithSchedulerInstructions3d(counter, max, loopParallelism) \
78 { \
79 tarch::la::Vector<3, int> counter##Max(max); \
80 auto counter##Range0 = iota(0, counter##Max(0)); \
81 auto counter##Range1 = iota(0, counter##Max(1)); \
82 auto counter##Range2 = iota(0, counter##Max(2)); \
83 std::for_each( std::execution::par, cartesian_product( counter##Range0, counter##Range1, counter##Range2 ), [&]( auto counter##Native ) { \
84 tarch::la::Vector<3, int> counter = { counter##Native[0], counter##Native[1], counter##Native[2] };
85
86
87#define parallelDforWithSchedulerInstructions4d(counter, max, loopParallelism) \
88 { \
89 tarch::la::Vector<4, int> counter##Max(max); \
90 auto counter##Range0 = iota(0, counter##Max(0)); \
91 auto counter##Range1 = iota(0, counter##Max(1)); \
92 auto counter##Range2 = iota(0, counter##Max(2)); \
93 auto counter##Range3 = iota(0, counter##Max(3)); \
94 std::for_each( std::execution::par, cartesian_product( counter##Range0, counter##Range1, counter##Range2, counter##Range3 ), [&]( auto counter##Native ) { \
95 tarch::la::Vector<4, int> counter = { counter##Native[0], counter##Native[1], counter##Native[2], counter##Native[3] };
96
97
98#define parallelDforWithSchedulerInstructions5d(counter, max, loopParallelism) \
99 { \
100 tarch::la::Vector<5, int> counter##Max(max); \
101 auto counter##Range0 = iota(0, counter##Max(0)); \
102 auto counter##Range1 = iota(0, counter##Max(1)); \
103 auto counter##Range2 = iota(0, counter##Max(2)); \
104 auto counter##Range3 = iota(0, counter##Max(3)); \
105 auto counter##Range4 = iota(0, counter##Max(4)); \
106 std::for_each( std::execution::par, cartesian_product( counter##Range0, counter##Range1, counter##Range2, counter##Range3, counter##Range4 ), [&]( auto counter##Native ) { \
107 tarch::la::Vector<5, int> counter = { counter##Native[0], counter##Native[1], counter##Native[2], counter##Native[3], counter##Native[4] };
108
109
115#define endParallelDfor \
116 }); \
117 }
118
119
120#define simtForWithSchedulerInstructions(counter, max, loopParallelism) \
121 { \
122 std::for_each( std::execution::par_unseq, iota(0, max), [&]( const int counter ) {
123
124
129#define endSimtFor \
130 }); \
131 }
132
133
134#define simtDforWithSchedulerInstructions2d(counter, max, loopParallelism) \
135 { \
136 tarch::la::Vector<2, int> counter##Max(max); \
137 auto counter##Range0 = iota(0, counter##Max(0)); \
138 auto counter##Range1 = iota(0, counter##Max(1)); \
139 std::for_each( std::execution::par_unseq, cartesian_product( counter##Range0, counter##Range1 ), [&]( auto counter##Native ) { \
140 tarch::la::Vector<2, int> counter = { counter##Native[0], counter##Native[1] };
141
142
143#define simtDforWithSchedulerInstructions3d(counter, max, loopParallelism) \
144 { \
145 tarch::la::Vector<3, int> counter##Max(max); \
146 auto counter##Range0 = iota(0, counter##Max(0)); \
147 auto counter##Range1 = iota(0, counter##Max(1)); \
148 auto counter##Range2 = iota(0, counter##Max(2)); \
149 std::for_each( std::execution::par_unseq, cartesian_product( counter##Range0, counter##Range1, counter##Range2 ), [&]( auto counter##Native ) { \
150 tarch::la::Vector<3, int> counter = { counter##Native[0], counter##Native[1], counter##Native[2] };
151
152
153#define simtDforWithSchedulerInstructions4d(counter, max, loopParallelism) \
154 { \
155 tarch::la::Vector<4, int> counter##Max(max); \
156 auto counter##Range0 = iota(0, counter##Max(0)); \
157 auto counter##Range1 = iota(0, counter##Max(1)); \
158 auto counter##Range2 = iota(0, counter##Max(2)); \
159 auto counter##Range3 = iota(0, counter##Max(3)); \
160 std::for_each( std::execution::par_unseq, cartesian_product( counter##Range0, counter##Range1, counter##Range2, counter##Range3 ), [&]( auto counter##Native ) { \
161 tarch::la::Vector<4, int> counter = { counter##Native[0], counter##Native[1], counter##Native[2], counter##Native[3] };
162
163
164#define simtDforWithSchedulerInstructions5d(counter, max, loopParallelism) \
165 { \
166 tarch::la::Vector<5, int> counter##Max(max); \
167 auto counter##Range0 = iota(0, counter##Max(0)); \
168 auto counter##Range1 = iota(0, counter##Max(1)); \
169 auto counter##Range2 = iota(0, counter##Max(2)); \
170 auto counter##Range3 = iota(0, counter##Max(3)); \
171 auto counter##Range4 = iota(0, counter##Max(4)); \
172 std::for_each( std::execution::par_unseq, cartesian_product( counter##Range0, counter##Range1, counter##Range2, counter##Range3, counter##Range4 ), [&]( auto counter##Native ) { \
173 tarch::la::Vector<5, int> counter = { counter##Native[0], counter##Native[1], counter##Native[2], counter##Native[3], counter##Native[4] };
174
175
181#define endSimtDfor \
182 }); \
183 }
constexpr tl::views::detail::cartesian_product_fn cartesian_product