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
25 #ifdef TBB_OLD_BLOCKED_RANGE_ND
26 namespace tbb {
27 namespace detail {
28 namespace d1 {
29 using blocked_nd_range = blocked_rangeNd;
30 }}}
31 #endif
32#endif
33
34#if defined(SharedSYCL)
36
40#define CPUGPUMethod SYCL_EXTERNAL
41#else
42#define CPUGPUMethod
43#endif
44
45namespace peano4 {
46 namespace utils {
73
77 typedef std::bitset<Dimensions> LoopDirection;
78
90
100
110
117 void dIncByVector(tarch::la::Vector<Dimensions, int>& counter, int max, int increment);
118
123 void dIncByScalar(tarch::la::Vector<Dimensions, int>& counter, int max, int increment);
124
129 void dInc(tarch::la::Vector<Dimensions, int>& counter, int max, int doNotExamine);
130
136 void dInc(tarch::la::Vector<Dimensions, int>& counter, int max, LoopDirection& direction);
137
148
160
168 );
169
214 CPUGPUMethod int dLinearised(const std::bitset<Dimensions>& counter);
215
220 int d2Linearised(const tarch::la::Vector<2, int>& counter, int max);
221
226 int d3Linearised(const tarch::la::Vector<3, int>& counter, int max);
227
236
245
250
251
254
263
269
277 }
278}
279
280
282
283
320#define dfor(counter, max) \
321 for (tarch::la::Vector<Dimensions, int> counter = peano4::utils::dStartVector(); peano4::utils::dCmp(counter, max); \
322 peano4::utils::dInc(counter, max))
323
324
453#define parallelFor(counter, max) \
454 parallelForWithSchedulerInstructions(counter, max, ::peano4::utils::LoopPlacement::SpreadOut)
455
456#define simtFor(counter, max) \
457 simtForWithSchedulerInstructions(counter, max, ::peano4::utils::LoopPlacement::SpreadOut)
458
459#define parallelDfor(counter, max) \
460 parallelDforWithSchedulerInstructions(counter, max, ::peano4::utils::LoopPlacement::SpreadOut)
461
462#if Dimensions == 2
463#define parallelDforWithSchedulerInstructions(counter, max, loopPlacement) \
464 parallelDforWithSchedulerInstructions2d(counter, max, loopPlacement)
465
466#define parallelDPlusOneForWithSchedulerInstructions(counter, max, loopPlacement) \
467 parallelDforWithSchedulerInstructions3d(counter, max, loopPlacement)
468
469#define parallelDPlusTwoForWithSchedulerInstructions(counter, max, loopPlacement) \
470 parallelDforWithSchedulerInstructions4d(counter, max, loopPlacement)
471
472#define simtDforWithSchedulerInstructions(counter, max, loopPlacement) \
473 simtDforWithSchedulerInstructions2d(counter, max, loopPlacement)
474
475#define simtDPlusOneForWithSchedulerInstructions(counter, max, loopPlacement) \
476 simtDforWithSchedulerInstructions3d(counter, max, loopPlacement)
477
478#define simtDPlusTwoForWithSchedulerInstructions(counter, max, loopPlacement) \
479 simtDforWithSchedulerInstructions4d(counter, max, loopPlacement)
480#elif Dimensions == 3
481#define parallelDforWithSchedulerInstructions(counter, max, loopPlacement) \
482 parallelDforWithSchedulerInstructions3d(counter, max, loopPlacement)
483
484#define parallelDPlusOneForWithSchedulerInstructions(counter, max, loopPlacement) \
485 parallelDforWithSchedulerInstructions4d(counter, max, loopPlacement)
486
487#define parallelDPlusTwoForWithSchedulerInstructions(counter, max, loopPlacement) \
488 parallelDforWithSchedulerInstructions5d(counter, max, loopPlacement)
489
490#define simtDforWithSchedulerInstructions(counter, max, loopPlacement) \
491 simtDforWithSchedulerInstructions3d(counter, max, loopPlacement)
492
493#define simtDPlusOneForWithSchedulerInstructions(counter, max, loopPlacement) \
494 simtDforWithSchedulerInstructions4d(counter, max, loopPlacement)
495
496#define simtDPlusTwoForWithSchedulerInstructions(counter, max, loopPlacement) \
497 simtDforWithSchedulerInstructions5d(counter, max, loopPlacement)
498#endif
499
500
501#if defined(SharedOMP) and defined(OpenMPTaskGroup)
502#include "omp/Loop.h"
503#elif defined(SharedOMP) and !defined(OpenMPTaskGroup)
505#elif defined(SharedTBB)
506#include "tbb/Loop.h"
507#elif defined(SharedCPP)
508//and __cplusplus >= 202101L
509#include "cpp/Loop.h"
510#elif defined(SharedSYCL)
511#include "sycl/Loop.h"
512#else
513#define parallelForWithSchedulerInstructions(counter, max, loopPlacement) \
514 for (int counter = 0; counter < max; counter++) {
515
516#define parallelDforWithSchedulerInstructions2d(counter, max, loopPlacement) \
517 { \
518 tarch::la::Vector<2, 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 tarch::la::Vector<2, int> counter = {counter##0, counter##1};
522
523#define parallelDforWithSchedulerInstructions3d(counter, max, loopPlacement) \
524 { \
525 tarch::la::Vector<3, int> counter##Max(max); \
526 for (int counter##0 = 0; counter##0 < counter##Max(0); counter##0 ++) \
527 for (int counter##1 = 0; counter##1 < counter##Max(1); counter##1 ++) \
528 for (int counter##2 = 0; counter##2 < counter##Max(2); counter##2 ++) { \
529 tarch::la::Vector<3, int> counter = {counter##0, counter##1, counter##2};
530
531#define parallelDforWithSchedulerInstructions4d(counter, max, loopPlacement) \
532 { \
533 tarch::la::Vector<4, int> counter##Max(max); \
534 for (int counter##0 = 0; counter##0 < counter##Max(0); counter##0 ++) \
535 for (int counter##1 = 0; counter##1 < counter##Max(1); counter##1 ++) \
536 for (int counter##2 = 0; counter##2 < counter##Max(2); counter##2 ++) \
537 for (int counter##3 = 0; counter##3 < counter##Max(3); counter##3 ++) { \
538 tarch::la::Vector<4, int> counter = {counter##0, counter##1, counter##2, counter##3};
539
540#define parallelDforWithSchedulerInstructions5d(counter, max, loopPlacement) \
541 { \
542 tarch::la::Vector<5, int> counter##Max(max); \
543 for (int counter##0 = 0; counter##0 < counter##Max(0); counter##0 ++) \
544 for (int counter##1 = 0; counter##1 < counter##Max(1); counter##1 ++) \
545 for (int counter##2 = 0; counter##2 < counter##Max(2); counter##2 ++) \
546 for (int counter##3 = 0; counter##3 < counter##Max(3); counter##3 ++) \
547 for (int counter##4 = 0; counter##4 < counter##Max(4); counter##4 ++) { \
548 tarch::la::Vector<5, int> counter = {counter##0, counter##1, counter##2, counter##3, counter##4};
549
550#define endParallelFor }
551#define endParallelDfor \
552 } \
553 }
554
555
556#define simtForWithSchedulerInstructions(counter, max, loopPlacement) \
557 for (int counter = 0; counter < max; counter++) {
558
559#define endSimtFor endParallelFor
560
561#define simtDforWithSchedulerInstructions2d(counter, max, loopPlacement) \
562 parallelDforWithSchedulerInstructions2d(counter, max, loopPlacement)
563
564#define simtDforWithSchedulerInstructions3d(counter, max, loopPlacement) \
565 parallelDforWithSchedulerInstructions3d(counter, max, loopPlacement)
566
567#define simtDforWithSchedulerInstructions4d(counter, max, loopPlacement) \
568 parallelDforWithSchedulerInstructions4d(counter, max, loopPlacement)
569
570#define simtDforWithSchedulerInstructions5d(counter, max, loopPlacement) \
571 parallelDforWithSchedulerInstructions5d(counter, max, loopPlacement)
572
573#define endSimtDfor endParallelDfor
574
575#endif
576
577
608#define dfor4(counter) \
609 for (int counter##Scalar = 0; counter##Scalar < FOUR_POWER_D; counter##Scalar++) { \
610 tarch::la::Vector<Dimensions, int> counter; \
611 { \
612 int copy##counter##Scalar = counter##Scalar; \
613 for (int counter##ddd = Dimensions - 1; counter##ddd >= 0; counter##ddd--) { \
614 int counter##aPowI = 1; \
615 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
616 counter##aPowI *= 4; \
617 } \
618 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
619 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
620 } \
621 }
622
623
654#define dfor3(counter) \
655 for (int counter##Scalar = 0; counter##Scalar < ThreePowerD; counter##Scalar++) { \
656 tarch::la::Vector<Dimensions, int> counter; \
657 { \
658 int copy##counter##Scalar = counter##Scalar; \
659 for (int counter##ddd = Dimensions - 1; counter##ddd >= 0; counter##ddd--) { \
660 int counter##aPowI = 1; \
661 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
662 counter##aPowI *= 3; \
663 } \
664 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
665 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
666 } \
667 }
668
669
670#define dfor5(counter) \
671 for (int counter##Scalar = 0; counter##Scalar < FIVE_POWER_D; counter##Scalar++) { \
672 tarch::la::Vector<Dimensions, int> counter; \
673 { \
674 int copy##counter##Scalar = counter##Scalar; \
675 for (int counter##ddd = Dimensions - 1; counter##ddd >= 0; counter##ddd--) { \
676 int counter##aPowI = 1; \
677 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
678 counter##aPowI *= 5; \
679 } \
680 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
681 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
682 } \
683 }
684
685#define dfor7(counter) \
686 for (int counter##Scalar = 0; counter##Scalar < SEVEN_POWER_D; counter##Scalar++) { \
687 tarch::la::Vector<Dimensions, int> counter; \
688 { \
689 int copy##counter##Scalar = counter##Scalar; \
690 for (int counter##ddd = Dimensions - 1; counter##ddd >= 0; counter##ddd--) { \
691 int counter##aPowI = 1; \
692 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
693 counter##aPowI *= 7; \
694 } \
695 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
696 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
697 } \
698 }
699
700
701#define dfor9(counter) \
702 for (int counter##Scalar = 0; counter##Scalar < NINE_POWER_D; counter##Scalar++) { \
703 tarch::la::Vector<Dimensions, int> counter; \
704 { \
705 int copy##counter##Scalar = counter##Scalar; \
706 for (int counter##ddd = Dimensions - 1; counter##ddd >= 0; counter##ddd--) { \
707 int counter##aPowI = 1; \
708 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
709 counter##aPowI *= 9; \
710 } \
711 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
712 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
713 } \
714 }
715
730#define d2for(counter, max) \
731 for (int counter##Scalar = 0; counter##Scalar < tarch::la::aPowI(2, max); counter##Scalar++) { \
732 tarch::la::Vector<2, int> counter; \
733 { \
734 int copy##counter##Scalar = counter##Scalar; \
735 for (int counter##ddd = 2 - 1; counter##ddd >= 0; counter##ddd--) { \
736 int counter##aPowI = 1; \
737 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
738 counter##aPowI *= max; \
739 } \
740 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
741 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
742 } \
743 }
744
751#define d2for2(counter) \
752 for (int counter##Scalar = 0; counter##Scalar < tarch::la::aPowI(2, 2); counter##Scalar++) { \
753 tarch::la::Vector<2, int> counter; \
754 { \
755 int copy##counter##Scalar = counter##Scalar; \
756 for (int counter##ddd = 2 - 1; counter##ddd >= 0; counter##ddd--) { \
757 int counter##aPowI = 1; \
758 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
759 counter##aPowI *= 2; \
760 } \
761 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
762 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
763 } \
764 }
765
772#define d3for2(counter) \
773 for (int counter##Scalar = 0; counter##Scalar < tarch::la::aPowI(3, 2); counter##Scalar++) { \
774 tarch::la::Vector<3, int> counter; \
775 { \
776 int copy##counter##Scalar = counter##Scalar; \
777 for (int counter##ddd = 3 - 1; counter##ddd >= 0; counter##ddd--) { \
778 int counter##aPowI = 1; \
779 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
780 counter##aPowI *= 2; \
781 } \
782 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
783 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
784 } \
785 }
786
787
802#define d3for(counter, max) \
803 for (int counter##Scalar = 0; counter##Scalar < tarch::la::aPowI(3, max); counter##Scalar++) { \
804 tarch::la::Vector<3, int> counter; \
805 { \
806 int copy##counter##Scalar = counter##Scalar; \
807 for (int counter##ddd = 3 - 1; counter##ddd >= 0; counter##ddd--) { \
808 int counter##aPowI = 1; \
809 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
810 counter##aPowI *= max; \
811 } \
812 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
813 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
814 } \
815 }
816
817
824#define d2for3(counter) \
825 for (int counter##Scalar = 0; counter##Scalar < tarch::la::aPowI(2, 3); counter##Scalar++) { \
826 tarch::la::Vector<2, int> counter; \
827 { \
828 int copy##counter##Scalar = counter##Scalar; \
829 for (int counter##ddd = 2 - 1; counter##ddd >= 0; counter##ddd--) { \
830 int counter##aPowI = 1; \
831 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
832 counter##aPowI *= 3; \
833 } \
834 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
835 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
836 } \
837 }
838
845#define d3for3(counter) \
846 for (int counter##Scalar = 0; counter##Scalar < tarch::la::aPowI(3, 3); counter##Scalar++) { \
847 tarch::la::Vector<3, int> counter; \
848 { \
849 int copy##counter##Scalar = counter##Scalar; \
850 for (int counter##ddd = 3 - 1; counter##ddd >= 0; counter##ddd--) { \
851 int counter##aPowI = 1; \
852 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
853 counter##aPowI *= 3; \
854 } \
855 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
856 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
857 } \
858 }
859
860
892/*
893 * bit flipping used for Dimensions = 2, and Dimensions = 3
894 * for more information about the idea principle used refer to https://opt-patterns.wiki.tum.de/dfor
895 */
896#if Dimensions == 2
897#define dfor2(counter) \
898 for (int counter##Scalar = 0, AA##counter = 0, BB##counter = 0; counter##Scalar < TwoPowerD; counter##Scalar++) { \
899 tarch::la::Vector<Dimensions, int> counter; \
900 counter(0) = AA##counter; \
901 counter(1) = BB##counter; \
902 AA##counter = !AA##counter; \
903 BB##counter = !(AA##counter ^ BB##counter);
904
905#elif Dimensions == 3
906#define dfor2(counter) \
907 for (int counter##Scalar = 0, AA##counter = 0, BB##counter = 0, CC##counter = 0; counter##Scalar < TwoPowerD; \
908 counter##Scalar++) { \
909 tarch::la::Vector<Dimensions, int> counter; \
910 counter(0) = AA##counter; \
911 counter(1) = BB##counter; \
912 counter(2) = CC##counter; \
913 AA##counter = !AA##counter; \
914 BB##counter = !(AA##counter ^ BB##counter); \
915 CC##counter = CC##counter || (!AA##counter && !BB##counter && !CC##counter);
916
917#else
918#define dfor2(counter) \
919 for (int counter##Scalar = 0; counter##Scalar < TwoPowerD; counter##Scalar++) { \
920 tarch::la::Vector<Dimensions, int> counter; \
921 { \
922 int copy##counter##Scalar = counter##Scalar; \
923 for (int counter##ddd = Dimensions - 1; counter##ddd >= 0; counter##ddd--) { \
924 int counter##aPowI = 1; \
925 for (int counter##jjj = 0; counter##jjj < counter##ddd; counter##jjj++) { \
926 counter##aPowI *= 2; \
927 } \
928 counter(counter##ddd) = copy##counter##Scalar / counter##aPowI; \
929 copy##counter##Scalar -= counter(counter##ddd) * counter##aPowI; \
930 } \
931 }
932
933#endif
934
935
940#define enddforx }
941
942
949#define dfore(counter, max, dim, value) \
950 for (tarch::la::Vector<Dimensions, int> counter = peano4::utils::dStartVector(dim, value); \
951 peano4::utils::dCmp(counter, max); \
952 peano4::utils::dInc(counter, max, dim))
953
954
986#define zfor(counter, max, direction) \
987 { \
988 for (tarch::la::Vector<Dimensions, int> counter = peano4::utils::dStartVector(max, direction); \
989 peano4::utils::dCmp(counter, max); \
990 peano4::utils::dInc(counter, max, direction)) {
991
992
993/*
994 * zfor3 is an optimized version of zfor for max = 3
995 * A lookup table is used for dim=2 and dim=3, for higher dimensions
996 * the standard zfor is used instead
997 */
998#if Dimensions == 2
999// first entry is direction, second entry is cell, third entry is tuples
1000static const int lookupzfor3[4][9][2] = {
1001 {{2, 2}, {1, 2}, {0, 2}, {0, 1}, {1, 1}, {2, 1}, {2, 0}, {1, 0}, {0, 0}},
1002 {{0, 2}, {1, 2}, {2, 2}, {2, 1}, {1, 1}, {0, 1}, {0, 0}, {1, 0}, {2, 0}},
1003 {{2, 0}, {1, 0}, {0, 0}, {0, 1}, {1, 1}, {2, 1}, {2, 2}, {1, 2}, {0, 2}},
1004 {{0, 0}, {1, 0}, {2, 0}, {2, 1}, {1, 1}, {0, 1}, {0, 2}, {1, 2}, {2, 2}}};
1005
1006#define zfor3(counter, direction) \
1007 { \
1008 tarch::la::Vector<Dimensions, int> counter; \
1009 int counter##initDir = static_cast<int>(direction.to_ulong()); \
1010 for (int counter##i = 0; counter##i < 9; ++counter##i) { \
1011 counter(0) = lookupzfor3[counter##initDir][counter##i][0]; \
1012 counter(1) = lookupzfor3[counter##initDir][counter##i][1];
1013
1014#elif Dimensions == 3
1015static const int lookupzfor3[8][27][3] = {
1016 {{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},
1017 {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},
1018 {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}},
1019 {{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},
1020 {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},
1021 {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}},
1022 {{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},
1023 {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},
1024 {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}},
1025 {{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},
1026 {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},
1027 {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}},
1028 {{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},
1029 {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},
1030 {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}},
1031 {{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},
1032 {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},
1033 {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}},
1034 {{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},
1035 {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},
1036 {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}},
1037 {{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},
1038 {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},
1039 {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}}};
1040
1041#define zfor3(counter, direction) \
1042 { \
1043 tarch::la::Vector<Dimensions, int> counter; \
1044 int counter##initDir = static_cast<int>(direction.to_ulong()); \
1045 for (int counter##i = 0; counter##i < 27; ++counter##i) { \
1046 counter(0) = lookupzfor3[counter##initDir][counter##i][0]; \
1047 counter(1) = lookupzfor3[counter##initDir][counter##i][1]; \
1048 counter(2) = lookupzfor3[counter##initDir][counter##i][2];
1049
1050#else
1051#define zfor3(counter, direction) zfor(counter, 3, direction)
1052
1053#endif
1054
1055
1056#define endzfor \
1057 } \
1058 }
std::string toString(peano4::utils::LoopPlacement)
#define CPUGPUMethod
Definition Loop.h:42
CPUGPUMethod void dInc(tarch::la::Vector< Dimensions, int > &counter, int max)
d-dimensional counterpart of increment operator
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.
std::bitset< Dimensions > LoopDirection
Is used by the z-loop.
Definition Loop.h:77
LoopPlacement
Guide loop-level parallelism.
Definition Loop.h:72
CPUGPUMethod int dLinearised(const tarch::la::Vector< Dimensions, int > &counter, int max)
Map d-dimensional vector onto integer index.
CPUGPUMethod int dCmp(const tarch::la::Vector< Dimensions, int > &counter, int max)
Element-wise comparison for the for d-dimensional for loops.
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().
CPUGPUMethod tarch::la::Vector< Dimensions, int > dStartVector()
Construct start vector (0,0,....) for d-dimensional loop.
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()
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
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.
I've written an API to IIT, but I'm not currently using.
Simple vector class.
Definition Vector.h:159