Bridge++  Ver. 2.0.2
fft_3d_parallel3d.h
Go to the documentation of this file.
1 
13 #ifndef FFT_3D_PARALLEL3D_INCLUDED
14 #define FFT_3D_PARALLEL3D_INCLUDED
15 
16 // requires FFTW library
17 #ifdef USE_FFTWLIB
18 
19 // requires MPI
20 #ifdef USE_MPI
21 
22 #include <fftw3.h>
23 
24 #include "fft.h"
25 #include "Parameters/parameters.h"
27 
28 class FFT_3d_parallel3d : public FFT
29 {
30  public:
31  static const std::string class_name;
32 
33  public:
34  FFT_3d_parallel3d();
35  FFT_3d_parallel3d(const Parameters& params);
36  virtual ~FFT_3d_parallel3d();
37 
38  void fft(Field& dst, const Field& src, enum Direction dir);
39  void fft(Field& dst, const Field& src);
40  void fft(Field& field);
41 
42  void set_parameters(const Parameters& params);
43  void set_parameters(const std::string& direction);
44 
45  void get_parameters(Parameters& params) const;
46 
47  private:
48 
49  bool check_ok();
50 
51  void initialize();
52  void finalize();
53 
54  bool need_create_plan(const Field&);
55 
56  void create_plan(int site_dof);
57  void release_plan();
58 
59  void create_mpi_datatype(int site_dof);
60  void release_mpi_datatype();
61 
62  void create_fft_plan(int site_dof);
63  void release_fft_plan();
64 
65  // utility functions
66  std::vector<int> grid_rank_to_coord(int r);
67  int find_global_index(const std::vector<int>& coord);
68 
70 
71  int m_site_dof;
72 
73  // {x,y,z} subcommunicator
74  MPI_Comm m_comm;
75 
76  int m_local_rank;
77  int m_local_ipe_x;
78  int m_local_ipe_y;
79  int m_local_ipe_z;
80 
81  // geometry and grid info of xyz-plane
82  int m_ndims;
83 
84  std::vector<int> m_grid_size;
85  int m_grid_vol;
86 
87  std::vector<int> m_lattice_size;
88  int m_lattice_vol;
89 
90  std::vector<int> m_local_size;
91  int m_local_vol;
92 
93  // datatypes for gather/scatter
94  MPI_Datatype m_site_vector_type;
95  MPI_Datatype m_local_patch_type;
96  MPI_Datatype m_subarray_type;
97 
98  std::vector<int> m_sendcounts;
99  std::vector<int> m_subarray_displs;
100  std::vector<int> m_local_patch_displs;
101 
102  // fft workspace. do fft on-the-fly.
103  fftw_complex *m_buf;
104 
105  fftw_plan m_plan_fw;
106  fftw_plan m_plan_bw;
107 
108  bool m_initialized;
109 
110  // for compatibility with FFT_xyz classes
111  Direction m_direction;
112 
113 
114 #ifdef USE_FACTORY
115  private:
116  static FFT *create_object()
117  {
118  return new FFT_3d_parallel3d();
119  }
120 
121  static FFT *create_object_with_params(const Parameters& params)
122  {
123  return new FFT_3d_parallel3d(params);
124  }
125 
126  public:
127  static bool register_factory()
128  {
129  bool init = true;
130  init &= FFT::Factory::Register("FFT_3d_parallel_3dim", create_object);
131  init &= FFT::Factory_params::Register("FFT_3d_parallel_3dim", create_object_with_params);
132  return init;
133  }
134 #endif
135 };
136 
137 #endif /* USE_MPI */
138 #endif /* USE_FFTWLIB */
139 
140 #endif /* FFT_3D_PARALLEL3D_INCLUDED */
Parameters
Class for parameters.
Definition: parameters.h:46
Direction
Direction
Definition: bridge_defs.h:24
communicator_mpi.h
parameters.h
fft.h
Field
Container of Field-type object.
Definition: field.h:46
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.h:42