18 const std::string FFT_xyz_3dim::class_name =
"FFT_xyz_3dim";
21 void FFT_xyz_3dim::init()
29 int threads_ok = fftw_init_threads();
38 if ((NPE_x * NPE_y * NPE_t) != 1) {
39 vout.
crucial(m_vl,
"%s: FFTW supports parallelization only in z-direction.\n",
53 ptrdiff_t fftw_size_p = fftw_mpi_local_size_3d(Lz_p, Ly_p, Lx_p,
55 &m_Nz_p, &m_z_start_p);
57 m_in = fftw_alloc_complex(fftw_size_p);
58 m_out = fftw_alloc_complex(fftw_size_p);
60 if (!m_in || !m_out) {
61 vout.
crucial(m_vl,
"%s: failed to allocate memory %d [Byte].\n",
62 class_name.c_str(), (int)fftw_size_p);
67 const size_t fftw_size =
sizeof(fftw_complex) * Lx * Ly * Lz;
68 m_in = (fftw_complex *)fftw_malloc(fftw_size);
69 m_out = (fftw_complex *)fftw_malloc(fftw_size);
71 if (!m_in || !m_out) {
72 vout.
crucial(m_vl,
"%s: failed to allocate memory %d [Byte].\n",
73 class_name.c_str(), (int)fftw_size);
81 void FFT_xyz_3dim::tidy_up()
83 if (m_in) fftw_free(m_in);
84 if (m_out) fftw_free(m_out);
85 if (m_plan) fftw_destroy_plan(m_plan);
90 void FFT_xyz_3dim::FFT(
Field& field,
const bool is_forward)
101 const int Nin = field.
nin();
102 const int Nex = field.
nex();
108 fftw_plan_with_nthreads(Nthread);
116 m_plan = fftw_mpi_plan_dft_3d(Lz_p, Ly_p, Lx_p, m_in, m_out,
118 FFTW_FORWARD, FFTW_ESTIMATE);
120 m_plan = fftw_mpi_plan_dft_3d(Lz_p, Ly_p, Lx_p, m_in, m_out,
122 FFTW_BACKWARD, FFTW_ESTIMATE);
126 m_plan = fftw_plan_dft_3d(Lz, Ly, Lx, m_in, m_out,
127 FFTW_FORWARD, FFTW_ESTIMATE);
129 m_plan = fftw_plan_dft_3d(Lz, Ly, Lx, m_in, m_out,
130 FFTW_BACKWARD, FFTW_ESTIMATE);
137 for (
int in2 = 0; in2 < Nin / 2; ++in2) {
138 for (
int t_global = 0; t_global < Lt; t_global++) {
139 for (
int ex = 0; ex < Nex; ++ex) {
141 for (
int z = 0; z < Nz; z++) {
142 for (
int y_global = 0; y_global < Ly; y_global++) {
143 for (
int x_global = 0; x_global < Lx; x_global++) {
144 int isite_xyz_local = x_global + Lx * (y_global + Ly * z);
146 int isite = m_index.site(x_global, y_global, z, t_global);
147 int i_real = 2 * in2;
148 int i_imag = 2 * in2 + 1;
150 m_in[isite_xyz_local][0] = field.
cmp(i_real, isite, ex);
151 m_in[isite_xyz_local][1] = field.
cmp(i_imag, isite, ex);
157 fftw_execute(m_plan);
161 for (
int z = 0; z < Nz; z++) {
162 for (
int y_global = 0; y_global < Ly; y_global++) {
163 for (
int x_global = 0; x_global < Lx; x_global++) {
164 int isite_xyz_local = x_global + Lx * (y_global + Ly * z);
166 int isite = m_index.site(x_global, y_global, z, t_global);
167 int i_real = 2 * in2;
168 int i_imag = 2 * in2 + 1;
170 field.
set(i_real, isite, ex, m_out[isite_xyz_local][0]);
171 field.
set(i_imag, isite, ex, m_out[isite_xyz_local][1]);
183 void FFT_xyz_3dim::FFT(
Field& field_out,
const Field& field_in,
const bool is_forward)
194 const int Nin = field_in.
nin();
195 const int Nex = field_in.
nex();
201 fftw_plan_with_nthreads(Nthread);
209 m_plan = fftw_mpi_plan_dft_3d(Lz_p, Ly_p, Lx_p, m_in, m_out,
211 FFTW_FORWARD, FFTW_ESTIMATE);
213 m_plan = fftw_mpi_plan_dft_3d(Lz_p, Ly_p, Lx_p, m_in, m_out,
215 FFTW_BACKWARD, FFTW_ESTIMATE);
219 m_plan = fftw_plan_dft_3d(Lz, Ly, Lx, m_in, m_out,
220 FFTW_FORWARD, FFTW_ESTIMATE);
222 m_plan = fftw_plan_dft_3d(Lz, Ly, Lx, m_in, m_out,
223 FFTW_BACKWARD, FFTW_ESTIMATE);
230 for (
int in2 = 0; in2 < Nin / 2; ++in2) {
231 for (
int t_global = 0; t_global < Lt; t_global++) {
232 for (
int ex = 0; ex < Nex; ++ex) {
234 for (
int z = 0; z < Nz; z++) {
235 for (
int y_global = 0; y_global < Ly; y_global++) {
236 for (
int x_global = 0; x_global < Lx; x_global++) {
237 int isite_xyz_local = x_global + Lx * (y_global + Ly * z);
239 int isite = m_index.site(x_global, y_global, z, t_global);
240 int i_real = 2 * in2;
241 int i_imag = 2 * in2 + 1;
243 m_in[isite_xyz_local][0] = field_in.
cmp(i_real, isite, ex);
244 m_in[isite_xyz_local][1] = field_in.
cmp(i_imag, isite, ex);
250 fftw_execute(m_plan);
254 for (
int z = 0; z < Nz; z++) {
255 for (
int y_global = 0; y_global < Ly; y_global++) {
256 for (
int x_global = 0; x_global < Lx; x_global++) {
257 int isite_xyz_local = x_global + Lx * (y_global + Ly * z);
259 int isite = m_index.site(x_global, y_global, z, t_global);
260 int i_real = 2 * in2;
261 int i_imag = 2 * in2 + 1;
263 field_out.
set(i_real, isite, ex, m_out[isite_xyz_local][0]);
264 field_out.
set(i_imag, isite, ex, m_out[isite_xyz_local][1]);
static int get_num_threads()
returns available number of threads.
void set(const int jin, const int site, const int jex, double v)
Container of Field-type object.
double cmp(const int jin, const int site, const int jex) const
void crucial(const char *format,...)