|
| 1 | +// RUN: %libomptarget-compilexx-generic && %libomptarget-run-generic |
| 2 | +// RUN: %libomptarget-compilexx-generic -O3 && %libomptarget-run-generic |
| 3 | +// RUN: %libomptarget-compilexx-generic -O3 -ffast-math && \ |
| 4 | +// RUN: %libomptarget-run-generic |
| 5 | + |
| 6 | +#include <cassert> |
| 7 | +#include <complex> |
| 8 | +#include <iostream> |
| 9 | + |
| 10 | +template <typename T> void test_map() { |
| 11 | + std::complex<T> a(0.2, 1), a_check; |
| 12 | +#pragma omp target map(from : a_check) |
| 13 | + { a_check = a; } |
| 14 | + |
| 15 | + assert(std::abs(a - a_check) < 1e-6); |
| 16 | +} |
| 17 | + |
| 18 | +template <typename RT, typename AT, typename BT> void test_plus(AT a, BT b) { |
| 19 | + std::complex<RT> c, c_host; |
| 20 | + |
| 21 | + c_host = a + b; |
| 22 | +#pragma omp target map(from : c) |
| 23 | + { c = a + b; } |
| 24 | + |
| 25 | + assert(std::abs(c - c_host) < 1e-6); |
| 26 | +} |
| 27 | + |
| 28 | +template <typename RT, typename AT, typename BT> void test_minus(AT a, BT b) { |
| 29 | + std::complex<RT> c, c_host; |
| 30 | + |
| 31 | + c_host = a - b; |
| 32 | +#pragma omp target map(from : c) |
| 33 | + { c = a - b; } |
| 34 | + |
| 35 | + assert(std::abs(c - c_host) < 1e-6); |
| 36 | +} |
| 37 | + |
| 38 | +template <typename RT, typename AT, typename BT> void test_mul(AT a, BT b) { |
| 39 | + std::complex<RT> c, c_host; |
| 40 | + |
| 41 | + c_host = a * b; |
| 42 | +#pragma omp target map(from : c) |
| 43 | + { c = a * b; } |
| 44 | + |
| 45 | + assert(std::abs(c - c_host) < 1e-6); |
| 46 | +} |
| 47 | + |
| 48 | +template <typename RT, typename AT, typename BT> void test_div(AT a, BT b) { |
| 49 | + std::complex<RT> c, c_host; |
| 50 | + |
| 51 | + c_host = a / b; |
| 52 | +#pragma omp target map(from : c) |
| 53 | + { c = a / b; } |
| 54 | + |
| 55 | + assert(std::abs(c - c_host) < 1e-6); |
| 56 | +} |
| 57 | + |
| 58 | +template <typename T> void test_complex() { |
| 59 | + test_map<T>(); |
| 60 | + |
| 61 | + test_plus<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3)); |
| 62 | + test_plus<T>(std::complex<T>(0, 1), T(0.5)); |
| 63 | + test_plus<T>(T(0.5), std::complex<T>(0, 1)); |
| 64 | + |
| 65 | + test_minus<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3)); |
| 66 | + test_minus<T>(std::complex<T>(0, 1), T(0.5)); |
| 67 | + test_minus<T>(T(0.5), std::complex<T>(0, 1)); |
| 68 | + |
| 69 | + test_mul<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3)); |
| 70 | + test_mul<T>(std::complex<T>(0, 1), T(0.5)); |
| 71 | + test_mul<T>(T(0.5), std::complex<T>(0, 1)); |
| 72 | + |
| 73 | + test_div<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3)); |
| 74 | + test_div<T>(std::complex<T>(0, 1), T(0.5)); |
| 75 | + test_div<T>(T(0.5), std::complex<T>(0, 1)); |
| 76 | +} |
| 77 | + |
| 78 | +int main() { |
| 79 | + std::cout << "Testing float" << std::endl; |
| 80 | + test_complex<float>(); |
| 81 | + std::cout << "Testing double" << std::endl; |
| 82 | + test_complex<double>(); |
| 83 | + return 0; |
| 84 | +} |
0 commit comments