QMCPACK
test_user_defined_reduction_complex.cpp
Go to the documentation of this file.
1 #include <vector>
2 #include <complex>
3 #include <cassert>
4 
5 #if !defined(OPENMP_NO_UDR)
6 #pragma omp declare reduction(+: std::complex<float>: omp_out += omp_in)
7 #endif
8 
9 int main()
10 {
11  const int N = 100;
12  std::vector<std::complex<float>> array(N);
13 
14  auto array_ptr = array.data();
15  for (int i = 0; i < N; i++)
16  array_ptr[i] = std::complex<float>(i);
17 
18  std::complex<float> sum;
19  #pragma omp parallel for reduction(+: sum)
20  for (int i = 0; i < N; i++)
21  sum += array_ptr[i];
22 
23  assert(std::real(sum) == 4950);
24  assert(std::imag(sum) == 0);
25 }
QMCTraits::RealType real
float imag(const float &c)
imaginary part of a scalar. Cannot be replaced by std::imag due to AFQMC specific needs...