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#pragma once
4
5#include <bitset>
6
7#include "config.h"
11#include "tarch/la/Vector.h"
12
13
14#if defined(SharedTBB)
15 #if defined(SharedTBBExtension) and !defined(TBB_PREVIEW_BLOCKED_RANGE_ND)
16 #include "tbb/blocked_rangeNd.h"
17 #else
18 #include <oneapi/tbb/blocked_range.h>
19 #endif
20
21 #include <oneapi/tbb/blocked_range2d.h>
22 #include <oneapi/tbb/blocked_range3d.h>
23 #include <oneapi/tbb/parallel_for.h>
24#endif
25
26
27#if defined(SharedSYCL)
29
33#define CPUGPUMethod SYCL_EXTERNAL
34#else
35#define CPUGPUMethod
36#endif
37
38namespace peano4 {
39 namespace utils {
66
70 typedef std::bitset<Dimensions> LoopDirection;
71
83
92 void dDec(tarch::la::Vector<Dimensions, int>& counter, int max);
93
103
110 void dIncByVector(tarch::la::Vector<Dimensions, int>& counter, int max, int increment);
111
116 void dIncByScalar(tarch::la::Vector<Dimensions, int>& counter, int max, int increment);
117
122 void dInc(tarch::la::Vector<Dimensions, int>& counter, int max, int doNotExamine);
123
129 void dInc(tarch::la::Vector<Dimensions, int>& counter, int max, LoopDirection& direction);
130
140 CPUGPUMethod int dCmp(const tarch::la::Vector<Dimensions, int>& counter, int max);
141
153
159 bool dCmpLinearOrder(
161 );
162
207 CPUGPUMethod int dLinearised(const std::bitset<Dimensions>& counter);
208
213 int d2Linearised(const tarch::la::Vector<2, int>& counter, int max);
214
219 int d3Linearised(const tarch::la::Vector<3, int>& counter, int max);
220
229
238
243
244
247
256
262
270 }
271}
272
273
275
276
313#define dfor(counter, max) \
314 for (tarch::la::Vector<Dimensions, int> counter = peano4::utils::dStartVector(); peano4::utils::dCmp(counter, max); \
315 peano4::utils::dInc(counter, max))
316
317
446#define parallelFor(counter, max) \
447 parallelForWithSchedulerInstructions(counter, max, ::peano4::utils::LoopPlacement::SpreadOut)
448
449#define simtFor(counter, max) \
450 simtForWithSchedulerInstructions(counter, max, ::peano4::utils::LoopPlacement::SpreadOut)
451
452#define parallelDfor(counter, max) \
453 parallelDforWithSchedulerInstructions(counter, max, ::peano4::utils::LoopPlacement::SpreadOut)
454
455#if Dimensions == 2
456#define parallelDforWithSchedulerInstructions(counter, max, loopPlacement) \
457 parallelDforWithSchedulerInstructions2d(counter, max, loopPlacement)
458
459#define parallelDPlusOneForWithSchedulerInstructions(counter, max, loopPlacement) \
460 parallelDforWithSchedulerInstructions3d(counter, max, loopPlacement)
461
462#define parallelDPlusTwoForWithSchedulerInstructions(counter, max, loopPlacement) \
463 parallelDforWithSchedulerInstructions4d(counter, max, loopPlacement)
464
465#define simtDforWithSchedulerInstructions(counter, max, loopPlacement) \
466 simtDforWithSchedulerInstructions2d(counter, max, loopPlacement)
467
468#define simtDPlusOneForWithSchedulerInstructions(counter, max, loopPlacement) \
469 simtDforWithSchedulerInstructions3d(counter, max, loopPlacement)
470
471#define simtDPlusTwoForWithSchedulerInstructions(counter, max, loopPlacement) \
472 simtDforWithSchedulerInstructions4d(counter, max, loopPlacement)
473#elif Dimensions == 3
474#define parallelDforWithSchedulerInstructions(counter, max, loopPlacement) \
475 parallelDforWithSchedulerInstructions3d(counter, max, loopPlacement)
476
477#define parallelDPlusOneForWithSchedulerInstructions(counter, max, loopPlacement) \
478 parallelDforWithSchedulerInstructions4d(counter, max, loopPlacement)
479
480#define parallelDPlusTwoForWithSchedulerInstructions(counter, max, loopPlacement) \
481 parallelDforWithSchedulerInstructions5d(counter, max, loopPlacement)
482
483#define simtDforWithSchedulerInstructions(counter, max, loopPlacement) \
484 simtDforWithSchedulerInstructions3d(counter, max, loopPlacement)
485
486#define simtDPlusOneForWithSchedulerInstructions(counter, max, loopPlacement) \
487 simtDforWithSchedulerInstructions4d(counter, max, loopPlacement)
488
489#define simtDPlusTwoForWithSchedulerInstructions(counter, max, loopPlacement) \
490 simtDforWithSchedulerInstructions5d(counter, max, loopPlacement)
491#endif
492
493
494#if defined(SharedOMP) and defined(OpenMPTaskGroup)
495#include "omp/Loop.h"
496#elif defined(SharedOMP) and !defined(OpenMPTaskGroup)
498#elif defined(SharedTBB)
499#include "tbb/Loop.h"
500#elif defined(SharedCPP)
501//and __cplusplus >= 202101L
502#include "cpp/Loop.h"
503#elif defined(SharedSYCL)
504#include "sycl/Loop.h"
505#else
506#define parallelForWithSchedulerInstructions(counter, max, loopPlacement) \
507 for (int counter = 0; counter < max; counter++) {
508
509#define parallelDforWithSchedulerInstructions2d(counter, max, loopPlacement) \
510 { \
511 tarch::la::Vector<2, int> counter##Max(max); \
512 for (int counter##0 = 0; counter##0 < counter##Max(0); counter##0 ++) \
513 for (int counter##1 = 0; counter##1 < counter##Max(1); counter##1 ++) { \
514 tarch::la::Vector<2, int> counter = {counter##0, counter##1};
515
516#define parallelDforWithSchedulerInstructions3d(counter, max, loopPlacement) \
517 { \
518 tarch::la::Vector<3, int> counter##Max(max); \
519 for (int counter##0 = 0; counter##0 < counter##Max(0); counter##0 ++) \
520 for (int counter##1 = 0; counter##1 < counter##Max(1); counter##1 ++) \
521 for (int counter##2 = 0; counter##2 < counter##Max(2); counter##2 ++) { \
522 tarch::la::Vector<3, int> counter = {counter##0, counter##1, counter##2};
523
524#define parallelDforWithSchedulerInstructions4d(counter, max, loopPlacement) \
525 { \
526 tarch::la::Vector<4, int> counter##Max(max); \
527 for (int counter##0 = 0; counter##0 < counter##Max(0); counter##0 ++) \
528 for (int counter##1 = 0; counter##1 < counter##Max(1); counter##1 ++) \
529 for (int counter##2 = 0; counter##2 < counter##Max(2); counter##2 ++) \
530 for (int counter##3 = 0; counter##3 < counter##Max(3); counter##3 ++) { \
531 tarch::la::Vector<4, int> counter = {counter##0, counter##1, counter##2, counter##3};
532
533#define parallelDforWithSchedulerInstructions5d(counter, max, loopPlacement) \
534 { \
535 tarch::la::Vector<5, int> counter##Max(max); \
536 for (int counter##0 = 0; counter##0 < counter##Max(0); counter##0 ++) \
537 for (int counter##1 = 0; counter##1 < counter##Max(1); counter##1 ++) \
538 for (int counter##2 = 0; counter##2 < counter##Max(2); counter##2 ++) \
539 for (int counter##3 = 0; counter##3 < counter##Max(3); counter##3 ++) \
540 for (int counter##4 = 0; counter##4 < counter##Max(4); counter##4 ++) { \
541 tarch::la::Vector<5, int> counter = {counter##0, counter##1, counter##2, counter##3, counter##4};
542
543#define endParallelFor }
544#define endParallelDfor \
545 } \
546 }
547
548
549#define simtForWithSchedulerInstructions(counter, max, loopPlacement) \
550 for (int counter = 0; counter < max; counter++) {
551
552#define endSimtFor endParallelFor
553
554#define simtDforWithSchedulerInstructions2d(counter, max, loopPlacement) \
555 parallelDforWithSchedulerInstructions2d(counter, max, loopPlacement)
556
557#define simtDforWithSchedulerInstructions3d(counter, max, loopPlacement) \
558 parallelDforWithSchedulerInstructions3d(counter, max, loopPlacement)
559
560#define simtDforWithSchedulerInstructions4d(counter, max, loopPlacement) \
561 parallelDforWithSchedulerInstructions4d(counter, max, loopPlacement)
562
563#define simtDforWithSchedulerInstructions5d(counter, max, loopPlacement) \
564 parallelDforWithSchedulerInstructions5d(counter, max, loopPlacement)
565
566#define endSimtDfor endParallelDfor
567
568#endif
569
570
601#define dfor4(counter) \
602 for (int counter##Scalar = 0; counter##Scalar < FOUR_POWER_D; counter##Scalar++) { \
603 tarch::la::Vector<Dimensions, int> counter; \
604 { \
605 int copy##counter##Scalar = counter##Scalar; \
606 for (int counter##ddd = Dimensions - 1; counter##ddd >= 0; counter##ddd--) { \
607 int counter##aPowI = 1; \
608 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
609 counter##aPowI *= 4; \
610 } \
611 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
612 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
613 } \
614 }
615
616
647#define dfor3(counter) \
648 for (int counter##Scalar = 0; counter##Scalar < ThreePowerD; counter##Scalar++) { \
649 tarch::la::Vector<Dimensions, int> counter; \
650 { \
651 int copy##counter##Scalar = counter##Scalar; \
652 for (int counter##ddd = Dimensions - 1; counter##ddd >= 0; counter##ddd--) { \
653 int counter##aPowI = 1; \
654 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
655 counter##aPowI *= 3; \
656 } \
657 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
658 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
659 } \
660 }
661
662
663#define dfor5(counter) \
664 for (int counter##Scalar = 0; counter##Scalar < FIVE_POWER_D; counter##Scalar++) { \
665 tarch::la::Vector<Dimensions, int> counter; \
666 { \
667 int copy##counter##Scalar = counter##Scalar; \
668 for (int counter##ddd = Dimensions - 1; counter##ddd >= 0; counter##ddd--) { \
669 int counter##aPowI = 1; \
670 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
671 counter##aPowI *= 5; \
672 } \
673 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
674 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
675 } \
676 }
677
678#define dfor7(counter) \
679 for (int counter##Scalar = 0; counter##Scalar < SEVEN_POWER_D; counter##Scalar++) { \
680 tarch::la::Vector<Dimensions, int> counter; \
681 { \
682 int copy##counter##Scalar = counter##Scalar; \
683 for (int counter##ddd = Dimensions - 1; counter##ddd >= 0; counter##ddd--) { \
684 int counter##aPowI = 1; \
685 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
686 counter##aPowI *= 7; \
687 } \
688 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
689 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
690 } \
691 }
692
693
694#define dfor9(counter) \
695 for (int counter##Scalar = 0; counter##Scalar < NINE_POWER_D; counter##Scalar++) { \
696 tarch::la::Vector<Dimensions, int> counter; \
697 { \
698 int copy##counter##Scalar = counter##Scalar; \
699 for (int counter##ddd = Dimensions - 1; counter##ddd >= 0; counter##ddd--) { \
700 int counter##aPowI = 1; \
701 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
702 counter##aPowI *= 9; \
703 } \
704 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
705 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
706 } \
707 }
708
723#define d2for(counter, max) \
724 for (int counter##Scalar = 0; counter##Scalar < tarch::la::aPowI(2, max); counter##Scalar++) { \
725 tarch::la::Vector<2, int> counter; \
726 { \
727 int copy##counter##Scalar = counter##Scalar; \
728 for (int counter##ddd = 2 - 1; counter##ddd >= 0; counter##ddd--) { \
729 int counter##aPowI = 1; \
730 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
731 counter##aPowI *= max; \
732 } \
733 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
734 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
735 } \
736 }
737
744#define d2for2(counter) \
745 for (int counter##Scalar = 0; counter##Scalar < tarch::la::aPowI(2, 2); counter##Scalar++) { \
746 tarch::la::Vector<2, int> counter; \
747 { \
748 int copy##counter##Scalar = counter##Scalar; \
749 for (int counter##ddd = 2 - 1; counter##ddd >= 0; counter##ddd--) { \
750 int counter##aPowI = 1; \
751 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
752 counter##aPowI *= 2; \
753 } \
754 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
755 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
756 } \
757 }
758
765#define d3for2(counter) \
766 for (int counter##Scalar = 0; counter##Scalar < tarch::la::aPowI(3, 2); counter##Scalar++) { \
767 tarch::la::Vector<3, int> counter; \
768 { \
769 int copy##counter##Scalar = counter##Scalar; \
770 for (int counter##ddd = 3 - 1; counter##ddd >= 0; counter##ddd--) { \
771 int counter##aPowI = 1; \
772 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
773 counter##aPowI *= 2; \
774 } \
775 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
776 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
777 } \
778 }
779
780
795#define d3for(counter, max) \
796 for (int counter##Scalar = 0; counter##Scalar < tarch::la::aPowI(3, max); counter##Scalar++) { \
797 tarch::la::Vector<3, int> counter; \
798 { \
799 int copy##counter##Scalar = counter##Scalar; \
800 for (int counter##ddd = 3 - 1; counter##ddd >= 0; counter##ddd--) { \
801 int counter##aPowI = 1; \
802 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
803 counter##aPowI *= max; \
804 } \
805 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
806 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
807 } \
808 }
809
810
817#define d2for3(counter) \
818 for (int counter##Scalar = 0; counter##Scalar < tarch::la::aPowI(2, 3); counter##Scalar++) { \
819 tarch::la::Vector<2, int> counter; \
820 { \
821 int copy##counter##Scalar = counter##Scalar; \
822 for (int counter##ddd = 2 - 1; counter##ddd >= 0; counter##ddd--) { \
823 int counter##aPowI = 1; \
824 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
825 counter##aPowI *= 3; \
826 } \
827 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
828 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
829 } \
830 }
831
838#define d3for3(counter) \
839 for (int counter##Scalar = 0; counter##Scalar < tarch::la::aPowI(3, 3); counter##Scalar++) { \
840 tarch::la::Vector<3, int> counter; \
841 { \
842 int copy##counter##Scalar = counter##Scalar; \
843 for (int counter##ddd = 3 - 1; counter##ddd >= 0; counter##ddd--) { \
844 int counter##aPowI = 1; \
845 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
846 counter##aPowI *= 3; \
847 } \
848 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
849 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
850 } \
851 }
852
853
885/*
886 * bit flipping used for Dimensions = 2, and Dimensions = 3
887 * for more information about the idea principle used refer to https://opt-patterns.wiki.tum.de/dfor
888 */
889#if Dimensions == 2
890#define dfor2(counter) \
891 for (int counter##Scalar = 0, AA##counter = 0, BB##counter = 0; counter##Scalar < TwoPowerD; counter##Scalar++) { \
892 tarch::la::Vector<Dimensions, int> counter; \
893 counter(0) = AA##counter; \
894 counter(1) = BB##counter; \
895 AA##counter = !AA##counter; \
896 BB##counter = !(AA##counter ^ BB##counter);
897
898#elif Dimensions == 3
899#define dfor2(counter) \
900 for (int counter##Scalar = 0, AA##counter = 0, BB##counter = 0, CC##counter = 0; counter##Scalar < TwoPowerD; \
901 counter##Scalar++) { \
902 tarch::la::Vector<Dimensions, int> counter; \
903 counter(0) = AA##counter; \
904 counter(1) = BB##counter; \
905 counter(2) = CC##counter; \
906 AA##counter = !AA##counter; \
907 BB##counter = !(AA##counter ^ BB##counter); \
908 CC##counter = CC##counter || (!AA##counter && !BB##counter && !CC##counter);
909
910#else
911#define dfor2(counter) \
912 for (int counter##Scalar = 0; counter##Scalar < TwoPowerD; counter##Scalar++) { \
913 tarch::la::Vector<Dimensions, int> counter; \
914 { \
915 int copy##counter##Scalar = counter##Scalar; \
916 for (int counter##ddd = Dimensions - 1; counter##ddd >= 0; counter##ddd--) { \
917 int counter##aPowI = 1; \
918 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
919 counter##aPowI *= 2; \
920 } \
921 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
922 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
923 } \
924 }
925
926#endif
927
928
933#define enddforx }
934
935
942#define dfore(counter, max, dim, value) \
943 for (tarch::la::Vector<Dimensions, int> counter = peano4::utils::dStartVector(dim, value); \
944 peano4::utils::dCmp(counter, max); \
945 peano4::utils::dInc(counter, max, dim))
946
947
979#define zfor(counter, max, direction) \
980 { \
981 for (tarch::la::Vector<Dimensions, int> counter = peano4::utils::dStartVector(max, direction); \
982 peano4::utils::dCmp(counter, max); \
983 peano4::utils::dInc(counter, max, direction)) {
984
985
986/*
987 * zfor3 is an optimized version of zfor for max = 3
988 * A lookup table is used for dim=2 and dim=3, for higher dimensions
989 * the standard zfor is used instead
990 */
991#if Dimensions == 2
992// first entry is direction, second entry is cell, third entry is tuples
993static const int lookupzfor3[4][9][2] = {
994 {{2, 2}, {1, 2}, {0, 2}, {0, 1}, {1, 1}, {2, 1}, {2, 0}, {1, 0}, {0, 0}},
995 {{0, 2}, {1, 2}, {2, 2}, {2, 1}, {1, 1}, {0, 1}, {0, 0}, {1, 0}, {2, 0}},
996 {{2, 0}, {1, 0}, {0, 0}, {0, 1}, {1, 1}, {2, 1}, {2, 2}, {1, 2}, {0, 2}},
997 {{0, 0}, {1, 0}, {2, 0}, {2, 1}, {1, 1}, {0, 1}, {0, 2}, {1, 2}, {2, 2}}};
998
999#define zfor3(counter, direction) \
1000 { \
1001 tarch::la::Vector<Dimensions, int> counter; \
1002 int counter##initDir = static_cast<int>(direction.to_ulong()); \
1003 for (int counter##i = 0; counter##i < 9; ++counter##i) { \
1004 counter(0) = lookupzfor3[counter##initDir][counter##i][0]; \
1005 counter(1) = lookupzfor3[counter##initDir][counter##i][1];
1006
1007#elif Dimensions == 3
1008static const int lookupzfor3[8][27][3] = {
1009 {{2, 2, 2}, {1, 2, 2}, {0, 2, 2}, {0, 1, 2}, {1, 1, 2}, {2, 1, 2}, {2, 0, 2}, {1, 0, 2}, {0, 0, 2},
1010 {0, 0, 1}, {1, 0, 1}, {2, 0, 1}, {2, 1, 1}, {1, 1, 1}, {0, 1, 1}, {0, 2, 1}, {1, 2, 1}, {2, 2, 1},
1011 {2, 2, 0}, {1, 2, 0}, {0, 2, 0}, {0, 1, 0}, {1, 1, 0}, {2, 1, 0}, {2, 0, 0}, {1, 0, 0}, {0, 0, 0}},
1012 {{0, 2, 2}, {1, 2, 2}, {2, 2, 2}, {2, 1, 2}, {1, 1, 2}, {0, 1, 2}, {0, 0, 2}, {1, 0, 2}, {2, 0, 2},
1013 {2, 0, 1}, {1, 0, 1}, {0, 0, 1}, {0, 1, 1}, {1, 1, 1}, {2, 1, 1}, {2, 2, 1}, {1, 2, 1}, {0, 2, 1},
1014 {0, 2, 0}, {1, 2, 0}, {2, 2, 0}, {2, 1, 0}, {1, 1, 0}, {0, 1, 0}, {0, 0, 0}, {1, 0, 0}, {2, 0, 0}},
1015 {{2, 0, 2}, {1, 0, 2}, {0, 0, 2}, {0, 1, 2}, {1, 1, 2}, {2, 1, 2}, {2, 2, 2}, {1, 2, 2}, {0, 2, 2},
1016 {0, 2, 1}, {1, 2, 1}, {2, 2, 1}, {2, 1, 1}, {1, 1, 1}, {0, 1, 1}, {0, 0, 1}, {1, 0, 1}, {2, 0, 1},
1017 {2, 0, 0}, {1, 0, 0}, {0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {2, 1, 0}, {2, 2, 0}, {1, 2, 0}, {0, 2, 0}},
1018 {{0, 0, 2}, {1, 0, 2}, {2, 0, 2}, {2, 1, 2}, {1, 1, 2}, {0, 1, 2}, {0, 2, 2}, {1, 2, 2}, {2, 2, 2},
1019 {2, 2, 1}, {1, 2, 1}, {0, 2, 1}, {0, 1, 1}, {1, 1, 1}, {2, 1, 1}, {2, 0, 1}, {1, 0, 1}, {0, 0, 1},
1020 {0, 0, 0}, {1, 0, 0}, {2, 0, 0}, {2, 1, 0}, {1, 1, 0}, {0, 1, 0}, {0, 2, 0}, {1, 2, 0}, {2, 2, 0}},
1021 {{2, 2, 0}, {1, 2, 0}, {0, 2, 0}, {0, 1, 0}, {1, 1, 0}, {2, 1, 0}, {2, 0, 0}, {1, 0, 0}, {0, 0, 0},
1022 {0, 0, 1}, {1, 0, 1}, {2, 0, 1}, {2, 1, 1}, {1, 1, 1}, {0, 1, 1}, {0, 2, 1}, {1, 2, 1}, {2, 2, 1},
1023 {2, 2, 2}, {1, 2, 2}, {0, 2, 2}, {0, 1, 2}, {1, 1, 2}, {2, 1, 2}, {2, 0, 2}, {1, 0, 2}, {0, 0, 2}},
1024 {{0, 2, 0}, {1, 2, 0}, {2, 2, 0}, {2, 1, 0}, {1, 1, 0}, {0, 1, 0}, {0, 0, 0}, {1, 0, 0}, {2, 0, 0},
1025 {2, 0, 1}, {1, 0, 1}, {0, 0, 1}, {0, 1, 1}, {1, 1, 1}, {2, 1, 1}, {2, 2, 1}, {1, 2, 1}, {0, 2, 1},
1026 {0, 2, 2}, {1, 2, 2}, {2, 2, 2}, {2, 1, 2}, {1, 1, 2}, {0, 1, 2}, {0, 0, 2}, {1, 0, 2}, {2, 0, 2}},
1027 {{2, 0, 0}, {1, 0, 0}, {0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {2, 1, 0}, {2, 2, 0}, {1, 2, 0}, {0, 2, 0},
1028 {0, 2, 1}, {1, 2, 1}, {2, 2, 1}, {2, 1, 1}, {1, 1, 1}, {0, 1, 1}, {0, 0, 1}, {1, 0, 1}, {2, 0, 1},
1029 {2, 0, 2}, {1, 0, 2}, {0, 0, 2}, {0, 1, 2}, {1, 1, 2}, {2, 1, 2}, {2, 2, 2}, {1, 2, 2}, {0, 2, 2}},
1030 {{0, 0, 0}, {1, 0, 0}, {2, 0, 0}, {2, 1, 0}, {1, 1, 0}, {0, 1, 0}, {0, 2, 0}, {1, 2, 0}, {2, 2, 0},
1031 {2, 2, 1}, {1, 2, 1}, {0, 2, 1}, {0, 1, 1}, {1, 1, 1}, {2, 1, 1}, {2, 0, 1}, {1, 0, 1}, {0, 0, 1},
1032 {0, 0, 2}, {1, 0, 2}, {2, 0, 2}, {2, 1, 2}, {1, 1, 2}, {0, 1, 2}, {0, 2, 2}, {1, 2, 2}, {2, 2, 2}}};
1033
1034#define zfor3(counter, direction) \
1035 { \
1036 tarch::la::Vector<Dimensions, int> counter; \
1037 int counter##initDir = static_cast<int>(direction.to_ulong()); \
1038 for (int counter##i = 0; counter##i < 27; ++counter##i) { \
1039 counter(0) = lookupzfor3[counter##initDir][counter##i][0]; \
1040 counter(1) = lookupzfor3[counter##initDir][counter##i][1]; \
1041 counter(2) = lookupzfor3[counter##initDir][counter##i][2];
1042
1043#else
1044#define zfor3(counter, direction) zfor(counter, 3, direction)
1045
1046#endif
1047
1048
1049#define endzfor \
1050 } \
1051 }
std::string toString(peano4::utils::LoopPlacement)
Definition Loop.cpp:348
#define CPUGPUMethod
Definition Loop.h:35
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.
Definition Loop.cpp:116
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.
Definition Loop.cpp:305
CPUGPUMethod void dInc(tarch::la::Vector< Dimensions, int > &counter, int max)
d-dimensional counterpart of increment operator
Definition Loop.cpp:158
std::bitset< Dimensions > LoopDirection
Is used by the z-loop.
Definition Loop.h:70
LoopPlacement
Guide loop-level parallelism.
Definition Loop.h:65
CPUGPUMethod tarch::la::Vector< Dimensions, int > dStartVector()
Construct start vector (0,0,....) for d-dimensional loop.
Definition Loop.cpp:316
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().
Definition Loop.cpp:209
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...
Definition Loop.cpp:196
void setupLookupTableForDLinearised()
Definition Loop.cpp:68
CPUGPUMethod int dLinearised(const tarch::la::Vector< Dimensions, int > &counter, int max)
Map d-dimensional vector onto integer index.
Definition Loop.cpp:106
tarch::la::Vector< Dimensions, int > dDelinearised(int value, int max)
Counterpart of dLinearised().
Definition Loop.cpp:146
int dLinearisedWithoutLookup(const tarch::la::Vector< Dimensions, int > &counter, int max)
Linearisation not Optimised.
Definition Loop.cpp:90
void dDec(tarch::la::Vector< Dimensions, int > &counter, int max)
d-dimensional counterpart of decrement operator
Definition Loop.cpp:169
CPUGPUMethod int dCmp(const tarch::la::Vector< Dimensions, int > &counter, int max)
Element-wise comparison for the for d-dimensional for loops.
Definition Loop.cpp:292
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.
Definition Loop.cpp:129
void setupLookupTableForDDelinearised()
Definition Loop.cpp:79
tarch::la::Vector< Dimensions, int > dDelinearisedWithoutLookup(int value, int max)
Delinearization not optimised.
Definition Loop.cpp:142
Simple vector class.
Definition Vector.h:134