ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
fft.hpp File Reference

Routines, row decomposition, data structures and communication for the 3D-FFT. More...

#include "config/config.hpp"
#include <utils/Vector.hpp>
#include <boost/mpi/communicator.hpp>
#include <fftw3.h>
#include <cstddef>
#include <new>
#include <vector>
+ Include dependency graph for fft.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  fft_allocator< T >
 Aligned allocator for fft data. More...
 
struct  fft_forw_plan
 Structure for performing a 1D FFT. More...
 
struct  fft_back_plan
 Additional information for backwards FFT. More...
 
struct  fft_data_struct
 Information about the three one dimensional FFTs and how the nodes have to communicate inbetween. More...
 

Typedefs

template<class T >
using fft_vector = std::vector< T, fft_allocator< T > >
 

Functions

int fft_init (Utils::Vector3i const &ca_mesh_dim, int const *ca_mesh_margin, Utils::Vector3i const &global_mesh_dim, Utils::Vector3d const &global_mesh_off, int &ks_pnum, fft_data_struct &fft, Utils::Vector3i const &grid, boost::mpi::communicator const &comm)
 Initialize everything connected to the 3D-FFT.
 
void fft_perform_forw (double *data, fft_data_struct &fft, const boost::mpi::communicator &comm)
 Perform an in-place forward 3D FFT.
 
void fft_perform_back (double *data, bool check_complex, fft_data_struct &fft, const boost::mpi::communicator &comm)
 Perform an in-place backward 3D FFT.
 
void fft_pack_block (double const *in, double *out, int const start[3], int const size[3], int const dim[3], int element)
 Pack a block (size[3] starting at start[3]) of an input 3d-grid with dimension dim[3] into an output 3d-block with dimension size[3].
 
void fft_unpack_block (double const *in, double *out, int const start[3], int const size[3], int const dim[3], int element)
 Unpack a 3d-grid input block (size[3]) into an output 3d-grid with dimension dim[3] at start position start[3].
 

Detailed Description

Routines, row decomposition, data structures and communication for the 3D-FFT.

The 3D-FFT is split into 3 ond dimensional FFTs. The data is distributed in such a way, that for the actual direction of the FFT each node has a certain number of rows for which it performs a 1D-FFT. After performing the FFT on that direction the data is redistributed.

For simplicity at the moment I have implemented a full complex to complex FFT (even though a real to complex FFT would be sufficient)

Todo:

Combine the forward and backward structures.

The packing routines could be moved to utils.hpp when they are needed elsewhere.

For more information about FFT usage, see fft.cpp.

Definition in file fft.hpp.

Typedef Documentation

◆ fft_vector

template<class T >
using fft_vector = std::vector<T, fft_allocator<T> >

Definition at line 87 of file fft.hpp.

Function Documentation

◆ fft_init()

int fft_init ( Utils::Vector3i const &  ca_mesh_dim,
int const *  ca_mesh_margin,
Utils::Vector3i const &  global_mesh_dim,
Utils::Vector3d const &  global_mesh_off,
int &  ks_pnum,
fft_data_struct fft,
Utils::Vector3i const &  grid,
boost::mpi::communicator const &  comm 
)

Initialize everything connected to the 3D-FFT.

Parameters
[in]ca_mesh_dimLocal CA mesh dimensions.
[in]ca_mesh_marginLocal CA mesh margins.
[in]global_mesh_dimGlobal CA mesh dimensions.
[in]global_mesh_offGlobal CA mesh offset.
[out]ks_pnumNumber of permutations in k-space.
[out]fftFFT plan.
[in]gridNumber of nodes in each spatial dimension.
[in]commMPI communicator.
Returns
Maximal size of local fft mesh (needed for allocation of ca_mesh).

Definition at line 483 of file fft.cpp.

