1 | // RUN: %libomptarget-compileopt-run-and-check-generic |
2 | // |
3 | // UNSUPPORTED: x86_64-pc-linux-gnu |
4 | // UNSUPPORTED: x86_64-pc-linux-gnu-LTO |
5 | // UNSUPPORTED: aarch64-unknown-linux-gnu |
6 | // UNSUPPORTED: aarch64-unknown-linux-gnu-LTO |
7 | // UNSUPPORTED: s390x-ibm-linux-gnu |
8 | // UNSUPPORTED: s390x-ibm-linux-gnu-LTO |
9 | |
10 | #include <omp.h> |
11 | #include <ompx.h> |
12 | #include <stdio.h> |
13 | #include <stdlib.h> |
14 | #include <string.h> |
15 | |
16 | struct info { |
17 | int tid, bid, tdim; |
18 | }; |
19 | |
20 | int main(int argc, char **argv) { |
21 | int N = 1 << 20; |
22 | if (argc > 1) |
23 | N = atoi(nptr: argv[1]); |
24 | |
25 | struct info *X = (struct info *)malloc(size: sizeof(*X) * N); |
26 | memset(s: X, c: '0', n: sizeof(*X) * N); |
27 | |
28 | int TL = 256; |
29 | int NT = (N + TL - 1) / TL; |
30 | |
31 | #pragma omp target data map(tofrom : X [0:N]) |
32 | #pragma omp target teams num_teams(NT) thread_limit(TL) |
33 | { |
34 | #pragma omp parallel |
35 | { |
36 | int tid = ompx_thread_id_x(); |
37 | int bid = ompx_block_id_x(); |
38 | int tdim = ompx_block_dim_x(); |
39 | int gid = tid + bid * tdim; |
40 | if (gid < N) { |
41 | X[gid].tid = tid; |
42 | X[gid].bid = bid; |
43 | X[gid].tdim = tdim; |
44 | }; |
45 | } |
46 | } |
47 | |
48 | int tid = 0, bid = 0, tdim = 256; |
49 | for (int i = 0; i < N; i++) { |
50 | if (X[i].tid != tid || X[i].bid != bid || X[i].tdim != tdim) { |
51 | printf(format: "%i: %i vs %i, %i vs %i, %i vs %i\n" , i, X[i].tid, tid, X[i].bid, |
52 | bid, X[i].tdim, tdim); |
53 | return 1; |
54 | } |
55 | tid++; |
56 | if (tid == tdim) { |
57 | tid = 0; |
58 | bid++; |
59 | } |
60 | } |
61 | |
62 | // CHECK: OK |
63 | printf(format: "OK" ); |
64 | return 0; |
65 | } |
66 | |