Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / libomptarget / test / offloading / ompx_coords.c
blob61dad61f46405e369289be09594e480d2b8e78cb
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
8 #include <omp.h>
9 #include <ompx.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
14 struct info {
15 int tid, bid, tdim;
18 int main(int argc, char **argv) {
19 int N = 1 << 20;
20 if (argc > 1)
21 N = atoi(argv[1]);
23 struct info *X = (struct info *)malloc(sizeof(*X) * N);
24 memset(X, '0', sizeof(*X) * N);
26 int TL = 256;
27 int NT = (N + TL - 1) / TL;
29 #pragma omp target data map(tofrom : X [0:N])
30 #pragma omp target teams num_teams(NT) thread_limit(TL)
32 #pragma omp parallel
34 int tid = ompx_thread_id_x();
35 int bid = ompx_block_id_x();
36 int tdim = ompx_block_dim_x();
37 int gid = tid + bid * tdim;
38 if (gid < N) {
39 X[gid].tid = tid;
40 X[gid].bid = bid;
41 X[gid].tdim = tdim;
46 int tid = 0, bid = 0, tdim = 256;
47 for (int i = 0; i < N; i++) {
48 if (X[i].tid != tid || X[i].bid != bid || X[i].tdim != tdim) {
49 printf("%i: %i vs %i, %i vs %i, %i vs %i\n", i, X[i].tid, tid, X[i].bid,
50 bid, X[i].tdim, tdim);
51 return 1;
53 tid++;
54 if (tid == tdim) {
55 tid = 0;
56 bid++;
60 // CHECK: OK
61 printf("OK");
62 return 0;