1 | // Run lines are in the target specific versions. |
2 | |
3 | #include <omp.h> |
4 | #include <stdio.h> |
5 | |
6 | #define N 512 |
7 | |
8 | int main() { |
9 | int Result[N], NumThreads; |
10 | |
11 | #pragma omp target teams num_teams(1) thread_limit(N) \ |
12 | ompx_dyn_cgroup_mem(N * sizeof(Result[0])) \ |
13 | map(from : Result, NumThreads) |
14 | { |
15 | int Buffer[N]; |
16 | #pragma omp parallel |
17 | { |
18 | int *DynBuffer = (int *)llvm_omp_target_dynamic_shared_alloc(); |
19 | int TId = omp_get_thread_num(); |
20 | if (TId == 0) |
21 | NumThreads = omp_get_num_threads(); |
22 | Buffer[TId] = 7; |
23 | DynBuffer[TId] = 3; |
24 | #pragma omp barrier |
25 | int WrappedTId = (TId + 37) % NumThreads; |
26 | Result[TId] = Buffer[WrappedTId] + DynBuffer[WrappedTId]; |
27 | } |
28 | } |
29 | |
30 | if (llvm_omp_target_dynamic_shared_alloc()) |
31 | return -1; |
32 | |
33 | if (NumThreads < N / 2 || NumThreads > N) { |
34 | printf(format: "Expected number of threads to be in [%i:%i], but got: %i" , N / 2, N, |
35 | NumThreads); |
36 | return -1; |
37 | } |
38 | |
39 | int Failed = 0; |
40 | for (int i = 0; i < NumThreads; ++i) { |
41 | if (Result[i] != 7 + 3) { |
42 | printf(format: "Result[%i] is %i, expected %i\n" , i, Result[i], 7 + 3); |
43 | ++Failed; |
44 | } |
45 | } |
46 | |
47 | if (!Failed) |
48 | printf(format: "PASS\n" ); |
49 | } |
50 | |