DiFfRG
Loading...
Searching...
No Matches
integrator_4D_openAcc.hh
Go to the documentation of this file.
1#pragma once
2
3// standard library
4#include <future>
5
6// external libraries
7#include <openacc.h>
8#include <tbb/tbb.h>
9
10// DiFfRG
12
13namespace DiFfRG
14{
15 template <typename NT, typename KERNEL> class Integrator4DOACC
16 {
17 public:
21 using ctype = typename get_type::ctype<NT>;
22
23 Integrator4DOACC(QuadratureProvider &quadrature_provider, const std::array<uint, 4> grid_sizes,
24 const ctype x_extent, const JSONValue &)
25 : Integrator4DOACC(quadrature_provider, grid_sizes, x_extent)
26 {
27 }
28
29 Integrator4DOACC(QuadratureProvider &quadrature_provider, std::array<uint, 4> grid_sizes, const ctype x_extent,
30 const uint max_block_size = 0)
32 x_quadrature_p(quadrature_provider.get_points<ctype>(grid_sizes[0])),
33 x_quadrature_w(quadrature_provider.get_weights<ctype>(grid_sizes[0])),
34 ang_quadrature_p1(quadrature_provider.get_points<ctype>(grid_sizes[1])),
35 ang_quadrature_w1(quadrature_provider.get_weights<ctype>(grid_sizes[1])),
36 ang_quadrature_p2(quadrature_provider.get_points<ctype>(grid_sizes[2])),
37 ang_quadrature_w2(quadrature_provider.get_weights<ctype>(grid_sizes[2])),
38 ang_quadrature_p3(quadrature_provider.get_points<ctype>(grid_sizes[3])),
39 ang_quadrature_w3(quadrature_provider.get_weights<ctype>(grid_sizes[3]))
40 {
41 (void)max_block_size;
42 }
43
54 template <typename... T> NT get(const ctype k, const T &...t) const
55 {
56 using std::sqrt;
57
58 const auto constant = KERNEL::constant(k, t...);
59
60 NT value = 0.;
61#pragma acc parallel loop reduction(+ : value)
62 for (uint idx_x = 0; idx_x < grid_sizes[0]; ++idx_x) {
63 const ctype q = k * sqrt(x_quadrature_p[idx_x] * x_extent);
64
65#pragma acc loop reduction(+ : value)
66 for (uint idx_y = 0; idx_y < grid_sizes[1]; ++idx_y) {
67 const ctype cos1 = 2 * (ang_quadrature_p1[idx_y] - (ctype)0.5);
68 const ctype int_element = (powr<2>(q) * (ctype)0.5 * powr<2>(k)) // x = p^2 / k^2 integral
69 * sqrt(1. - powr<2>(cos1)) // cos1 integral jacobian
70 / powr<4>(2 * (ctype)M_PI); // fourier factor
71
72#pragma acc loop reduction(+ : value)
73 for (uint cos2_idx = 0; cos2_idx < grid_sizes[2]; ++cos2_idx) {
74 const ctype cos2 = 2 * (ang_quadrature_p2[cos2_idx] - (ctype)0.5);
75
76 for (uint phi_idx = 0; phi_idx < grid_sizes[3]; ++phi_idx) {
77 const ctype phi = 2 * (ctype)M_PI * ang_quadrature_p3[phi_idx];
78
79 const ctype weight = 2 * (ctype)M_PI * ang_quadrature_w3[phi_idx] // phi weight
80 * 2 * ang_quadrature_w2[cos2_idx] // cos2 weight
81 * 2 * ang_quadrature_w1[idx_y] // cos1 weight
82 * x_quadrature_w[idx_x] * x_extent; // x weight
83
84 value += int_element * weight * KERNEL::kernel(q, cos1, cos2, phi, k, t...);
85 }
86 }
87 }
88 }
89 return constant + value;
90 }
91
102 template <typename... T> std::future<NT> request(const ctype k, const T &...t) const
103 {
104 return std::async(std::launch::deferred, [=, this]() { return get(k, t...); });
105 }
106
107 private:
108 const std::array<uint, 4> grid_sizes;
109
111
112 const std::vector<ctype> &x_quadrature_p;
113 const std::vector<ctype> &x_quadrature_w;
114 const std::vector<ctype> &ang_quadrature_p1;
115 const std::vector<ctype> &ang_quadrature_w1;
116 const std::vector<ctype> &ang_quadrature_p2;
117 const std::vector<ctype> &ang_quadrature_w2;
118 const std::vector<ctype> &ang_quadrature_p3;
119 const std::vector<ctype> &ang_quadrature_w3;
120 };
121} // namespace DiFfRG
Definition integrator_4D_openAcc.hh:16
std::future< NT > request(const ctype k, const T &...t) const
Request a future for the integral of the kernel.
Definition integrator_4D_openAcc.hh:102
typename get_type::ctype< NT > ctype
Numerical type to be used for integration tasks e.g. the argument or possible jacobians.
Definition integrator_4D_openAcc.hh:21
const std::vector< ctype > & ang_quadrature_p3
Definition integrator_4D_openAcc.hh:118
const std::vector< ctype > & ang_quadrature_w2
Definition integrator_4D_openAcc.hh:117
const std::vector< ctype > & ang_quadrature_p2
Definition integrator_4D_openAcc.hh:116
Integrator4DOACC(QuadratureProvider &quadrature_provider, const std::array< uint, 4 > grid_sizes, const ctype x_extent, const JSONValue &)
Definition integrator_4D_openAcc.hh:23
const std::vector< ctype > & ang_quadrature_w3
Definition integrator_4D_openAcc.hh:119
const std::vector< ctype > & x_quadrature_p
Definition integrator_4D_openAcc.hh:112
const std::vector< ctype > & x_quadrature_w
Definition integrator_4D_openAcc.hh:113
const std::vector< ctype > & ang_quadrature_w1
Definition integrator_4D_openAcc.hh:115
const std::vector< ctype > & ang_quadrature_p1
Definition integrator_4D_openAcc.hh:114
const std::array< uint, 4 > grid_sizes
Definition integrator_4D_openAcc.hh:108
Integrator4DOACC(QuadratureProvider &quadrature_provider, std::array< uint, 4 > grid_sizes, const ctype x_extent, const uint max_block_size=0)
Definition integrator_4D_openAcc.hh:29
const ctype x_extent
Definition integrator_4D_openAcc.hh:110
NT get(const ctype k, const T &...t) const
Get the integral of the kernel.
Definition integrator_4D_openAcc.hh:54
A wrapper around the boost json value class.
Definition json.hh:19
A class that provides quadrature points and weights, in host and device memory. The quadrature points...
Definition quadrature_provider.hh:139
typename internal::_ctype< CT >::value ctype
Definition types.hh:106
Definition complex_math.hh:14
constexpr __forceinline__ __host__ __device__ NumberType powr(const NumberType x)
A compile-time evaluatable power function for whole number exponents.
Definition math.hh:45
unsigned int uint
Definition utils.hh:22