Bump version to 19.1.0-rc3
[llvm-project.git] / offload / test / offloading / back2back_distribute.c
blob63cabd0c66788b5931411f9e193692410f588811
1 // RUN: %libomptarget-compile-generic -O3 && %libomptarget-run-generic | %fcheck-generic
3 #include <omp.h>
4 #include <stdio.h>
5 #include <stdlib.h>
7 #define MAX_N 25000
9 void reset_input(double *a, double *a_h, double *b, double *c) {
10 for(int i = 0 ; i < MAX_N ; i++) {
11 a[i] = a_h[i] = i;
12 b[i] = i*2;
13 c[i] = i-3;
17 int main(int argc, char *argv[]) {
18 double *a = (double *)calloc(MAX_N, sizeof(double));
19 double *a_h = (double *)calloc(MAX_N, sizeof(double));
20 double *d = (double *)calloc(MAX_N, sizeof(double));
21 double *d_h = (double *)calloc(MAX_N, sizeof(double));
22 double *b = (double *)calloc(MAX_N, sizeof(double));
23 double *c = (double *)calloc(MAX_N, sizeof(double));
25 #pragma omp target enter data map(to:a[:MAX_N],b[:MAX_N],c[:MAX_N],d[:MAX_N])
27 for (int n = 32 ; n < MAX_N ; n+=5000) {
28 reset_input(a, a_h, b, c);
30 #pragma omp target update to(a[:n],b[:n],c[:n],d[:n])
31 int t = 0;
32 for (int tms = 1 ; tms <= 256 ; tms *= 2) { // 8 times
33 for (int ths = 32 ; ths <= 1024 ; ths *= 2) { // 6 times
34 t++;
35 #pragma omp target
36 #pragma omp teams num_teams(tms) thread_limit(ths)
38 #pragma omp distribute parallel for
39 for (int i = 0; i < n; ++i) {
40 a[i] += b[i] + c[i];
42 #pragma omp distribute parallel for
43 for (int i = 0; i < n; ++i) {
44 d[i] -= b[i] + c[i];
47 } // loop over 'ths'
48 } // loop over 'tms'
50 // check results for each 'n'
51 for (int times = 0 ; times < t ; times++) {
52 for (int i = 0; i < n; ++i) {
53 a_h[i] += b[i] + c[i];
55 for (int i = 0; i < n; ++i)
56 d_h[i] -= b[i] + c[i];
58 #pragma omp target update from(a[:n],d[:n])
60 for (int i = 0; i < n; ++i) {
61 if (a_h[i] != a[i]) {
62 printf("A Error at n = %d, i = %d: host = %f, device = %f\n", n, i, a_h[i], a[i]);
63 return 1;
65 if (d_h[i] != d[i]) {
66 printf("D Error at n = %d, i = %d: host = %lf, device = %lf\n", n, i, d_h[i], d[i]);
67 return 1;
70 } // loop over 'n'
72 // CHECK: Succeeded
73 printf("Succeeded\n");
74 return 0;