@@ -53,13 +53,25 @@ namespace opdi {
5353 this ->parallelData );
5454 DataTools::pushTaskData (this ->taskData );
5555
56- ReductionTools::beginRegionThatSupportsReductions (false );
56+ assert (ReductionTools::implicitTaskNestingDepth <= omp_get_level ());
57+
58+ if (ReductionTools::implicitTaskNestingDepth != omp_get_level ()) {
59+ /* TaskProbe constructor before ReductionProbe constructor (if any) */
60+ do {
61+ ++ReductionTools::implicitTaskNestingDepth;
62+ } while (ReductionTools::implicitTaskNestingDepth != omp_get_level ());
63+
64+ ReductionTools::beginRegionThatSupportsReductions (false );
65+ }
5766 }
5867
5968 ~TaskProbe () {
6069 if (needsAction) {
61- /* order of TaskProbe and ReductionProbe destructors not relevant */
70+ assert (ReductionTools::implicitTaskNestingDepth == omp_get_level ());
71+
6272 ReductionTools::endRegionThatSupportsReductions ();
73+ --ReductionTools::implicitTaskNestingDepth;
74+
6375 logic->onImplicitTaskEnd (this ->taskData );
6476 DataTools::popTaskData ();
6577 DataTools::popParallelData ();
@@ -103,9 +115,20 @@ namespace opdi {
103115 struct ReductionProbe {
104116 public:
105117
106- ReductionProbe (int ) {}
118+ ReductionProbe (int ) {}
107119
108120 ReductionProbe () {
121+ assert (ReductionTools::implicitTaskNestingDepth <= omp_get_level ());
122+
123+ if (ReductionTools::implicitTaskNestingDepth != omp_get_level ()) {
124+ /* this condition can only be satisfied by probes on a parallel construct */
125+ /* ReductionProbe constructor before TaskProbe constructor */
126+ do {
127+ ++ReductionTools::implicitTaskNestingDepth;
128+ } while (ReductionTools::implicitTaskNestingDepth != omp_get_level ());
129+ ReductionTools::beginRegionThatSupportsReductions (false );
130+ }
131+
109132 ReductionTools::regionHasReductions ();
110133 }
111134
0 commit comments