summaryrefslogtreecommitdiff
path: root/openmp
diff options
context:
space:
mode:
authorAnimesh Kumar <animesh.kumar@amd.com>2023-03-23 14:58:01 +0530
committerAnimesh Kumar <animesh.kumar@amd.com>2023-04-28 15:53:41 +0530
commit578b2a36b6756f91e3e22d967f98efb5ff090d25 (patch)
treef9670243b15417b13b4c4c467ef2cee24816fb03 /openmp
parentcd68e17bc2f9b7b54a3d3ab5f917793d41ce17cb (diff)
downloadllvm-578b2a36b6756f91e3e22d967f98efb5ff090d25.tar.gz
[OpenMP] Add LIT test on task depend clause
The working of depend clause with iterator modifier can be correctly tested by means of execution tests and not at the LLVM IR level. These tests are imported/inspired from the SOLLVE tests. SOLLVE repo: https://github.com/SOLLVE/sollve_vv Differential Revision: https://reviews.llvm.org/D146706
Diffstat (limited to 'openmp')
-rw-r--r--openmp/runtime/test/tasking/omp_task_depend_iterator.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/openmp/runtime/test/tasking/omp_task_depend_iterator.cpp b/openmp/runtime/test/tasking/omp_task_depend_iterator.cpp
new file mode 100644
index 000000000000..27eee0a45fc3
--- /dev/null
+++ b/openmp/runtime/test/tasking/omp_task_depend_iterator.cpp
@@ -0,0 +1,86 @@
+// RUN: %libomp-cxx-compile-and-run
+
+/*
+
+This test is imported from SOLLVE: 5.0/task/test_task_depend_iterator.cpp
+SOLLVE page: https://github.com/SOLLVE/sollve_vv
+
+OpenMP API Version 5.0 Nov 2020
+
+This test is for the iterator modifier when used with the task depend
+clause. This modifier should create an iterator that expands to multiple values
+inside the clause they appear. In this particular test case the iterator expands into
+several values creating several dependencies at the same time.
+
+*/
+
+#include <omp.h>
+#include <algorithm>
+#include <cstdlib>
+#include <iostream>
+#include <thread>
+#include <vector>
+#include "omp_testsuite.h"
+
+#define N 1024
+#define FROM 64
+#define LENGTH 128
+
+int test_omp_task_depend_iterator() {
+ int ptr[] = {0, 4, 5, 6, 7, 8, 9, 10, 11};
+ int cols[] = {1, 2, 3, 4, 5, 5, 6, 6, 7, 7, 8};
+ std::vector<int> threadOrder;
+ bool threadOrderError = false;
+#pragma omp parallel num_threads(8)
+ {
+#pragma omp single
+ {
+ for (int i = 0; i < 8; ++i) {
+ int pos = ptr[i], size = ptr[i + 1] - ptr[i];
+#pragma omp task depend(iterator(it = 0 : size), in : ptr[cols[pos + it]]) depend(out : ptr[i])
+ {
+#pragma omp critical
+ {
+ threadOrder.push_back(i);
+ } // end critical section
+ } // end task depend
+ }
+ } // end single
+ } // end parallel
+
+ // store the indices of the execution order of generated tasks in idx[]
+ std::vector<int>::iterator idx[8];
+ for (int i = 0; i < 8; ++i)
+ idx[i] = std::find (threadOrder.begin(), threadOrder.end(), i);
+
+ // verify that dependencies are met in the order
+ if (idx[0] != threadOrder.begin())
+ threadOrderError |= true;
+ if (idx[1] > idx[5] || idx[2] > idx[5])
+ threadOrderError |= true;
+ if (idx[3] > idx[6] || idx[4] > idx[6])
+ threadOrderError |= true;
+ if (idx[5] > idx[7] || idx[6] > idx[7])
+ threadOrderError |= true;
+
+ std::sort(threadOrder.begin(), threadOrder.end());
+ for(int i = 0; i < 8; ++i)
+ threadOrderError = (threadOrder[i] != i) || threadOrderError;
+
+ // FALSE If dependencies between tasks were not enforced in the correct order.
+ return !threadOrderError;
+}
+
+
+
+int main() {
+ int i;
+ int num_failed=0;
+
+ for(i = 0; i < REPETITIONS; i++) {
+ if(!test_omp_task_depend_iterator()) {
+ num_failed++;
+ }
+ }
+ return num_failed;
+}