1 // RUN: %libomp-cxx-compile-and-run
5 This test is imported from SOLLVE: 5.0/task/test_task_depend_iterator.cpp
6 SOLLVE page: https://github.com/SOLLVE/sollve_vv
8 OpenMP API Version 5.0 Nov 2020
10 This test is for the iterator modifier when used with the task depend
11 clause. This modifier should create an iterator that expands to multiple values
12 inside the clause they appear. In this particular test case the iterator expands into
13 several values creating several dependencies at the same time.
23 #include "omp_testsuite.h"
29 int test_omp_task_depend_iterator() {
30 int ptr
[] = {0, 4, 5, 6, 7, 8, 9, 10, 11};
31 int cols
[] = {1, 2, 3, 4, 5, 5, 6, 6, 7, 7, 8};
32 std::vector
<int> threadOrder
;
33 bool threadOrderError
= false;
34 #pragma omp parallel num_threads(8)
38 for (int i
= 0; i
< 8; ++i
) {
39 int pos
= ptr
[i
], size
= ptr
[i
+ 1] - ptr
[i
];
40 #pragma omp task depend(iterator(it = 0 : size), in : ptr[cols[pos + it]]) depend(out : ptr[i])
44 threadOrder
.push_back(i
);
45 } // end critical section
51 // store the indices of the execution order of generated tasks in idx[]
52 std::vector
<int>::iterator idx
[8];
53 for (int i
= 0; i
< 8; ++i
)
54 idx
[i
] = std::find (threadOrder
.begin(), threadOrder
.end(), i
);
56 // verify that dependencies are met in the order
57 if (idx
[0] != threadOrder
.begin())
58 threadOrderError
|= true;
59 if (idx
[1] > idx
[5] || idx
[2] > idx
[5])
60 threadOrderError
|= true;
61 if (idx
[3] > idx
[6] || idx
[4] > idx
[6])
62 threadOrderError
|= true;
63 if (idx
[5] > idx
[7] || idx
[6] > idx
[7])
64 threadOrderError
|= true;
66 std::sort(threadOrder
.begin(), threadOrder
.end());
67 for(int i
= 0; i
< 8; ++i
)
68 threadOrderError
= (threadOrder
[i
] != i
) || threadOrderError
;
70 // FALSE If dependencies between tasks were not enforced in the correct order.
71 return !threadOrderError
;
80 for(i
= 0; i
< REPETITIONS
; i
++) {
81 if(!test_omp_task_depend_iterator()) {