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#define parallelForWithSchedulerInstructions(counter, max, loopParallelism) \
7 tbb::parallel_for( \
8 tbb::blocked_range<int>( \
9 0, max, loopParallelism==::peano4::utils::LoopPlacement::Serial ? max : 1 \
10 ), \
11 [&]( const tbb::blocked_range<int>& range ) { \
12 for( int counter = range.begin(); counter < range.end(); counter++ ) \
13
14
19#define endParallelFor \
20 } \
21 );
22
23
24#define parallelDforWithSchedulerInstructions2d(counter, max, loopParallelism) \
25{ \
26 tarch::la::Vector<2,int> counter##Max(max); \
27 int counter##Size[] = {counter##Max(0),counter##Max(1)}; \
28 tbb::parallel_for( \
29 tbb::blocked_rangeNd<int,2>( \
30 counter##Size, \
31 loopParallelism==::peano4::utils::LoopPlacement::Serial ? counter##Max(0) : 1 \
32 ), \
33 [&]( const tbb::blocked_rangeNd<int,2>& range ) { \
34 for( int counter##1 = range.dim(0).begin(); counter##1 < range.dim(0).end(); counter##1++ ) \
35 for( int counter##2 = range.dim(1).begin(); counter##2 < range.dim(1).end(); counter##2++ ) { \
36 tarch::la::Vector<2, int> counter = { counter##1, counter##2 };
37
38
39#define parallelDforWithSchedulerInstructions3d(counter, max, loopParallelism) \
40 { \
41 tarch::la::Vector<3,int> counter##Max(max); \
42 int counter##Size[] = {counter##Max(0),counter##Max(1),counter##Max(2)}; \
43 tbb::parallel_for( \
44 tbb::blocked_rangeNd<int,3>( \
45 counter##Size,\
46 loopParallelism==::peano4::utils::LoopPlacement::Serial ? counter##Max(0) : 1 \
47 ), \
48 [&]( const tbb::blocked_rangeNd<int,3>& range ) { \
49 for( int counter##1 = range.dim(0).begin(); counter##1 < range.dim(0).end(); counter##1++ ) \
50 for( int counter##2 = range.dim(1).begin(); counter##2 < range.dim(1).end(); counter##2++ ) \
51 for( int counter##3 = range.dim(2).begin(); counter##3 < range.dim(2).end(); counter##3++ ) {\
52 tarch::la::Vector<3, int> counter = { counter##1, counter##2, counter##3 };
53
54
55#define parallelDforWithSchedulerInstructions4d(counter, max, loopParallelism) \
56 { \
57 tarch::la::Vector<4,int> counter##Max(max); \
58 int counter##Size[] = {counter##Max(0),counter##Max(1),counter##Max(2),counter##Max(3)}; \
59 tbb::parallel_for( \
60 tbb::blocked_rangeNd<int,4>( \
61 counter##Size,\
62 loopParallelism==::peano4::utils::LoopPlacement::Serial ? counter##Max(0) : 1 \
63 ), \
64 [&]( const tbb::blocked_rangeNd<int,4>& range ) { \
65 for( int counter##1 = range.dim(0).begin(); counter##1 < range.dim(0).end(); counter##1++ ) \
66 for( int counter##2 = range.dim(1).begin(); counter##2 < range.dim(1).end(); counter##2++ ) \
67 for( int counter##3 = range.dim(2).begin(); counter##3 < range.dim(2).end(); counter##3++ ) \
68 for( int counter##4 = range.dim(3).begin(); counter##4 < range.dim(3).end(); counter##4++ ) { \
69 tarch::la::Vector<4, int> counter = { counter##1, counter##2, counter##3, counter##4 };
70
71
72#define parallelDforWithSchedulerInstructions5d(counter, max, loopParallelism) \
73 { \
74 tarch::la::Vector<5,int> counter##Max(max); \
75 int counter##Size[] = {counter##Max(0),counter##Max(1),counter##Max(2),counter##Max(3),counter##Max(4)}; \
76 tbb::parallel_for( \
77 tbb::blocked_rangeNd<int,5>( \
78 counter##Size,\
79 loopParallelism==::peano4::utils::LoopPlacement::Serial ? counter##Max(0) : 1 \
80 ), \
81 [&]( const tbb::blocked_rangeNd<int,5>& range ) { \
82 for( int counter##1 = range.dim(0).begin(); counter##1 < range.dim(0).end(); counter##1++ ) \
83 for( int counter##2 = range.dim(1).begin(); counter##2 < range.dim(1).end(); counter##2++ ) \
84 for( int counter##3 = range.dim(2).begin(); counter##3 < range.dim(2).end(); counter##3++ ) \
85 for( int counter##4 = range.dim(3).begin(); counter##4 < range.dim(3).end(); counter##4++ ) \
86 for( int counter##5 = range.dim(4).begin(); counter##5 < range.dim(4).end(); counter##5++ ) { \
87 tarch::la::Vector<5, int> counter = { counter##1, counter##2, counter##3, counter##4, counter##5 };
88
89
102#define endParallelDfor \
103 } \
104 } \
105 ); \
106 }
107
108
112#define simtForWithSchedulerInstructions(counter, max, loopParallelism) \
113 parallelForWithSchedulerInstructions(counter, max, (loopParallelism==::peano4::utils::LoopPlacement::Nested ? ::peano4::utils::LoopPlacement::Nested : ::peano4::utils::LoopPlacement::Serial))
114
115#define endSimtFor \
116 endParallelFor
117
118#define simtDforWithSchedulerInstructions2d(counter, max, loopParallelism) \
119 parallelDforWithSchedulerInstructions2d(counter, max, (loopParallelism==::peano4::utils::LoopPlacement::Nested ? ::peano4::utils::LoopPlacement::Nested : ::peano4::utils::LoopPlacement::Serial))
120
121#define simtDforWithSchedulerInstructions3d(counter, max, loopParallelism) \
122 parallelDforWithSchedulerInstructions3d(counter, max, (loopParallelism==::peano4::utils::LoopPlacement::Nested ? ::peano4::utils::LoopPlacement::Nested : ::peano4::utils::LoopPlacement::Serial))
123
124#define simtDforWithSchedulerInstructions4d(counter, max, loopParallelism) \
125 parallelDforWithSchedulerInstructions4d(counter, max, (loopParallelism==::peano4::utils::LoopPlacement::Nested ? ::peano4::utils::LoopPlacement::Nested : ::peano4::utils::LoopPlacement::Serial))
126
127#define simtDforWithSchedulerInstructions5d(counter, max, loopParallelism) \
128 parallelDforWithSchedulerInstructions5d(counter, max, (loopParallelism==::peano4::utils::LoopPlacement::Nested ? ::peano4::utils::LoopPlacement::Nested : ::peano4::utils::LoopPlacement::Serial))
129
130#define endSimtDfor \
131 endParallelDfor