Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / libomptarget / test / offloading / ompx_saxpy_mixed.c
blob440b694e3ac706d110ed0467ab00bf58264cebff
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 <math.h>
9 #include <omp.h>
10 #include <ompx.h>
11 #include <stdio.h>
12 #include <stdlib.h>
14 int main(int argc, char **argv) {
15 int N = 1 << 29;
16 if (argc > 1)
17 N = atoi(argv[1]);
18 float a = 2.f;
20 float *X = (float *)malloc(sizeof(*X) * N);
21 float *Y = (float *)malloc(sizeof(*X) * N);
23 for (int i = 0; i < N; i++) {
24 X[i] = 1.0f;
25 Y[i] = 2.0f;
28 int TL = 256;
29 int NT = (N + TL - 1) / TL;
31 #pragma omp target data map(to : X [0:N]) map(Y [0:N])
32 #pragma omp target teams num_teams(NT) thread_limit(TL)
34 #pragma omp parallel
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 Y[gid] = a * X[gid] + Y[gid];
45 float maxError = 0.0f;
46 for (int i = 0; i < N; i++) {
47 maxError = fmax(maxError, fabs(Y[i] - 4.0f));
48 if (maxError) {
49 printf("%i %f %f\n", i, maxError, Y[i]);
50 break;
53 // CHECK: Max error: 0.00
54 printf("Max error: %f\n", maxError);
56 return 0;