7 int result = counter(Dimensions - 1);
8 #if !defined(SharedSYCL)
9 assertion2(counter(Dimensions - 1) >= 0, counter, max);
10 assertion2(counter(Dimensions - 1) < max, counter, max);
12 for (
int d = Dimensions - 2;
d >= 0;
d--) {
13 #if !defined(SharedSYCL)
17 result = result *
max + counter(d);
27 for (
int d=Dimensions-1;
d>=0;
d--) {
35 #ifdef DloopOptimiseAggressive
39 const int MaxIndexOfLinearization = FIVE_POWER_D;
40 int LookupTableDLinearised[MaxIndexOfLinearization*(MaxMax-1)];
47 for (
int d=0;
d<Dimensions;
d++) {
48 result += key * counter(d);
54 result += (
max-2)*MaxIndexOfLinearization;
60 int getKeyForDDeLinearised(
int value,
int max) {
62 return value + (
max-2)*MaxIndexOfLinearization;
69 #ifdef DloopOptimiseAggressive
70 for (
int i=2; i<=MaxMax; i++) {
72 LookupTableDLinearised[getKeyForDLinearised(k,i)] = dLinearisedNotOptimised(k,i);
80 #ifdef DloopOptimiseAggressive
81 for (
int value=0; value<MaxIndexOfLinearization; value++) {
82 for (
int i=2; i<=MaxMax; i++) {
83 LookupTableDDeLinearised[getKeyForDDeLinearised(value,i)] = dDelinearisedNotOptimised(value,i);
91 return dLinearisedNotOptimised(counter,max);
98 for (
int d=0; d<Dimensions; d++) {
99 result += (counter[d] ? 1 : 0) * base;
107 #ifdef DloopOptimiseAggressive
108 assertionEquals3(LookupTableDLinearised[getKeyForDLinearised(counter,max)], dLinearisedNotOptimised(counter,max), counter,max,getKeyForDLinearised(counter,max));
109 return LookupTableDLinearised[getKeyForDLinearised(counter,max)];
111 return dLinearisedNotOptimised(counter,max);
117 int result = counter(2 - 1);
118 assertion2(counter(2 - 1) >= 0, counter, max);
119 assertion2(counter(2 - 1) < max, counter, max);
120 for (
int d = 2 - 2; d >= 0; d--) {
122 assertion3(counter(d) < max, counter, d, max);
123 result = result * max + counter(d);
130 int result = counter(3 - 1);
131 assertion2(counter(3 - 1) >= 0, counter, max);
132 assertion2(counter(3 - 1) < max, counter, max);
133 for (
int d = 3 - 2; d >= 0; d--) {
135 assertion2(counter(d) < max, counter(d), max);
136 result = result * max + counter(d);
143 return dDelinearisedNotOptimised(value, max);
147 #ifdef DloopOptimiseAggressive
148 for (
int d=0; d<Dimensions; d++) {
149 assertionEquals2(LookupTableDDeLinearised[getKeyForDDeLinearised(value,max)](d), dDelinearisedNotOptimised(value,max)(d),value,max);
151 return LookupTableDDeLinearised[getKeyForDDeLinearised(value,max)];
153 return dDelinearisedNotOptimised(value,max);
160 for (
int i=0; i<Dimensions-1; i++) {
161 if ( counter(i) >= max ) {
170 for (
int i = 0; i < Dimensions - 1; i++) {
175 for (
int i=0; i<Dimensions-1; i++) {
176 if ( counter(i) < 0 ) {
186 for (
int i=0; i<Dimensions-1; i++) {
187 if ( counter(i) >= max(i) ) {
197 counter(0) += increment;
198 for (
int i=0; i<Dimensions-1; i++) {
199 if ( counter(i) >= max ) {
201 counter(i+1) += increment;
210 counter(0) += increment;
211 for (
int i=0; i<Dimensions-1; i++) {
212 while ( counter(i) >= max ) {
224 if (doNotExamine!=0) {
230 for (
int i=0; i<Dimensions-1; i++) {
231 if ( counter(i) >= max ) {
233 if ( doNotExamine != i+1) {
237 if ( doNotExamine != Dimensions-1 ) {
241 counter(Dimensions-1) = max;
250 for (
int i=0; i<Dimensions; i++) {
251 if ( direction[i] ) {
253 bool greater = counter(i) >= max;
254 if (greater && (i==Dimensions-1)) {
260 direction[i] = !direction[i];
266 bool smaller = counter(i) < 0;
267 if (smaller && (i==Dimensions-1)) {
273 direction[i] = !direction[i];
283 for (
int i=0; i<Dimensions; i++) {
284 assertion2( counter(i)<=max(i), counter,max );
286 result &= (counter(i)<max(i));
294 for (
int i=0; i<Dimensions; i++) {
295 #if !defined(SharedSYCL)
299 result &= (counter(i)<max);
306 for (
int i = Dimensions - 1; i >= 0; i--) {
307 if (counter(i) > max(i)) {
309 }
else if (counter(i) < max(i)) {
327 result( dim ) = value;
334 assertion2( max>0 && max<=3, max, direction );
335 for (
int i=0; i<Dimensions; i++) {
#define assertion2(expr, param0, param1)
#define assertionEquals3(lhs, rhs, a, b, c)
#define assertion3(expr, param0, param1, param2)
#define assertionEquals(lhs, rhs)
#define assertionEquals2(lhs, rhs, a, b)
std::string toString(peano4::utils::LoopPlacement arg)
#define dfor(counter, max)
d-dimensional Loop
int d2Linearised(const tarch::la::Vector< 2, int > &counter, int max)
Special 2d variant of dLinearised that works also if you compile with other dimensions.
bool dCmpLinearOrder(const tarch::la::Vector< Dimensions, int > &counter, const tarch::la::Vector< Dimensions, int > &max)
Compares two vectors with regards to their linearised value.
CPUGPUMethod void dInc(tarch::la::Vector< Dimensions, int > &counter, int max)
d-dimensional counterpart of increment operator
std::bitset< Dimensions > LoopDirection
Is used by the z-loop.
LoopPlacement
Guide loop-level parallelism.
CPUGPUMethod tarch::la::Vector< Dimensions, int > dStartVector()
Construct start vector (0,0,....) for d-dimensional loop.
void dIncByScalar(tarch::la::Vector< Dimensions, int > &counter, int max, int increment)
Perform a scalar increment of a vector: The operation equals a sequence of increment calls to dInc().
void dIncByVector(tarch::la::Vector< Dimensions, int > &counter, int max, int increment)
Perform a d-dimensional increment by value increment: The first component of the counter is increment...
void setupLookupTableForDLinearised()
CPUGPUMethod int dLinearised(const tarch::la::Vector< Dimensions, int > &counter, int max)
Map d-dimensional vector onto integer index.
tarch::la::Vector< Dimensions, int > dDelinearised(int value, int max)
Counterpart of dLinearised().
int dLinearisedWithoutLookup(const tarch::la::Vector< Dimensions, int > &counter, int max)
Linearisation not Optimised.
void dDec(tarch::la::Vector< Dimensions, int > &counter, int max)
d-dimensional counterpart of decrement operator
CPUGPUMethod int dCmp(const tarch::la::Vector< Dimensions, int > &counter, int max)
Element-wise comparison for the for d-dimensional for loops.
int d3Linearised(const tarch::la::Vector< 3, int > &counter, int max)
Special 3d variant of dLinearised that works also if you compile with other dimensions.
void setupLookupTableForDDelinearised()
tarch::la::Vector< Dimensions, int > dDelinearisedWithoutLookup(int value, int max)
Delinearization not optimised.
double max(double a, double b, double c)
I need the maximum of three values all the time, to I decided to write a function for this.
int aPowI(int i, int a)
Computes the i-th power of a in integer arithmetic.