1 // RUN: %libomptarget-compilexx-generic -O3 && %libomptarget-run-generic
2 // RUN: %libomptarget-compilexx-generic -O3 -ffast-math && %libomptarget-run-generic
9 template <typename T
> void test_map() {
10 std::cout
<< "map(complex<T>)" << std::endl
;
11 std::complex<T
> a(0.2, 1), a_check
;
12 #pragma omp target map(from : a_check)
15 if (std::abs(a
- a_check
) > 1e-6) {
16 std::cout
<< "wrong map value check" << a_check
<< " correct value " << a
22 #if !defined(__NO_UDR)
23 #pragma omp declare reduction(+ : std::complex <float> : omp_out += omp_in)
24 #pragma omp declare reduction(+ : std::complex <double> : omp_out += omp_in)
27 template <typename T
> class initiator
{
29 static T
value(int i
) { return T(i
); }
32 template <typename T
> class initiator
<std::complex<T
>> {
34 static std::complex<T
> value(int i
) { return {T(i
), T(-i
)}; }
37 template <typename T
> void test_reduction() {
38 T
sum(0), sum_host(0);
41 for (int i
= 0; i
< size
; i
++) {
42 array
[i
] = initiator
<T
>::value(i
);
46 #pragma omp target teams distribute parallel for map(to : array[:size]) reduction(+ : sum)
47 for (int i
= 0; i
< size
; i
++)
50 if (std::abs(sum
- sum_host
) > 1e-6) {
51 std::cout
<< "wrong reduction value check" << sum
<< " correct value "
52 << sum_host
<< std::endl
;
56 const int nblock(10), block_size(10);
58 #pragma omp target teams distribute map(to \
62 for (int ib
= 0; ib
< nblock
; ib
++) {
64 const int istart
= ib
* block_size
;
65 const int iend
= (ib
+ 1) * block_size
;
66 #pragma omp parallel for reduction(+ : partial_sum)
67 for (int i
= istart
; i
< iend
; i
++)
68 partial_sum
+= array
[i
];
69 block_sum
[ib
] = partial_sum
;
73 for (int ib
= 0; ib
< nblock
; ib
++)
75 if (std::abs(sum
- sum_host
) > 1e-6) {
76 std::cout
<< "hierarchical parallelism wrong reduction value check" << sum
77 << " correct value " << sum_host
<< std::endl
;
82 template <typename T
> void test_complex() {
84 test_reduction
<std::complex<T
>>();
88 std::cout
<< "Testing complex" << std::endl
;
89 std::cout
<< "Testing float" << std::endl
;
90 test_complex
<float>();
91 std::cout
<< "Testing double" << std::endl
;
92 test_complex
<double>();