References fft_data_struct::back, anonymous_namespace{fft.cpp}::calc_2d_grid(), anonymous_namespace{fft.cpp}::calc_local_mesh(), anonymous_namespace{fft.cpp}::calc_send_block(), Utils::Array< T, N >::data(), fft_data_struct::data_buf, fft_forw_plan::dir, fft_back_plan::dir, fft_forw_plan::element, fft_pack_block(), anonymous_namespace{fft.cpp}::find_comm_groups(), fft_forw_plan::group, fft_data_struct::init_tag, Utils::make_span(), anonymous_namespace{fft.cpp}::map_3don2d_grid(), fft_data_struct::max_comm_size, fft_data_struct::max_mesh_size, fft_forw_plan::n_ffts, fft_forw_plan::n_permute, fft_forw_plan::new_mesh, fft_forw_plan::new_size, node, fft_forw_plan::old_mesh, fft_forw_plan::our_fftw_plan, fft_back_plan::our_fftw_plan, anonymous_namespace{fft.cpp}::pack_block_permute1(), anonymous_namespace{fft.cpp}::pack_block_permute2(), fft_forw_plan::pack_function, fft_back_plan::pack_function, fft_data_struct::plan, Utils::product(), fft_forw_plan::recv_block, fft_data_struct::recv_buf, fft_forw_plan::recv_size, fft_forw_plan::row_dir, fft_forw_plan::send_block, fft_data_struct::send_buf, fft_forw_plan::send_size, and fft_forw_plan::start.

Referenced by CoulombP3M::init(), and DipolarP3M::init().

◆ fft_pack_block()

void fft_pack_block ( double const *  in,
double *  out,
int const  start[3],
int const  size[3],
int const  dim[3],
int  element 
)

Pack a block (size[3] starting at start[3]) of an input 3d-grid with dimension dim[3] into an output 3d-block with dimension size[3].

The block with dimensions (size[0], size[1], size[2]) is stored in 'row-major-order' or 'C-order', that means the first index is changing slowest when running through the linear array. The element (i0 (slow), i1 (mid), i2 (fast)) has the linear index li = i2 + size[2] * (i1 + (size[1] * i0)).

Parameters
[in]inpointer to input 3d-grid.
[out]outpointer to output 3d-grid (block).
[in]startstart index of the block in the in-grid.
[in]sizesize of the block (=dimension of the out-grid).
[in]dimsize of the in-grid.
[in]elementsize of a grid element (e.g. 1 for Real, 2 for Complex).

Definition at line 755 of file fft.cpp.

Referenced by fft_init(), p3m_send_mesh::gather_grid(), and p3m_send_mesh::spread_grid().

◆ fft_perform_back()

void fft_perform_back ( double *  data,
bool  check_complex,
fft_data_struct fft,
const boost::mpi::communicator comm 
)

Perform an in-place backward 3D FFT.

Warning
The content of data is overwritten.
Parameters
[in,out]dataMesh.
[in]check_complexThrow an error if the complex component is non-zero.
[in,out]fftFFT plan.
[in]commMPI communicator.

Definition at line 713 of file fft.cpp.

References fft_data_struct::back, anonymous_namespace{fft.cpp}::back_grid_comm(), fft_data_struct::data_buf, fft_forw_plan::new_size, fft_back_plan::our_fftw_plan, and fft_data_struct::plan.

Referenced by CoulombP3M::long_range_kernel(), and DipolarP3M::long_range_kernel().

◆ fft_perform_forw()

void fft_perform_forw ( double *  data,
fft_data_struct fft,
const boost::mpi::communicator comm 
)

Perform an in-place forward 3D FFT.

Warning
The content of data is overwritten.
Parameters
[in,out]dataMesh.
[in,out]fftFFT plan.
[in]commMPI communicator

Definition at line 682 of file fft.cpp.

References fft_data_struct::data_buf, anonymous_namespace{fft.cpp}::forw_grid_comm(), fft_forw_plan::new_size, fft_forw_plan::our_fftw_plan, and fft_data_struct::plan.

Referenced by CoulombP3M::long_range_kernel(), DipolarP3M::long_range_kernel(), and CoulombP3M::long_range_pressure().

◆ fft_unpack_block()

void fft_unpack_block ( double const *  in,
double *  out,
int const  start[3],
int const  size[3],
int const  dim[3],
int  element 
)

Unpack a 3d-grid input block (size[3]) into an output 3d-grid with dimension dim[3] at start position start[3].

see also fft_pack_block.

Parameters
[in]inpointer to input 3d-grid.
[out]outpointer to output 3d-grid (block).
[in]startstart index of the block in the in-grid.
[in]sizesize of the block (=dimension of the out-grid).
[in]dimsize of the in-grid.
[in]elementsize of a grid element (e.g. 1 for Real, 2 for Complex).

Definition at line 779 of file fft.cpp.

Referenced by anonymous_namespace{fft.cpp}::back_grid_comm(), anonymous_namespace{fft.cpp}::forw_grid_comm(), and p3m_send_mesh::spread_grid().