]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libgomp/testsuite/libgomp.c/examples-4/target_data-3.c
8 void init (int Q
[][COLS
], const int rows
, const int cols
)
11 for (i
= 0; i
< rows
; i
++)
12 for (j
= 0; j
< cols
; j
++)
13 Q
[i
][j
] = (i
+ 1) * 100 + (j
+ 1);
16 void check (int a
[][COLS
], int b
[][COLS
], const int rows
, const int cols
)
19 for (i
= 0; i
< rows
; i
++)
20 for (j
= 0; j
< cols
; j
++)
21 if (a
[i
][j
] != b
[i
][j
])
25 void gramSchmidt_ref (int Q
[][COLS
], const int rows
, const int cols
)
29 for (k
= 0; k
< cols
; k
++)
33 for (i
= 0; i
< rows
; i
++)
34 tmp
+= (Q
[i
][k
] * Q
[i
][k
]);
36 for (i
= 0; i
< rows
; i
++)
41 void gramSchmidt (int Q
[][COLS
], const int rows
, const int cols
)
45 #pragma omp target data map(Q[0:rows][0:cols]) map(to:COLS)
46 for (k
= 0; k
< cols
; k
++)
50 #pragma omp target map(tofrom:tmp)
51 #pragma omp parallel for reduction(+:tmp)
52 for (i
= 0; i
< rows
; i
++)
53 tmp
+= (Q
[i
][k
] * Q
[i
][k
]);
56 #pragma omp parallel for
57 for (i
= 0; i
< rows
; i
++)
64 int (*Q1
)[COLS
] = (int(*)[COLS
]) malloc (ROWS
* COLS
* sizeof (int));
65 int (*Q2
)[COLS
] = (int(*)[COLS
]) malloc (ROWS
* COLS
* sizeof (int));
67 init (Q1
, ROWS
, COLS
);
68 init (Q2
, ROWS
, COLS
);
70 gramSchmidt_ref (Q1
, ROWS
, COLS
);
71 gramSchmidt (Q2
, ROWS
, COLS
);
73 check (Q1
, Q2
, ROWS
, COLS
);