|
| 1 | +// REQUIRES: ompx_taskgraph |
| 2 | +// RUN: %libomp-cxx-compile-and-run |
| 3 | +#include <omp.h> |
| 4 | +#include <cassert> |
| 5 | +#include <vector> |
| 6 | + |
| 7 | +constexpr const int TASKS_SIZE = 12; |
| 8 | + |
| 9 | +typedef struct ident ident_t; |
| 10 | + |
| 11 | +extern "C" { |
| 12 | +int __kmpc_global_thread_num(ident_t *); |
| 13 | +int __kmpc_start_record_task(ident_t *, int, int, int); |
| 14 | +void __kmpc_end_record_task(ident_t *, int, int, int); |
| 15 | +} |
| 16 | + |
| 17 | +void init(int &A, int val) { A = val; } |
| 18 | + |
| 19 | +void update(int &A, int &B, int val) { A = B + val; } |
| 20 | + |
| 21 | +void test(int nb, std::vector<std::vector<int>> &Ah) { |
| 22 | +#pragma omp parallel |
| 23 | +#pragma omp single |
| 24 | + { |
| 25 | + int gtid = __kmpc_global_thread_num(nullptr); |
| 26 | + int res = __kmpc_start_record_task(nullptr, gtid, 0, 0); |
| 27 | + if (res) { |
| 28 | + for (int k = 0; k < nb; ++k) { |
| 29 | +#pragma omp task depend(inout : Ah[k][0]) |
| 30 | + init(Ah[k][0], k); |
| 31 | + |
| 32 | + for (int i = 1; i < nb; ++i) { |
| 33 | +#pragma omp task depend(in : Ah[k][0]) depend(out : Ah[k][i]) |
| 34 | + update(Ah[k][i], Ah[k][0], 1); |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + __kmpc_end_record_task(nullptr, gtid, 0, 0); |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +int main() { |
| 43 | + std::vector<std::vector<int>> matrix(TASKS_SIZE, |
| 44 | + std::vector<int>(TASKS_SIZE, 0)); |
| 45 | + |
| 46 | + test(TASKS_SIZE, matrix); |
| 47 | + test(TASKS_SIZE, matrix); |
| 48 | + |
| 49 | + for (int k = 0; k < TASKS_SIZE; ++k) { |
| 50 | + assert(matrix[k][0] == k); |
| 51 | + for (int i = 1; i < TASKS_SIZE; ++i) { |
| 52 | + assert(matrix[k][i] == k + 1); |
| 53 | + } |
| 54 | + } |
| 55 | + return 0; |
| 56 | +} |
0 commit comments