22#include "communication.hpp"
29#include <boost/mpi/communicator.hpp>
32#include <heffte_backends.h>
36#include <initializer_list>
39#if defined(__CUDACC__)
46template <
typename FloatType, Arch Architecture,
class FFTConfig>
class P3MFFT {
48 using OutputType =
typename heffte::fft_output<FloatType>::type;
51 heffte::backend::cufft>;
52 template <
class T = OutputType>
57 std::conditional_t<FFTConfig::use_r2c, heffte::fft3d_r2c<backend>,
58 heffte::fft3d<backend>>;
59 using Box = heffte::box3d<>;
61 heffte::backend::device_instance<heffte::tag::gpu>::stream_type;
64 std::unique_ptr<Box> in_box;
66 std::unique_ptr<Box> out_box;
70 std::unique_ptr<FFT3D> fft3d;
71 std::shared_ptr<boost::mpi::environment> m_mpi_env_lock;
73 template <
typename T, std::
size_t N>
75 std::array<T, N>
res{};
76 std::ranges::copy(
vec,
res.begin());
83 m_mpi_env_lock.reset();
107 for (
auto i : {0
u, 1u, 2u}) {
115 out_box = std::make_unique<Box>(
out_boxes[comm.rank()]);
117 in_box = std::make_unique<Box>(
123 heffte::plan_options
options = heffte::default_options<backend>();
135 options.algorithm = heffte::reshape_algorithm::p2p_plined;
142#if defined(__CUDACC__)
157 if constexpr (FFTConfig::use_r2c) {
158 fft3d = std::make_unique<FFT3D>(
gpu_stream, *in_box, *out_box,
159 FFTConfig::r2c_dir, comm,
options);
164 m_workspace =
decltype(m_workspace)(fft3d->size_workspace());
183 fft3d->forward(
in,
out, m_workspace.data());
186 fft3d->backward(
in,
out, m_workspace.data());
Vector implementation and trait types for boost qvm interoperability.
void backward(auto &&in, auto &&out)
Utils::Vector3i ks_local_size() const
void forward(auto &&in, auto &&out)
Utils::Vector3i ks_local_ur_index() const
Utils::Vector3i rs_local_size() const
typename heffte::fft_output< FloatType >::type OutputType
heffte::fft3d< backend >::template buffer_container< T > buffer_container
P3MFFT(stream_type gpu_stream, boost::mpi::communicator comm, Utils::Vector3i const &global_mesh, Utils::Vector3i const &rs_local_ld_index, Utils::Vector3i const &rs_local_ur_index, Utils::Vector3i const &node_grid)
std::conditional_t< Architecture==Arch::CPU, heffte::backend::fftw, heffte::backend::cufft > backend
Utils::Vector3i ks_local_ld_index() const
static DEVICE_QUALIFIER constexpr Vector< T, N > broadcast(typename Base::value_type const &value) noexcept
Create a vector that has all entries set to the same value.
static std::shared_ptr< scoped_pause > make_shared_pause_scoped()
Generate a shared handle to temporarily disable any currently active exception trap for the lifetime ...
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
std::unique_ptr< CommunicationEnvironment > communication_environment
T product(Vector< T, N > const &v)