1 // RUN: %libomptarget-compilexx-generic -O3 && %libomptarget-run-generic
2 // RUN: %libomptarget-compilexx-generic -O3 -ffast-math && %libomptarget-run-generic
3 // RUN: %libomptarget-compileoptxx-generic -O3 && %libomptarget-run-generic
4 // RUN: %libomptarget-compileoptxx-generic -O3 -ffast-math && %libomptarget-run-generic
8 template <typename T
> int test_map() {
9 std::cout
<< "map(T)" << std::endl
;
11 #pragma omp target map(from : a_check)
15 std::cout
<< " wrong results";
22 template <typename T
> int test_reduction() {
23 std::cout
<< "flat parallelism" << std::endl
;
24 T
sum(0), sum_host(0);
27 for (int i
= 0; i
< size
; i
++) {
32 #pragma omp target teams distribute parallel for map(to : array[ : size]) \
34 for (int i
= 0; i
< size
; i
++)
38 std::cout
<< " wrong results " << sum
<< " host " << sum_host
<< std::endl
;
40 std::cout
<< "hierarchical parallelism" << std::endl
;
41 const int nblock(10), block_size(10);
43 #pragma omp target teams distribute map(to : array[ : size]) \
44 map(from : block_sum[ : nblock])
45 for (int ib
= 0; ib
< nblock
; ib
++) {
47 const int istart
= ib
* block_size
;
48 const int iend
= (ib
+ 1) * block_size
;
49 #pragma omp parallel for reduction(+ : partial_sum)
50 for (int i
= istart
; i
< iend
; i
++)
51 partial_sum
+= array
[i
];
52 block_sum
[ib
] = partial_sum
;
56 for (int ib
= 0; ib
< nblock
; ib
++) {
60 if (sum
!= sum_host
) {
61 std::cout
<< " wrong results " << sum
<< " host " << sum_host
<< std::endl
;
68 template <typename T
> int test_POD() {
71 ret
|= test_reduction
<T
>();
77 std::cout
<< "Testing float" << std::endl
;
78 ret
|= test_POD
<float>();
79 std::cout
<< "Testing double" << std::endl
;
80 ret
|= test_POD
<double>();