(git:e70887f)
Loading...
Searching...
No Matches
fft_lib_test.c
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* CP2K: A general program to perform molecular dynamics simulations */
3/* Copyright 2000-2026 CP2K developers group <https://cp2k.org> */
4/* */
5/* SPDX-License-Identifier: BSD-3-Clause */
6/*----------------------------------------------------------------------------*/
7
8#include "fft_lib_test.h"
9#include "fft_utils.h"
10
11#include "../mpiwrap/cp_mpi.h"
12#include "fft_lib.h"
13#include "fft_utils.h"
14
15#include "../base/cp_assert.h"
16#include <math.h>
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20#include <time.h>
21
22/*******************************************************************************
23 * \brief Compute the linear index of a point in a batched 3D grid.
24 * \param fft_size Size of the transform in each dimension.
25 * \param x Index along the first dimension.
26 * \param y Index along the second dimension.
27 * \param z Index along the third dimension.
28 * \param batch Index of the transform batch.
29 * \param number_of_ffts Number of independent (batched) transforms.
30 * \param transpose Whether the array uses the transposed layout.
31 * \return Linear index into the grid buffer.
32 ******************************************************************************/
33static inline int fft3d_index(const int fft_size[3], const int x, const int y,
34 const int z, const int batch,
35 const int number_of_ffts, const bool transpose) {
36 const int spatial = (x * fft_size[1] + y) * fft_size[2] + z;
37 return transpose
38 ? spatial * number_of_ffts + batch
39 : batch * (fft_size[0] * fft_size[1] * fft_size[2]) + spatial;
40}
41
42/*******************************************************************************
43 * \brief Compute the linear index of a point in a batched 3D complex
44 * half-spectrum grid.
45 * \param fft_size Size of the transform in each dimension.
46 * \param x Index along the first dimension.
47 * \param y Index along the second dimension.
48 * \param z Index along the third dimension.
49 * \param batch Index of the transform batch.
50 * \param number_of_ffts Number of independent (batched) transforms.
51 * \param transpose Whether the array uses the transposed layout.
52 * \return Linear index into the grid buffer.
53 ******************************************************************************/
54static inline int fft3d_index_complex(const int fft_size[3], const int x,
55 const int y, const int z, const int batch,
56 const int number_of_ffts,
57 const bool transpose) {
58 const int spatial = (x * fft_size[1] + y) * (fft_size[2] / 2 + 1) + z;
59 return transpose
60 ? spatial * number_of_ffts + batch
61 : batch * (fft_size[0] * fft_size[1] * (fft_size[2] / 2 + 1)) +
62 spatial;
63}
64
65/*******************************************************************************
66 * \brief Compute the linear index of a point in a padded batched 3D grid.
67 * \param fft_size Size of the transform in each dimension.
68 * \param x Index along the first dimension.
69 * \param y Index along the second dimension.
70 * \param z Index along the third dimension.
71 * \param batch Index of the transform batch.
72 * \param number_of_ffts Number of independent (batched) transforms.
73 * \param transpose Whether the array uses the transposed layout.
74 * \return Linear index into the grid buffer.
75 ******************************************************************************/
76static inline int fft3d_index_padded(const int fft_size[3], const int x,
77 const int y, const int z, const int batch,
78 const int number_of_ffts,
79 const bool transpose) {
80 const int spatial = (x * fft_size[1] + y) * 2 * (fft_size[2] / 2 + 1) + z;
81 return transpose
82 ? spatial * number_of_ffts + batch
83 : batch * (2 * fft_size[0] * fft_size[1] * (fft_size[2] / 2 + 1)) +
84 spatial;
85}
86
87/*******************************************************************************
88 * \brief Function to test the local FFT backend.
89 * \param fft_size Size of the transform in each dimension.
90 * \param number_of_ffts Number of independent (batched) transforms.
91 * \param transpose_rs Whether the real-space array uses the transposed layout.
92 * \param transpose_gs Whether the reciprocal-space array uses the transposed
93 * layout.
94 * \author Frederick Stein
95 ******************************************************************************/
96int fft_test_1d_local_low(const int fft_size, const int number_of_ffts,
97 const int transpose_rs, const int transpose_gs) {
98 const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
99
100 int errors = 0;
101
102 const double pi = acos(-1);
103
104 double complex *input_array = NULL, *output_array = NULL;
105 fft_allocate_complex(fft_size * number_of_ffts, &input_array);
106 fft_allocate_complex(fft_size * number_of_ffts, &output_array);
107
108 fft_register_1d_local(true, fft_size, number_of_ffts, transpose_rs,
109 transpose_gs, transpose_rs ? number_of_ffts : fft_size,
110 transpose_gs ? number_of_ffts : fft_size, input_array,
111 output_array);
112 fft_register_1d_local(false, fft_size, number_of_ffts, transpose_gs,
113 transpose_rs, transpose_gs ? number_of_ffts : fft_size,
114 transpose_rs ? number_of_ffts : fft_size, output_array,
115 input_array);
116
117 memset(input_array, 0, fft_size * number_of_ffts * sizeof(double complex));
118
119 // Check the forward FFT
120 if (transpose_rs) {
121#pragma omp parallel for default(none) \
122 shared(input_array, fft_size, number_of_ffts)
123 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
124 number_of_fft++) {
125 input_array[(number_of_fft % fft_size) * number_of_ffts + number_of_fft] =
126 1.0;
127 }
128 } else {
129#pragma omp parallel for default(none) \
130 shared(input_array, fft_size, number_of_ffts)
131 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
132 number_of_fft++) {
133 input_array[(number_of_fft % fft_size) + number_of_fft * fft_size] = 1.0;
134 }
135 }
136
137 fft_1d_local(true, fft_size, number_of_ffts, transpose_rs, transpose_gs,
138 transpose_rs ? number_of_ffts : fft_size,
139 transpose_gs ? number_of_ffts : fft_size, input_array,
140 output_array);
141
142 double max_error = 0.0;
143 if (transpose_gs) {
144#pragma omp parallel for default(none) \
145 shared(output_array, fft_size, number_of_ffts, pi, my_process) \
146 reduction(max : max_error) collapse(2)
147 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
148 number_of_fft++) {
149 for (int index = 0; index < fft_size; index++) {
150 const double complex my_value =
151 output_array[number_of_fft + index * number_of_ffts];
152 const double complex ref_value =
153 cexp(-2.0 * I * pi * (number_of_fft % fft_size) * index / fft_size);
154 const double current_error = cabs(my_value - ref_value);
155 if (my_process == 0 && current_error > 1.0e-4)
156 printf("ERROR %i %i/%i %i: (%f %f) (%f %f)\n", index, number_of_fft,
157 fft_size, number_of_ffts, creal(my_value), cimag(my_value),
158 creal(ref_value), cimag(ref_value));
159 max_error = fmax(max_error, current_error);
160 }
161 }
162 } else {
163#pragma omp parallel for default(none) \
164 shared(output_array, fft_size, number_of_ffts, pi, my_process) \
165 reduction(max : max_error) collapse(2)
166 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
167 number_of_fft++) {
168 for (int index = 0; index < fft_size; index++) {
169 const double complex my_value =
170 output_array[number_of_fft * fft_size + index];
171 const double complex ref_value =
172 cexp(-2.0 * I * pi * (number_of_fft % fft_size) * index / fft_size);
173 const double current_error = cabs(my_value - ref_value);
174 if (my_process == 0 && current_error > 1.0e-4)
175 printf("ERROR %i %i/%i %i: (%f %f) (%f %f)\n", index, number_of_fft,
176 fft_size, number_of_ffts, creal(my_value), cimag(my_value),
177 creal(ref_value), cimag(ref_value));
178 max_error = fmax(max_error, current_error);
179 }
180 }
181 }
182 fflush(stdout);
183
184 if (max_error > 1.0e-4) {
185 if (my_process == 0) {
186 printf("The fw 1D-FFT does not work correctly (%i %i): %f!\n", fft_size,
187 number_of_ffts, max_error);
188 fflush(stdout);
189 }
190 errors++;
191 }
192
193 // Check the backward FFT
194 memset(output_array, 0, fft_size * number_of_ffts * sizeof(double complex));
195
196 if (transpose_gs) {
197#pragma omp parallel for default(none) \
198 shared(output_array, fft_size, number_of_ffts)
199 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
200 number_of_fft++) {
201 output_array[number_of_fft + number_of_fft % fft_size * number_of_ffts] =
202 1.0;
203 }
204 } else {
205#pragma omp parallel for default(none) \
206 shared(output_array, fft_size, number_of_ffts)
207 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
208 number_of_fft++) {
209 output_array[number_of_fft * fft_size + number_of_fft % fft_size] = 1.0;
210 }
211 }
212
213 fft_1d_local(false, fft_size, number_of_ffts, transpose_gs, transpose_rs,
214 transpose_gs ? number_of_ffts : fft_size,
215 transpose_rs ? number_of_ffts : fft_size, output_array,
216 input_array);
217
218 max_error = 0.0;
219 if (transpose_rs) {
220#pragma omp parallel for default(none) \
221 shared(input_array, fft_size, number_of_ffts, pi, my_process) \
222 reduction(max : max_error) collapse(2)
223 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
224 number_of_fft++) {
225 for (int index = 0; index < fft_size; index++) {
226 const double complex my_value =
227 input_array[index * number_of_ffts + number_of_fft];
228 const double complex ref_value =
229 cexp(2.0 * I * pi * (number_of_fft % fft_size) * index / fft_size);
230 const double current_error = cabs(my_value - ref_value);
231 if (my_process == 0 && current_error > 1.0e-12)
232 printf("ERROR %i %i/%i %i: (%f %f) (%f %f)\n", index, number_of_fft,
233 fft_size, number_of_ffts, creal(my_value), cimag(my_value),
234 creal(ref_value), cimag(ref_value));
235 max_error = fmax(max_error, current_error);
236 }
237 }
238 } else {
239#pragma omp parallel for default(none) \
240 shared(input_array, fft_size, number_of_ffts, pi, my_process) \
241 reduction(max : max_error) collapse(2)
242 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
243 number_of_fft++) {
244 for (int index = 0; index < fft_size; index++) {
245 const double complex my_value =
246 input_array[index + number_of_fft * fft_size];
247 const double complex ref_value =
248 cexp(2.0 * I * pi * (number_of_fft % fft_size) * index / fft_size);
249 const double current_error = cabs(my_value - ref_value);
250 if (my_process == 0 && current_error > 1.0e-12)
251 printf("ERROR %i %i/%i %i: (%f %f) (%f %f)\n", index, number_of_fft,
252 fft_size, number_of_ffts, creal(my_value), cimag(my_value),
253 creal(ref_value), cimag(ref_value));
254 max_error = fmax(max_error, current_error);
255 }
256 }
257 }
258 fflush(stdout);
259
260 fft_free_complex(input_array);
261 fft_free_complex(output_array);
262
263 if (max_error > 1e-12) {
264 if (my_process == 0) {
265 printf("The bw 1D FFT does not work correctly (%i %i): %f!\n", fft_size,
266 number_of_ffts, max_error);
267 fflush(stdout);
268 }
269 errors++;
270 }
271
272 if (errors == 0 && my_process == 0)
273 printf("The 1D FFT does work correctly (%i %i)!\n", fft_size,
274 number_of_ffts);
275 return errors;
276}
277
278/*******************************************************************************
279 * \brief Function to test the local FFT backend (inplace).
280 * \param fft_size Size of the transform in each dimension.
281 * \param number_of_ffts Number of independent (batched) transforms.
282 * \param transpose Whether the array uses the transposed layout.
283 * \author Frederick Stein
284 ******************************************************************************/
285int fft_test_1d_local_inplace_low(const int fft_size, const int number_of_ffts,
286 const int transpose) {
287 const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
288
289 int errors = 0;
290
291 const double pi = acos(-1);
292
293 double complex *input_array = NULL;
294 fft_allocate_complex(fft_size * number_of_ffts, &input_array);
295
296 fft_register_1d_local(true, fft_size, number_of_ffts, transpose, transpose,
297 transpose ? number_of_ffts : fft_size,
298 transpose ? number_of_ffts : fft_size, input_array,
299 input_array);
300 fft_register_1d_local(false, fft_size, number_of_ffts, transpose, transpose,
301 transpose ? number_of_ffts : fft_size,
302 transpose ? number_of_ffts : fft_size, input_array,
303 input_array);
304
305 memset(input_array, 0, fft_size * number_of_ffts * sizeof(double complex));
306
307 // Check the forward FFT
308 if (transpose) {
309#pragma omp parallel for default(none) \
310 shared(input_array, fft_size, number_of_ffts)
311 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
312 number_of_fft++) {
313 input_array[(number_of_fft % fft_size) * number_of_ffts + number_of_fft] =
314 1.0;
315 }
316 } else {
317#pragma omp parallel for default(none) \
318 shared(input_array, fft_size, number_of_ffts)
319 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
320 number_of_fft++) {
321 input_array[(number_of_fft % fft_size) + number_of_fft * fft_size] = 1.0;
322 }
323 }
324
325 fft_1d_local(true, fft_size, number_of_ffts, transpose, transpose,
326 transpose ? number_of_ffts : fft_size,
327 transpose ? number_of_ffts : fft_size, input_array, input_array);
328
329 double max_error = 0.0;
330 if (transpose) {
331#pragma omp parallel for default(none) \
332 shared(input_array, fft_size, number_of_ffts, pi, my_process) \
333 reduction(max : max_error) collapse(2)
334 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
335 number_of_fft++) {
336 for (int index = 0; index < fft_size; index++) {
337 const double complex my_value =
338 input_array[number_of_fft + index * number_of_ffts];
339 const double complex ref_value =
340 cexp(-2.0 * I * pi * (number_of_fft % fft_size) * index / fft_size);
341 const double current_error = cabs(my_value - ref_value);
342 if (my_process == 0 && current_error > 1.0e-4)
343 printf("ERROR %i %i/%i %i: (%f %f) (%f %f)\n", index, number_of_fft,
344 fft_size, number_of_ffts, creal(my_value), cimag(my_value),
345 creal(ref_value), cimag(ref_value));
346 max_error = fmax(max_error, current_error);
347 }
348 }
349 } else {
350#pragma omp parallel for default(none) \
351 shared(input_array, fft_size, number_of_ffts, pi, my_process) \
352 reduction(max : max_error) collapse(2)
353 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
354 number_of_fft++) {
355 for (int index = 0; index < fft_size; index++) {
356 const double complex my_value =
357 input_array[number_of_fft * fft_size + index];
358 const double complex ref_value =
359 cexp(-2.0 * I * pi * (number_of_fft % fft_size) * index / fft_size);
360 const double current_error = cabs(my_value - ref_value);
361 if (my_process == 0 && current_error > 1.0e-4)
362 printf("ERROR %i %i/%i %i: (%f %f) (%f %f)\n", index, number_of_fft,
363 fft_size, number_of_ffts, creal(my_value), cimag(my_value),
364 creal(ref_value), cimag(ref_value));
365 max_error = fmax(max_error, current_error);
366 }
367 }
368 }
369 fflush(stdout);
370
371 if (max_error > 1.0e-4) {
372 if (my_process == 0) {
373 printf("The fw 1D-FFT (inplace) does not work correctly (%i %i): %f!\n",
374 fft_size, number_of_ffts, max_error);
375 fflush(stdout);
376 }
377 errors++;
378 }
379
380 // Check the backward FFT
381 memset(input_array, 0, fft_size * number_of_ffts * sizeof(double complex));
382
383 if (transpose) {
384#pragma omp parallel for default(none) \
385 shared(input_array, fft_size, number_of_ffts)
386 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
387 number_of_fft++) {
388 input_array[number_of_fft + number_of_fft % fft_size * number_of_ffts] =
389 1.0;
390 }
391 } else {
392#pragma omp parallel for default(none) \
393 shared(input_array, fft_size, number_of_ffts)
394 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
395 number_of_fft++) {
396 input_array[number_of_fft * fft_size + number_of_fft % fft_size] = 1.0;
397 }
398 }
399
400 fft_1d_local(false, fft_size, number_of_ffts, transpose, transpose,
401 transpose ? number_of_ffts : fft_size,
402 transpose ? number_of_ffts : fft_size, input_array, input_array);
403
404 max_error = 0.0;
405 if (transpose) {
406#pragma omp parallel for default(none) \
407 shared(input_array, fft_size, number_of_ffts, pi, my_process) \
408 reduction(max : max_error) collapse(2)
409 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
410 number_of_fft++) {
411 for (int index = 0; index < fft_size; index++) {
412 const double complex my_value =
413 input_array[index * number_of_ffts + number_of_fft];
414 const double complex ref_value =
415 cexp(2.0 * I * pi * (number_of_fft % fft_size) * index / fft_size);
416 const double current_error = cabs(my_value - ref_value);
417 if (my_process == 0 && current_error > 1.0e-12)
418 printf("ERROR %i %i/%i %i: (%f %f) (%f %f)\n", index, number_of_fft,
419 fft_size, number_of_ffts, creal(my_value), cimag(my_value),
420 creal(ref_value), cimag(ref_value));
421 max_error = fmax(max_error, current_error);
422 }
423 }
424 } else {
425#pragma omp parallel for default(none) \
426 shared(input_array, fft_size, number_of_ffts, pi, my_process) \
427 reduction(max : max_error) collapse(2)
428 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
429 number_of_fft++) {
430 for (int index = 0; index < fft_size; index++) {
431 const double complex my_value =
432 input_array[index + number_of_fft * fft_size];
433 const double complex ref_value =
434 cexp(2.0 * I * pi * (number_of_fft % fft_size) * index / fft_size);
435 const double current_error = cabs(my_value - ref_value);
436 if (my_process == 0 && current_error > 1.0e-12)
437 printf("ERROR %i %i/%i %i: (%f %f) (%f %f)\n", index, number_of_fft,
438 fft_size, number_of_ffts, creal(my_value), cimag(my_value),
439 creal(ref_value), cimag(ref_value));
440 max_error = fmax(max_error, current_error);
441 }
442 }
443 }
444 fflush(stdout);
445
446 fft_free_complex(input_array);
447
448 if (max_error > 1e-12) {
449 if (my_process == 0) {
450 printf("The bw 1D FFT (inplace) does not work correctly (%i %i): %f!\n",
451 fft_size, number_of_ffts, max_error);
452 fflush(stdout);
453 }
454 errors++;
455 }
456
457 if (errors == 0 && my_process == 0)
458 printf("The 1D FFT (inplace) does work correctly (%i %i)!\n", fft_size,
459 number_of_ffts);
460 return errors;
461}
462
463/*******************************************************************************
464 * \brief Function to test the local FFT backend.
465 * \param fft_size Size of the transform in each dimension.
466 * \param number_of_ffts Number of independent (batched) transforms.
467 * \param transpose_rs Whether the real-space array uses the transposed layout.
468 * \param transpose_gs Whether the reciprocal-space array uses the transposed
469 * layout.
470 * \author Frederick Stein
471 ******************************************************************************/
472int fft_test_1d_local_r2c_low(const int fft_size, const int number_of_ffts,
473 const int transpose_rs, const int transpose_gs) {
474 const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
475
476 int errors = 0;
477
478 const double pi = acos(-1);
479
480 double *input_array = NULL;
481 double complex *output_array = NULL;
482 fft_allocate_double(2 * (fft_size / 2 + 1) * number_of_ffts, &input_array);
483 fft_allocate_complex((fft_size / 2 + 1) * number_of_ffts + 4, &output_array);
484
485 fft_register_1d_r2c_local(fft_size, number_of_ffts, transpose_rs,
486 transpose_gs,
487 transpose_rs ? number_of_ffts : fft_size,
488 transpose_gs ? number_of_ffts : fft_size / 2 + 1,
489 input_array, output_array);
491 fft_size, number_of_ffts, transpose_gs, transpose_rs,
492 transpose_gs ? number_of_ffts : fft_size / 2 + 1,
493 transpose_rs ? number_of_ffts : fft_size, output_array, input_array);
494
495 memset(input_array, 0, fft_size * number_of_ffts * sizeof(double));
496 // Check the forward FFT
497 if (transpose_rs) {
498#pragma omp parallel for default(none) \
499 shared(input_array, fft_size, number_of_ffts)
500 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
501 number_of_fft++) {
502 input_array[(number_of_fft % fft_size) * number_of_ffts + number_of_fft] =
503 1.0;
504 }
505 } else {
506#pragma omp parallel for default(none) \
507 shared(input_array, fft_size, number_of_ffts)
508 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
509 number_of_fft++) {
510 input_array[(number_of_fft % fft_size) + number_of_fft * fft_size] = 1.0;
511 }
512 }
513
514 fft_1d_r2c_local(fft_size, number_of_ffts, transpose_rs, transpose_gs,
515 transpose_rs ? number_of_ffts : fft_size,
516 transpose_gs ? number_of_ffts : fft_size / 2 + 1,
517 input_array, output_array);
518
519 double max_error = 0.0;
520 if (transpose_gs) {
521#pragma omp parallel for default(none) \
522 shared(output_array, fft_size, number_of_ffts, pi, my_process) \
523 reduction(max : max_error) collapse(2)
524 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
525 number_of_fft++) {
526 for (int index = 0; index < fft_size / 2 + 1; index++) {
527 const double complex my_value =
528 output_array[number_of_fft + index * number_of_ffts];
529 const double complex ref_value =
530 cexp(-2.0 * I * pi * (number_of_fft % fft_size) * index / fft_size);
531 const double current_error = cabs(my_value - ref_value);
532 if (my_process == 0 && current_error > 1e-12)
533 printf("Error %i %i / %i %i: (%f %f) (%f %f)\n", index, number_of_fft,
534 fft_size, number_of_ffts, creal(my_value), cimag(my_value),
535 creal(ref_value), cimag(ref_value));
536 max_error = fmax(max_error, current_error);
537 }
538 }
539 } else {
540#pragma omp parallel for default(none) \
541 shared(output_array, fft_size, number_of_ffts, pi, my_process) \
542 reduction(max : max_error) collapse(2)
543 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
544 number_of_fft++) {
545 for (int index = 0; index < fft_size / 2 + 1; index++) {
546 const double complex my_value =
547 output_array[number_of_fft * (fft_size / 2 + 1) + index];
548 const double complex ref_value =
549 cexp(-2.0 * I * pi * (number_of_fft % fft_size) * index / fft_size);
550 const double current_error = cabs(my_value - ref_value);
551 if (my_process == 0 && current_error > 1e-12)
552 printf("Error %i %i / %i %i: (%f %f) (%f %f)\n", index, number_of_fft,
553 fft_size, number_of_ffts, creal(my_value), cimag(my_value),
554 creal(ref_value), cimag(ref_value));
555 max_error = fmax(max_error, current_error);
556 }
557 }
558 }
559 fflush(stdout);
560
561 if (max_error > 1.0e-8) {
562 if (my_process == 0) {
563 printf("The fw R2C 1D-FFT does not work correctly (%i %i): %f!\n",
564 fft_size, number_of_ffts, max_error);
565 fflush(stdout);
566 }
567 errors++;
568 }
569
570 // Check the backward FFT
571 memset(output_array, 0,
572 (fft_size / 2 + 1) * number_of_ffts * sizeof(double complex));
573
574 if (transpose_gs) {
575#pragma omp parallel for default(none) collapse(2) \
576 shared(output_array, fft_size, number_of_ffts)
577 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
578 number_of_fft++) {
579 for (int index = 0; index < fft_size / 2 + 1; index++) {
580 output_array[number_of_fft + index * number_of_ffts] =
581 cexp(-2.0 * I * acos(-1) * index * number_of_fft / fft_size);
582 }
583 }
584 } else {
585#pragma omp parallel for default(none) \
586 shared(output_array, fft_size, number_of_ffts)
587 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
588 number_of_fft++) {
589 for (int index = 0; index < fft_size / 2 + 1; index++) {
590 output_array[number_of_fft * (fft_size / 2 + 1) + index] =
591 cexp(-2.0 * I * acos(-1) * index * number_of_fft / fft_size);
592 }
593 }
594 }
595
596 fft_1d_c2r_local(fft_size, number_of_ffts, transpose_gs, transpose_rs,
597 transpose_gs ? number_of_ffts : fft_size / 2 + 1,
598 transpose_rs ? number_of_ffts : fft_size, output_array,
599 input_array);
600
601 max_error = 0.0;
602 if (transpose_rs) {
603#pragma omp parallel for default(none) \
604 shared(input_array, fft_size, number_of_ffts, my_process) \
605 reduction(max : max_error) collapse(2)
606 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
607 number_of_fft++) {
608 for (int index = 0; index < fft_size; index++) {
609 const double my_value =
610 input_array[index * number_of_ffts + number_of_fft];
611 const double ref_value =
612 (number_of_fft % fft_size == index ? (double)fft_size : 0.0);
613 const double current_error = fabs(my_value - ref_value);
614 if (my_process == 0 && current_error > 1e-4)
615 printf("ERROR %i %i / %i %i : %f %f\n", number_of_fft, index,
616 number_of_ffts, fft_size, my_value, ref_value);
617 max_error = fmax(max_error, current_error);
618 }
619 }
620 } else {
621#pragma omp parallel for default(none) \
622 shared(input_array, fft_size, number_of_ffts, my_process) \
623 reduction(max : max_error) collapse(2)
624 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
625 number_of_fft++) {
626 for (int index = 0; index < fft_size; index++) {
627 const double my_value = input_array[index + number_of_fft * fft_size];
628 const double ref_value =
629 (number_of_fft % fft_size == index ? (double)fft_size : 0.0);
630 const double current_error = fabs(my_value - ref_value);
631 if (my_process == 0 && current_error > 1e-4)
632 printf("ERROR %i %i / %i %i : %f %f\n", number_of_fft, index,
633 number_of_ffts, fft_size, my_value, ref_value);
634 max_error = fmax(max_error, current_error);
635 }
636 }
637 }
638 fflush(stdout);
639
640 if (max_error > 1e-8) {
641 if (my_process == 0) {
642 printf("The bw C2R-1D FFT does not work correctly (%i %i): %f!\n",
643 fft_size, number_of_ffts, max_error);
644 fflush(stdout);
645 }
646 errors++;
647 }
648
649 fft_free_double(input_array);
650 fft_free_complex(output_array);
651
652 if (errors == 0 && my_process == 0)
653 printf("The 1D R/C FFT does work correctly (%i %i)!\n", fft_size,
654 number_of_ffts);
655 return errors;
656}
657
658/*******************************************************************************
659 * \brief Function to test the local FFT backend.
660 * \param fft_size Size of the transform in each dimension.
661 * \param number_of_ffts Number of independent (batched) transforms.
662 * \param transpose Whether the array uses the transposed layout.
663 * \author Frederick Stein
664 ******************************************************************************/
666 const int number_of_ffts,
667 const int transpose) {
668 const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
669
670 int errors = 0;
671
672 const double pi = acos(-1);
673
674 double *input_array = NULL;
675 fft_allocate_double(2 * (fft_size / 2 + 1) * number_of_ffts, &input_array);
676 double complex *output_array = (double complex *)input_array;
677
678 fft_register_1d_r2c_local(fft_size, number_of_ffts, transpose, transpose,
679 transpose ? number_of_ffts : 2 * (fft_size / 2 + 1),
680 transpose ? number_of_ffts : fft_size / 2 + 1,
681 input_array, output_array);
682 fft_register_1d_c2r_local(fft_size, number_of_ffts, transpose, transpose,
683 transpose ? number_of_ffts : fft_size / 2 + 1,
684 transpose ? number_of_ffts : 2 * (fft_size / 2 + 1),
685 output_array, input_array);
686
687 memset(input_array, 0,
688 2 * (fft_size / 2 + 1) * number_of_ffts * sizeof(double));
689 // Check the forward FFT
690 if (transpose) {
691#pragma omp parallel for default(none) \
692 shared(input_array, fft_size, number_of_ffts)
693 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
694 number_of_fft++) {
695 input_array[(number_of_fft % fft_size) * number_of_ffts + number_of_fft] =
696 1.0;
697 }
698 } else {
699#pragma omp parallel for default(none) \
700 shared(input_array, fft_size, number_of_ffts)
701 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
702 number_of_fft++) {
703 input_array[(number_of_fft % fft_size) +
704 number_of_fft * 2 * (fft_size / 2 + 1)] = 1.0;
705 }
706 }
707
708 fft_1d_r2c_local(fft_size, number_of_ffts, transpose, transpose,
709 transpose ? number_of_ffts : 2 * (fft_size / 2 + 1),
710 transpose ? number_of_ffts : fft_size / 2 + 1, input_array,
711 output_array);
712
713 double max_error = 0.0;
714 if (transpose) {
715#pragma omp parallel for default(none) \
716 shared(output_array, fft_size, number_of_ffts, pi, my_process) \
717 reduction(max : max_error) collapse(2)
718 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
719 number_of_fft++) {
720 for (int index = 0; index < fft_size / 2 + 1; index++) {
721 const double complex my_value =
722 output_array[number_of_fft + index * number_of_ffts];
723 const double complex ref_value =
724 cexp(-2.0 * I * pi * (number_of_fft % fft_size) * index / fft_size);
725 const double current_error = cabs(my_value - ref_value);
726 if (my_process == 0 && current_error > 1e-12)
727 printf("Error %i %i / %i %i: (%f %f) (%f %f)\n", index, number_of_fft,
728 fft_size, number_of_ffts, creal(my_value), cimag(my_value),
729 creal(ref_value), cimag(ref_value));
730 max_error = fmax(max_error, current_error);
731 }
732 }
733 } else {
734#pragma omp parallel for default(none) \
735 shared(output_array, fft_size, number_of_ffts, pi, my_process) \
736 reduction(max : max_error) collapse(2)
737 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
738 number_of_fft++) {
739 for (int index = 0; index < fft_size / 2 + 1; index++) {
740 const double complex my_value =
741 output_array[number_of_fft * (fft_size / 2 + 1) + index];
742 const double complex ref_value =
743 cexp(-2.0 * I * pi * (number_of_fft % fft_size) * index / fft_size);
744 const double current_error = cabs(my_value - ref_value);
745 if (my_process == 0 && current_error > 1e-12)
746 printf("Error %i %i / %i %i: (%f %f) (%f %f)\n", index, number_of_fft,
747 fft_size, number_of_ffts, creal(my_value), cimag(my_value),
748 creal(ref_value), cimag(ref_value));
749 max_error = fmax(max_error, current_error);
750 }
751 }
752 }
753 fflush(stdout);
754
755 if (max_error > 1.0e-8) {
756 if (my_process == 0) {
757 printf(
758 "The fw R2C 1D-FFT (inplace) does not work correctly (%i %i): %f!\n",
759 fft_size, number_of_ffts, max_error);
760 fflush(stdout);
761 }
762 errors++;
763 }
764
765 // Check the backward FFT
766 memset(output_array, 0,
767 (fft_size / 2 + 1) * number_of_ffts * sizeof(double complex));
768
769 if (transpose) {
770#pragma omp parallel for default(none) collapse(2) \
771 shared(output_array, fft_size, number_of_ffts)
772 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
773 number_of_fft++) {
774 for (int index = 0; index < fft_size / 2 + 1; index++) {
775 output_array[number_of_fft + index * number_of_ffts] =
776 cexp(-2.0 * I * acos(-1) * index * number_of_fft / fft_size);
777 }
778 }
779 } else {
780#pragma omp parallel for default(none) \
781 shared(output_array, fft_size, number_of_ffts)
782 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
783 number_of_fft++) {
784 for (int index = 0; index < fft_size / 2 + 1; index++) {
785 output_array[number_of_fft * (fft_size / 2 + 1) + index] =
786 cexp(-2.0 * I * acos(-1) * index * number_of_fft / fft_size);
787 }
788 }
789 }
790
791 fft_1d_c2r_local(fft_size, number_of_ffts, transpose, transpose,
792 transpose ? number_of_ffts : fft_size / 2 + 1,
793 transpose ? number_of_ffts : 2 * (fft_size / 2 + 1),
794 output_array, input_array);
795
796 max_error = 0.0;
797 if (transpose) {
798#pragma omp parallel for default(none) \
799 shared(input_array, fft_size, number_of_ffts, my_process) \
800 reduction(max : max_error) collapse(2)
801 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
802 number_of_fft++) {
803 for (int index = 0; index < fft_size; index++) {
804 const double my_value =
805 input_array[index * number_of_ffts + number_of_fft];
806 const double ref_value =
807 (number_of_fft % fft_size == index ? (double)fft_size : 0.0);
808 const double current_error = fabs(my_value - ref_value);
809 if (my_process == 0 && current_error > 1e-4)
810 printf("ERROR %i %i / %i %i : %f %f\n", number_of_fft, index,
811 number_of_ffts, fft_size, my_value, ref_value);
812 max_error = fmax(max_error, current_error);
813 }
814 }
815 } else {
816#pragma omp parallel for default(none) \
817 shared(input_array, fft_size, number_of_ffts, my_process) \
818 reduction(max : max_error) collapse(2)
819 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
820 number_of_fft++) {
821 for (int index = 0; index < fft_size; index++) {
822 const double my_value =
823 input_array[index + number_of_fft * 2 * (fft_size / 2 + 1)];
824 const double ref_value =
825 (number_of_fft % fft_size == index ? (double)fft_size : 0.0);
826 const double current_error = fabs(my_value - ref_value);
827 if (my_process == 0 && current_error > 1e-4)
828 printf("ERROR %i %i / %i %i : %f %f\n", number_of_fft, index,
829 number_of_ffts, fft_size, my_value, ref_value);
830 max_error = fmax(max_error, current_error);
831 }
832 }
833 }
834 fflush(stdout);
835
836 if (max_error > 1e-8) {
837 if (my_process == 0) {
838 printf(
839 "The bw C2R-1D FFT (inplace) does not work correctly (%i %i): %f!\n",
840 fft_size, number_of_ffts, max_error);
841 fflush(stdout);
842 }
843 errors++;
844 }
845
846 fft_free_double(input_array);
847
848 if (errors == 0 && my_process == 0)
849 printf("The 1D R2C FFT (inplace) does work correctly (%i %i)!\n", fft_size,
850 number_of_ffts);
851 return errors;
852}
853
854/*******************************************************************************
855 * \brief Function to test the local FFT backend.
856 * \param fft_size Size of the transform in each dimension.
857 * \param number_of_ffts Number of independent (batched) transforms.
858 * \param transpose_rs Whether the real-space array uses the transposed layout.
859 * \param transpose_gs Whether the reciprocal-space array uses the transposed
860 * layout.
861 * \author Frederick Stein
862 ******************************************************************************/
863int fft_test_2d_local_low(const int fft_size[2], const int number_of_ffts,
864 const int transpose_rs, const int transpose_gs) {
865 const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
866
867 int errors = 0;
868
869 const double pi = acos(-1);
870
871 double complex *input_array = NULL, *output_array = NULL;
872 const int elements_per_fft = fft_size[0] * fft_size[1];
873 fft_allocate_complex(elements_per_fft * number_of_ffts, &input_array);
874 fft_allocate_complex(elements_per_fft * number_of_ffts, &output_array);
875
876 fft_register_2d_local(true, fft_size, number_of_ffts, transpose_rs,
877 transpose_gs, input_array, output_array);
878 fft_register_2d_local(false, fft_size, number_of_ffts, transpose_gs,
879 transpose_rs, output_array, input_array);
880
881 memset(input_array, 0,
882 elements_per_fft * number_of_ffts * sizeof(double complex));
883 double max_error = 0.0;
884 // Check the forward FFT
885 if (transpose_rs) {
886#pragma omp parallel for default(none) \
887 shared(input_array, elements_per_fft, number_of_ffts)
888 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
889 number_of_fft++) {
890 input_array[number_of_fft % elements_per_fft * number_of_ffts +
891 number_of_fft] = 1.0;
892 }
893 } else {
894#pragma omp parallel for default(none) \
895 shared(input_array, elements_per_fft, number_of_ffts)
896 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
897 number_of_fft++) {
898 input_array[number_of_fft % elements_per_fft +
899 number_of_fft * elements_per_fft] = 1.0;
900 }
901 }
902
903 fft_2d_local(true, fft_size, number_of_ffts, transpose_rs, transpose_gs,
904 input_array, output_array);
905
906 if (transpose_gs) {
907#pragma omp parallel for default(none) \
908 shared(output_array, fft_size, number_of_ffts, pi, my_process) \
909 reduction(max : max_error) collapse(3)
910 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
911 number_of_fft++) {
912 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
913 for (int index_1 = 0; index_1 < fft_size[1]; index_1++) {
914 const double complex my_value =
915 output_array[number_of_fft +
916 (index_0 * fft_size[1] + index_1) * number_of_ffts];
917 const double complex ref_value = cexp(
918 -2.0 * I * pi *
919 ((double)(number_of_fft / fft_size[1]) * index_0 / fft_size[0] +
920 (double)(number_of_fft % fft_size[1]) * index_1 / fft_size[1]));
921 double current_error = cabs(my_value - ref_value);
922 if (my_process == 0 && current_error > 1.0e-4)
923 printf("ERROR %i %i %i/%i %i %i: (%f %f) (%f %f)\n", index_0,
924 index_1, number_of_fft, fft_size[0], fft_size[1],
925 number_of_ffts, creal(my_value), cimag(my_value),
926 creal(ref_value), cimag(ref_value));
927 max_error = fmax(max_error, current_error);
928 }
929 }
930 }
931 } else {
932#pragma omp parallel for default(none) \
933 shared(output_array, fft_size, number_of_ffts, pi, my_process) \
934 reduction(max : max_error) collapse(3)
935 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
936 number_of_fft++) {
937 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
938 for (int index_1 = 0; index_1 < fft_size[1]; index_1++) {
939 const double complex my_value =
940 output_array[(number_of_fft * fft_size[0] + index_0) *
941 fft_size[1] +
942 index_1];
943 const double complex ref_value = cexp(
944 -2.0 * I * pi *
945 ((double)(number_of_fft / fft_size[1]) * index_0 / fft_size[0] +
946 (double)(number_of_fft % fft_size[1]) * index_1 / fft_size[1]));
947 double current_error = cabs(my_value - ref_value);
948 if (my_process == 0 && current_error > 1.0e-3)
949 printf("ERROR %i %i %i/%i %i %i: (%f %f) (%f %f)\n", index_0,
950 index_1, number_of_fft, fft_size[0], fft_size[1],
951 number_of_ffts, creal(my_value), cimag(my_value),
952 creal(ref_value), cimag(ref_value));
953 max_error = fmax(max_error, current_error);
954 }
955 }
956 }
957 }
958 fflush(stdout);
959
960 if (max_error > 1.0e-3) {
961 if (my_process == 0) {
962 printf("The fw 2D-FFT does not work correctly (%i %i/%i): %f!\n",
963 fft_size[0], fft_size[1], number_of_ffts, max_error);
964 fflush(stdout);
965 }
966 errors++;
967 }
968
969 // Check the backward FFT
970 memset(output_array, 0,
971 elements_per_fft * number_of_ffts * sizeof(double complex));
972
973 if (transpose_gs) {
974#pragma omp parallel for default(none) \
975 shared(output_array, elements_per_fft, number_of_ffts)
976 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
977 number_of_fft++) {
978 output_array[number_of_fft +
979 (number_of_fft % elements_per_fft) * number_of_ffts] = 1.0;
980 }
981 } else {
982#pragma omp parallel for default(none) \
983 shared(output_array, elements_per_fft, number_of_ffts)
984 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
985 number_of_fft++) {
986 output_array[number_of_fft * elements_per_fft +
987 number_of_fft % elements_per_fft] = 1.0;
988 }
989 }
990
991 fft_2d_local(false, fft_size, number_of_ffts, transpose_gs, transpose_rs,
992 output_array, input_array);
993
994 max_error = 0.0;
995 if (transpose_rs) {
996#pragma omp parallel for default(none) \
997 shared(input_array, fft_size, number_of_ffts, pi, my_process) \
998 reduction(max : max_error) collapse(3)
999 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1000 number_of_fft++) {
1001 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
1002 for (int index_1 = 0; index_1 < fft_size[1]; index_1++) {
1003 const double complex my_value =
1004 input_array[(index_0 * fft_size[1] + index_1) * number_of_ffts +
1005 number_of_fft];
1006 const double complex ref_value = cexp(
1007 2.0 * I * pi *
1008 ((double)(number_of_fft / fft_size[1]) * index_0 / fft_size[0] +
1009 (double)(number_of_fft % fft_size[1]) * index_1 / fft_size[1]));
1010 double current_error = cabs(my_value - ref_value);
1011 if (my_process == 0 && current_error > 1e-12)
1012 printf("Error %i %i %i: (%f %f) (%f %f)\n", index_0, index_1,
1013 number_of_fft, creal(my_value), cimag(my_value),
1014 creal(ref_value), cimag(ref_value));
1015 max_error = fmax(max_error, current_error);
1016 }
1017 }
1018 }
1019 } else {
1020#pragma omp parallel for default(none) \
1021 shared(input_array, fft_size, number_of_ffts, pi, my_process) \
1022 reduction(max : max_error) collapse(3)
1023 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1024 number_of_fft++) {
1025 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
1026 for (int index_1 = 0; index_1 < fft_size[1]; index_1++) {
1027 const double complex my_value =
1028 input_array[index_0 * fft_size[1] + index_1 +
1029 number_of_fft * fft_size[0] * fft_size[1]];
1030 const double complex ref_value = cexp(
1031 2.0 * I * pi *
1032 ((double)(number_of_fft / fft_size[1]) * index_0 / fft_size[0] +
1033 (double)(number_of_fft % fft_size[1]) * index_1 / fft_size[1]));
1034 double current_error = cabs(my_value - ref_value);
1035 if (my_process == 0 && current_error > 1e-12)
1036 printf("Error %i %i %i: (%f %f) (%f %f)\n", index_0, index_1,
1037 number_of_fft, creal(my_value), cimag(my_value),
1038 creal(ref_value), cimag(ref_value));
1039 max_error = fmax(max_error, current_error);
1040 }
1041 }
1042 }
1043 }
1044 fflush(stdout);
1045
1046 fft_free_complex(input_array);
1047 fft_free_complex(output_array);
1048
1049 if (max_error > 1e-12) {
1050 if (my_process == 0) {
1051 printf("The bw 2D-FFT does not work correctly (%i %i/%i): %f!\n",
1052 fft_size[0], fft_size[1], number_of_ffts, max_error);
1053 fflush(stdout);
1054 }
1055 errors++;
1056 }
1057
1058 if (errors == 0 && my_process == 0)
1059 printf("The 2D FFT does work correctly (%i %i/%i)!\n", fft_size[0],
1060 fft_size[1], number_of_ffts);
1061 return errors;
1062}
1063
1064/*******************************************************************************
1065 * \brief Function to test the local FFT backend.
1066 * \param fft_size Size of the transform in each dimension.
1067 * \param number_of_ffts Number of independent (batched) transforms.
1068 * \param transpose Whether the array uses the transposed layout.
1069 * \author Frederick Stein
1070 ******************************************************************************/
1071int fft_test_2d_local_inplace_low(const int fft_size[2],
1072 const int number_of_ffts,
1073 const int transpose) {
1074 const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
1075
1076 int errors = 0;
1077
1078 const double pi = acos(-1);
1079
1080 double complex *input_array = NULL;
1081 const int elements_per_fft = fft_size[0] * fft_size[1];
1082 fft_allocate_complex(elements_per_fft * number_of_ffts, &input_array);
1083 double complex *output_array = input_array;
1084
1085 fft_register_2d_local(true, fft_size, number_of_ffts, transpose, transpose,
1086 input_array, output_array);
1087 fft_register_2d_local(false, fft_size, number_of_ffts, transpose, transpose,
1088 output_array, input_array);
1089
1090 memset(input_array, 0,
1091 elements_per_fft * number_of_ffts * sizeof(double complex));
1092 double max_error = 0.0;
1093 // Check the forward FFT
1094 if (transpose) {
1095#pragma omp parallel for default(none) \
1096 shared(input_array, elements_per_fft, number_of_ffts)
1097 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1098 number_of_fft++) {
1099 input_array[number_of_fft % elements_per_fft * number_of_ffts +
1100 number_of_fft] = 1.0;
1101 }
1102 } else {
1103#pragma omp parallel for default(none) \
1104 shared(input_array, elements_per_fft, number_of_ffts)
1105 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1106 number_of_fft++) {
1107 input_array[number_of_fft % elements_per_fft +
1108 number_of_fft * elements_per_fft] = 1.0;
1109 }
1110 }
1111
1112 fft_2d_local(true, fft_size, number_of_ffts, transpose, transpose,
1113 input_array, output_array);
1114
1115 if (transpose) {
1116#pragma omp parallel for default(none) \
1117 shared(output_array, fft_size, number_of_ffts, pi, my_process) \
1118 reduction(max : max_error) collapse(3)
1119 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1120 number_of_fft++) {
1121 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
1122 for (int index_1 = 0; index_1 < fft_size[1]; index_1++) {
1123 const double complex my_value =
1124 output_array[number_of_fft +
1125 (index_0 * fft_size[1] + index_1) * number_of_ffts];
1126 const double complex ref_value = cexp(
1127 -2.0 * I * pi *
1128 ((double)(number_of_fft / fft_size[1]) * index_0 / fft_size[0] +
1129 (double)(number_of_fft % fft_size[1]) * index_1 / fft_size[1]));
1130 double current_error = cabs(my_value - ref_value);
1131 if (my_process == 0 && current_error > 1.0e-4)
1132 printf("ERROR %i %i %i/%i %i %i: (%f %f) (%f %f)\n", index_0,
1133 index_1, number_of_fft, fft_size[0], fft_size[1],
1134 number_of_ffts, creal(my_value), cimag(my_value),
1135 creal(ref_value), cimag(ref_value));
1136 max_error = fmax(max_error, current_error);
1137 }
1138 }
1139 }
1140 } else {
1141#pragma omp parallel for default(none) \
1142 shared(output_array, fft_size, number_of_ffts, pi, my_process) \
1143 reduction(max : max_error) collapse(3)
1144 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1145 number_of_fft++) {
1146 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
1147 for (int index_1 = 0; index_1 < fft_size[1]; index_1++) {
1148 const double complex my_value =
1149 output_array[(number_of_fft * fft_size[0] + index_0) *
1150 fft_size[1] +
1151 index_1];
1152 const double complex ref_value = cexp(
1153 -2.0 * I * pi *
1154 ((double)(number_of_fft / fft_size[1]) * index_0 / fft_size[0] +
1155 (double)(number_of_fft % fft_size[1]) * index_1 / fft_size[1]));
1156 double current_error = cabs(my_value - ref_value);
1157 if (my_process == 0 && current_error > 1.0e-3)
1158 printf("ERROR %i %i %i/%i %i %i: (%f %f) (%f %f)\n", index_0,
1159 index_1, number_of_fft, fft_size[0], fft_size[1],
1160 number_of_ffts, creal(my_value), cimag(my_value),
1161 creal(ref_value), cimag(ref_value));
1162 max_error = fmax(max_error, current_error);
1163 }
1164 }
1165 }
1166 }
1167 fflush(stdout);
1168
1169 if (max_error > 1.0e-3) {
1170 if (my_process == 0) {
1171 printf(
1172 "The fw 2D-FFT (inplace) does not work correctly (%i %i/%i): %f!\n",
1173 fft_size[0], fft_size[1], number_of_ffts, max_error);
1174 fflush(stdout);
1175 }
1176 errors++;
1177 }
1178
1179 // Check the backward FFT
1180 memset(output_array, 0,
1181 elements_per_fft * number_of_ffts * sizeof(double complex));
1182
1183 if (transpose) {
1184#pragma omp parallel for default(none) \
1185 shared(output_array, elements_per_fft, number_of_ffts)
1186 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1187 number_of_fft++) {
1188 output_array[number_of_fft +
1189 (number_of_fft % elements_per_fft) * number_of_ffts] = 1.0;
1190 }
1191 } else {
1192#pragma omp parallel for default(none) \
1193 shared(output_array, elements_per_fft, number_of_ffts)
1194 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1195 number_of_fft++) {
1196 output_array[number_of_fft * elements_per_fft +
1197 number_of_fft % elements_per_fft] = 1.0;
1198 }
1199 }
1200
1201 fft_2d_local(false, fft_size, number_of_ffts, transpose, transpose,
1202 output_array, input_array);
1203
1204 max_error = 0.0;
1205 if (transpose) {
1206#pragma omp parallel for default(none) \
1207 shared(input_array, fft_size, number_of_ffts, pi, my_process) \
1208 reduction(max : max_error) collapse(3)
1209 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1210 number_of_fft++) {
1211 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
1212 for (int index_1 = 0; index_1 < fft_size[1]; index_1++) {
1213 const double complex my_value =
1214 input_array[(index_0 * fft_size[1] + index_1) * number_of_ffts +
1215 number_of_fft];
1216 const double complex ref_value = cexp(
1217 2.0 * I * pi *
1218 ((double)(number_of_fft / fft_size[1]) * index_0 / fft_size[0] +
1219 (double)(number_of_fft % fft_size[1]) * index_1 / fft_size[1]));
1220 double current_error = cabs(my_value - ref_value);
1221 if (my_process == 0 && current_error > 1e-12)
1222 printf("Error %i %i %i: (%f %f) (%f %f)\n", index_0, index_1,
1223 number_of_fft, creal(my_value), cimag(my_value),
1224 creal(ref_value), cimag(ref_value));
1225 max_error = fmax(max_error, current_error);
1226 }
1227 }
1228 }
1229 } else {
1230#pragma omp parallel for default(none) \
1231 shared(input_array, fft_size, number_of_ffts, pi, my_process) \
1232 reduction(max : max_error) collapse(3)
1233 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1234 number_of_fft++) {
1235 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
1236 for (int index_1 = 0; index_1 < fft_size[1]; index_1++) {
1237 const double complex my_value =
1238 input_array[index_0 * fft_size[1] + index_1 +
1239 number_of_fft * fft_size[0] * fft_size[1]];
1240 const double complex ref_value = cexp(
1241 2.0 * I * pi *
1242 ((double)(number_of_fft / fft_size[1]) * index_0 / fft_size[0] +
1243 (double)(number_of_fft % fft_size[1]) * index_1 / fft_size[1]));
1244 double current_error = cabs(my_value - ref_value);
1245 if (my_process == 0 && current_error > 1e-12)
1246 printf("Error %i %i %i: (%f %f) (%f %f)\n", index_0, index_1,
1247 number_of_fft, creal(my_value), cimag(my_value),
1248 creal(ref_value), cimag(ref_value));
1249 max_error = fmax(max_error, current_error);
1250 }
1251 }
1252 }
1253 }
1254 fflush(stdout);
1255
1256 fft_free_complex(input_array);
1257
1258 if (max_error > 1e-12) {
1259 if (my_process == 0) {
1260 printf(
1261 "The bw 2D-FFT (inplace) does not work correctly (%i %i/%i): %f!\n",
1262 fft_size[0], fft_size[1], number_of_ffts, max_error);
1263 fflush(stdout);
1264 }
1265 errors++;
1266 }
1267
1268 if (errors == 0 && my_process == 0)
1269 printf("The 2D FFT (inplace) does work correctly (%i %i/%i)!\n",
1270 fft_size[0], fft_size[1], number_of_ffts);
1271 return errors;
1272}
1273
1274/*******************************************************************************
1275 * \brief Function to test the local FFT backend.
1276 * \param fft_size Size of the transform in each dimension.
1277 * \param number_of_ffts Number of independent (batched) transforms.
1278 * \param transpose_rs Whether the real-space array uses the transposed layout.
1279 * \param transpose_gs Whether the reciprocal-space array uses the transposed
1280 * layout.
1281 * \author Frederick Stein
1282 ******************************************************************************/
1283int fft_test_2d_local_r2c_low(const int fft_size[2], const int number_of_ffts,
1284 const int transpose_rs, const int transpose_gs) {
1285 const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
1286
1287 int errors = 0;
1288
1289 const double pi = acos(-1);
1290
1291 double *real_buffer = NULL;
1292 double complex *complex_buffer = NULL;
1293 fft_allocate_double(2 * (fft_size[1] / 2 + 1) * fft_size[0] * number_of_ffts,
1294 &real_buffer);
1295 fft_allocate_complex((fft_size[1] / 2 + 1) * fft_size[0] * number_of_ffts,
1296 &complex_buffer);
1297
1298 fft_register_2d_r2c_local(fft_size, number_of_ffts, transpose_rs,
1299 transpose_gs, real_buffer, complex_buffer);
1300 fft_register_2d_c2r_local(fft_size, number_of_ffts, transpose_gs,
1301 transpose_rs, complex_buffer, real_buffer);
1302
1303 memset(real_buffer, 0,
1304 2 * (fft_size[1] / 2 + 1) * fft_size[0] * number_of_ffts *
1305 sizeof(double));
1306
1307 double max_error = 0.0;
1308 // Check the forward FFT
1309 if (transpose_rs) {
1310#pragma omp parallel for default(none) \
1311 shared(real_buffer, fft_size, number_of_ffts)
1312 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1313 number_of_fft++) {
1314 real_buffer[(number_of_fft / fft_size[1] % fft_size[0] * fft_size[1] +
1315 number_of_fft % fft_size[1]) *
1316 number_of_ffts +
1317 number_of_fft] = 1.0;
1318 }
1319 } else {
1320#pragma omp parallel for default(none) \
1321 shared(real_buffer, fft_size, number_of_ffts)
1322 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1323 number_of_fft++) {
1324 real_buffer[(number_of_fft / fft_size[1] % fft_size[0] * fft_size[1] +
1325 number_of_fft % fft_size[1]) +
1326 number_of_fft * (fft_size[0] * fft_size[1])] = 1.0;
1327 }
1328 }
1329
1330 fft_2d_r2c_local(fft_size, number_of_ffts, transpose_rs, transpose_gs,
1331 real_buffer, complex_buffer);
1332
1333 if (transpose_gs) {
1334#pragma omp parallel for default(none) \
1335 shared(complex_buffer, fft_size, number_of_ffts, pi, my_process) \
1336 reduction(max : max_error) collapse(3)
1337 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1338 number_of_fft++) {
1339 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
1340 for (int index_1 = 0; index_1 < fft_size[1] / 2 + 1; index_1++) {
1341 const double complex my_value =
1342 complex_buffer[number_of_fft +
1343 (index_0 * (fft_size[1] / 2 + 1) + index_1) *
1344 number_of_ffts];
1345 const double complex ref_value = cexp(
1346 -2.0 * I * pi *
1347 ((double)(number_of_fft / fft_size[1]) * index_0 / fft_size[0] +
1348 (double)(number_of_fft % fft_size[1]) * index_1 / fft_size[1]));
1349 double current_error = cabs(my_value - ref_value);
1350 if (my_process == 0 && current_error > 1e-6)
1351 printf("Error %i %i %i/%i %i %i: (%f %f) (%f %f)\n", index_0,
1352 index_1, number_of_fft, fft_size[0], fft_size[1],
1353 number_of_ffts, creal(my_value), cimag(my_value),
1354 creal(ref_value), cimag(ref_value));
1355 max_error = fmax(max_error, current_error);
1356 }
1357 }
1358 }
1359 } else {
1360#pragma omp parallel for default(none) \
1361 shared(complex_buffer, fft_size, number_of_ffts, pi, my_process) \
1362 reduction(max : max_error) collapse(3)
1363 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1364 number_of_fft++) {
1365 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
1366 for (int index_1 = 0; index_1 < fft_size[1] / 2 + 1; index_1++) {
1367 const double complex my_value =
1368 complex_buffer[number_of_fft * fft_size[0] *
1369 (fft_size[1] / 2 + 1) +
1370 index_0 * (fft_size[1] / 2 + 1) + index_1];
1371 const double complex ref_value = cexp(
1372 -2.0 * I * pi *
1373 ((double)(number_of_fft / fft_size[1]) * index_0 / fft_size[0] +
1374 (double)(number_of_fft % fft_size[1]) * index_1 / fft_size[1]));
1375 double current_error = cabs(my_value - ref_value);
1376 if (my_process == 0 && current_error > 1e-6)
1377 printf("Error %i %i %i/%i %i %i: (%f %f) (%f %f)\n", index_0,
1378 index_1, number_of_fft, fft_size[0], fft_size[1],
1379 number_of_ffts, creal(my_value), cimag(my_value),
1380 creal(ref_value), cimag(ref_value));
1381 max_error = fmax(max_error, current_error);
1382 }
1383 }
1384 }
1385 }
1386 fflush(stdout);
1387
1388 if (max_error > 1.0e-12) {
1389 if (my_process == 0) {
1390 printf("The fw R2C 2D-FFT does not work correctly (%i %i/%i): %f!\n",
1391 fft_size[0], fft_size[1], number_of_ffts, max_error);
1392 fflush(stdout);
1393 }
1394 errors++;
1395 }
1396
1397 // Check the backward FFT
1398 memset(complex_buffer, 0,
1399 fft_size[0] * (fft_size[1] / 2 + 1) * number_of_ffts *
1400 sizeof(double complex));
1401
1402 if (transpose_gs) {
1403#pragma omp parallel for default(none) \
1404 shared(complex_buffer, fft_size, number_of_ffts, pi) \
1405 reduction(max : max_error) collapse(3)
1406 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1407 number_of_fft++) {
1408 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
1409 for (int index_1 = 0; index_1 < fft_size[1] / 2 + 1; index_1++) {
1410 complex_buffer[number_of_fft +
1411 (index_0 * (fft_size[1] / 2 + 1) + index_1) *
1412 number_of_ffts] =
1413 cexp(-2.0 * I * pi *
1414 ((double)(number_of_fft / fft_size[1]) * index_0 /
1415 fft_size[0] +
1416 (double)(number_of_fft % fft_size[1]) * index_1 /
1417 fft_size[1]));
1418 }
1419 }
1420 }
1421 } else {
1422#pragma omp parallel for default(none) \
1423 shared(complex_buffer, fft_size, number_of_ffts, pi) \
1424 reduction(max : max_error) collapse(3)
1425 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1426 number_of_fft++) {
1427 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
1428 for (int index_1 = 0; index_1 < fft_size[1] / 2 + 1; index_1++) {
1429 complex_buffer[number_of_fft * fft_size[0] * (fft_size[1] / 2 + 1) +
1430 index_0 * (fft_size[1] / 2 + 1) + index_1] =
1431 cexp(-2.0 * I * pi *
1432 ((double)(number_of_fft / fft_size[1]) * index_0 /
1433 fft_size[0] +
1434 (double)(number_of_fft % fft_size[1]) * index_1 /
1435 fft_size[1]));
1436 }
1437 }
1438 }
1439 }
1440
1441 fft_2d_c2r_local(fft_size, number_of_ffts, transpose_gs, transpose_rs,
1442 complex_buffer, real_buffer);
1443
1444 max_error = 0.0;
1445 if (transpose_rs) {
1446#pragma omp parallel for default(none) \
1447 shared(real_buffer, fft_size, number_of_ffts, pi, my_process) \
1448 reduction(max : max_error) collapse(3)
1449 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
1450 for (int index_1 = 0; index_1 < fft_size[1]; index_1++) {
1451 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1452 number_of_fft++) {
1453 const double my_value =
1454 real_buffer[(index_0 * fft_size[1] + index_1) * number_of_ffts +
1455 number_of_fft];
1456 const double ref_value =
1457 index_0 == number_of_fft / fft_size[1] % fft_size[0] &&
1458 index_1 == number_of_fft % fft_size[1]
1459 ? (double)(fft_size[0] * fft_size[1])
1460 : 0.0;
1461 const double current_error = fabs(my_value - ref_value);
1462 if (my_process == 0 && current_error > 1e-6)
1463 printf("Error %i %i %i/%i %i %i: %f %f\n", index_0, index_1,
1464 number_of_fft, fft_size[0], fft_size[1], number_of_ffts,
1465 my_value, ref_value);
1466 max_error = fmax(max_error, current_error);
1467 }
1468 }
1469 }
1470 } else {
1471#pragma omp parallel for default(none) \
1472 shared(real_buffer, fft_size, number_of_ffts, pi, my_process) \
1473 reduction(max : max_error) collapse(3)
1474 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1475 number_of_fft++) {
1476 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
1477 for (int index_1 = 0; index_1 < fft_size[1]; index_1++) {
1478 const double my_value =
1479 real_buffer[index_0 * fft_size[1] + index_1 +
1480 number_of_fft * fft_size[0] * fft_size[1]];
1481 const double ref_value =
1482 index_0 == number_of_fft / fft_size[1] % fft_size[0] &&
1483 index_1 == number_of_fft % fft_size[1]
1484 ? (double)(fft_size[0] * fft_size[1])
1485 : 0.0;
1486 double current_error = fabs(my_value - ref_value);
1487 if (my_process == 0 && current_error > 1e-6)
1488 printf("Error %i %i %i/%i %i %i: %f %f\n", index_0, index_1,
1489 number_of_fft, fft_size[0], fft_size[1], number_of_ffts,
1490 my_value, ref_value);
1491 max_error = fmax(max_error, current_error);
1492 }
1493 }
1494 }
1495 }
1496 fflush(stdout);
1497
1498 fft_free_double(real_buffer);
1499 fft_free_complex(complex_buffer);
1500
1501 if (max_error > 1e-8) {
1502 if (my_process == 0) {
1503 printf("The bw C2R 2D-FFT does not work correctly (%i %i/%i): %f!\n",
1504 fft_size[0], fft_size[1], number_of_ffts, max_error);
1505 fflush(stdout);
1506 }
1507 errors++;
1508 }
1509
1510 if (errors == 0 && my_process == 0)
1511 printf("The 2D R2C/C2R FFT does work correctly (%i %i/%i)!\n", fft_size[0],
1512 fft_size[1], number_of_ffts);
1513 return errors;
1514}
1515
1516/*******************************************************************************
1517 * \brief Function to test the local FFT backend.
1518 * \param fft_size Size of the transform in each dimension.
1519 * \param number_of_ffts Number of independent (batched) transforms.
1520 * \param transpose Whether the array uses the transposed layout.
1521 * \author Frederick Stein
1522 ******************************************************************************/
1523int fft_test_2d_local_r2c_inplace_low(const int fft_size[2],
1524 const int number_of_ffts,
1525 const int transpose) {
1526 const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
1527
1528 int errors = 0;
1529
1530 const double pi = acos(-1);
1531
1532 double *real_buffer = NULL;
1533 fft_allocate_double(2 * (fft_size[1] / 2 + 1) * fft_size[0] * number_of_ffts,
1534 &real_buffer);
1535 double complex *complex_buffer = (double complex *)real_buffer;
1536
1537 fft_register_2d_r2c_local(fft_size, number_of_ffts, transpose, transpose,
1538 real_buffer, complex_buffer);
1539 fft_register_2d_c2r_local(fft_size, number_of_ffts, transpose, transpose,
1540 complex_buffer, real_buffer);
1541
1542 memset(real_buffer, 0,
1543 2 * (fft_size[1] / 2 + 1) * fft_size[0] * number_of_ffts *
1544 sizeof(double));
1545
1546 double max_error = 0.0;
1547 // Check the forward FFT
1548 if (transpose) {
1549#pragma omp parallel for default(none) \
1550 shared(real_buffer, fft_size, number_of_ffts)
1551 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1552 number_of_fft++) {
1553 real_buffer[(number_of_fft / fft_size[1] % fft_size[0] * 2 *
1554 (fft_size[1] / 2 + 1) +
1555 number_of_fft % fft_size[1]) *
1556 number_of_ffts +
1557 number_of_fft] = 1.0;
1558 }
1559 } else {
1560#pragma omp parallel for default(none) \
1561 shared(real_buffer, fft_size, number_of_ffts)
1562 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1563 number_of_fft++) {
1564 real_buffer[(number_of_fft / fft_size[1] % fft_size[0] * 2 *
1565 (fft_size[1] / 2 + 1) +
1566 number_of_fft % fft_size[1]) +
1567 number_of_fft * (fft_size[0] * 2 * (fft_size[1] / 2 + 1))] =
1568 1.0;
1569 }
1570 }
1571
1572 fft_2d_r2c_local(fft_size, number_of_ffts, transpose, transpose, real_buffer,
1573 complex_buffer);
1574
1575 if (transpose) {
1576#pragma omp parallel for default(none) \
1577 shared(complex_buffer, fft_size, number_of_ffts, pi, my_process) \
1578 reduction(max : max_error) collapse(3)
1579 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1580 number_of_fft++) {
1581 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
1582 for (int index_1 = 0; index_1 < fft_size[1] / 2 + 1; index_1++) {
1583 const double complex my_value =
1584 complex_buffer[number_of_fft +
1585 (index_0 * (fft_size[1] / 2 + 1) + index_1) *
1586 number_of_ffts];
1587 const double complex ref_value = cexp(
1588 -2.0 * I * pi *
1589 ((double)(number_of_fft / fft_size[1]) * index_0 / fft_size[0] +
1590 (double)(number_of_fft % fft_size[1]) * index_1 / fft_size[1]));
1591 double current_error = cabs(my_value - ref_value);
1592 if (my_process == 0 && current_error > 1e-6)
1593 printf("Error %i %i %i/%i %i %i: (%f %f) (%f %f)\n", index_0,
1594 index_1, number_of_fft, fft_size[0], fft_size[1],
1595 number_of_ffts, creal(my_value), cimag(my_value),
1596 creal(ref_value), cimag(ref_value));
1597 max_error = fmax(max_error, current_error);
1598 }
1599 }
1600 }
1601 } else {
1602#pragma omp parallel for default(none) \
1603 shared(complex_buffer, fft_size, number_of_ffts, pi, my_process) \
1604 reduction(max : max_error) collapse(3)
1605 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1606 number_of_fft++) {
1607 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
1608 for (int index_1 = 0; index_1 < fft_size[1] / 2 + 1; index_1++) {
1609 const double complex my_value =
1610 complex_buffer[number_of_fft * fft_size[0] *
1611 (fft_size[1] / 2 + 1) +
1612 index_0 * (fft_size[1] / 2 + 1) + index_1];
1613 const double complex ref_value = cexp(
1614 -2.0 * I * pi *
1615 ((double)(number_of_fft / fft_size[1]) * index_0 / fft_size[0] +
1616 (double)(number_of_fft % fft_size[1]) * index_1 / fft_size[1]));
1617 double current_error = cabs(my_value - ref_value);
1618 if (my_process == 0 && current_error > 1e-6)
1619 printf("Error %i %i %i/%i %i %i: (%f %f) (%f %f)\n", index_0,
1620 index_1, number_of_fft, fft_size[0], fft_size[1],
1621 number_of_ffts, creal(my_value), cimag(my_value),
1622 creal(ref_value), cimag(ref_value));
1623 max_error = fmax(max_error, current_error);
1624 }
1625 }
1626 }
1627 }
1628 fflush(stdout);
1629
1630 if (max_error > 1.0e-12) {
1631 if (my_process == 0) {
1632 printf("The fw R2C 2D-FFT (inplace) does not work correctly (%i %i/%i): "
1633 "%f!\n",
1634 fft_size[0], fft_size[1], number_of_ffts, max_error);
1635 fflush(stdout);
1636 }
1637 errors++;
1638 }
1639
1640 // Check the backward FFT
1641 memset(complex_buffer, 0,
1642 fft_size[0] * (fft_size[1] / 2 + 1) * number_of_ffts *
1643 sizeof(double complex));
1644
1645 if (transpose) {
1646#pragma omp parallel for default(none) \
1647 shared(complex_buffer, fft_size, number_of_ffts, pi) \
1648 reduction(max : max_error) collapse(3)
1649 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1650 number_of_fft++) {
1651 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
1652 for (int index_1 = 0; index_1 < fft_size[1] / 2 + 1; index_1++) {
1653 complex_buffer[number_of_fft +
1654 (index_0 * (fft_size[1] / 2 + 1) + index_1) *
1655 number_of_ffts] =
1656 cexp(-2.0 * I * pi *
1657 ((double)(number_of_fft / fft_size[1]) * index_0 /
1658 fft_size[0] +
1659 (double)(number_of_fft % fft_size[1]) * index_1 /
1660 fft_size[1]));
1661 }
1662 }
1663 }
1664 } else {
1665#pragma omp parallel for default(none) \
1666 shared(complex_buffer, fft_size, number_of_ffts, pi) \
1667 reduction(max : max_error) collapse(3)
1668 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1669 number_of_fft++) {
1670 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
1671 for (int index_1 = 0; index_1 < fft_size[1] / 2 + 1; index_1++) {
1672 complex_buffer[number_of_fft * fft_size[0] * (fft_size[1] / 2 + 1) +
1673 index_0 * (fft_size[1] / 2 + 1) + index_1] =
1674 cexp(-2.0 * I * pi *
1675 ((double)(number_of_fft / fft_size[1]) * index_0 /
1676 fft_size[0] +
1677 (double)(number_of_fft % fft_size[1]) * index_1 /
1678 fft_size[1]));
1679 }
1680 }
1681 }
1682 }
1683
1684 fft_2d_c2r_local(fft_size, number_of_ffts, transpose, transpose,
1685 complex_buffer, real_buffer);
1686
1687 max_error = 0.0;
1688 if (transpose) {
1689#pragma omp parallel for default(none) \
1690 shared(real_buffer, fft_size, number_of_ffts, pi, my_process) \
1691 reduction(max : max_error) collapse(3)
1692 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
1693 for (int index_1 = 0; index_1 < fft_size[1]; index_1++) {
1694 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1695 number_of_fft++) {
1696 const double my_value =
1697 real_buffer[(index_0 * 2 * (fft_size[1] / 2 + 1) + index_1) *
1698 number_of_ffts +
1699 number_of_fft];
1700 const double ref_value =
1701 index_0 == number_of_fft / fft_size[1] % fft_size[0] &&
1702 index_1 == number_of_fft % fft_size[1]
1703 ? (double)(fft_size[0] * fft_size[1])
1704 : 0.0;
1705 const double current_error = fabs(my_value - ref_value);
1706 if (my_process == 0 && current_error > 1e-6)
1707 printf("Error %i %i %i/%i %i %i: %f %f\n", index_0, index_1,
1708 number_of_fft, fft_size[0], fft_size[1], number_of_ffts,
1709 my_value, ref_value);
1710 max_error = fmax(max_error, current_error);
1711 }
1712 }
1713 }
1714 } else {
1715#pragma omp parallel for default(none) \
1716 shared(real_buffer, fft_size, number_of_ffts, pi, my_process) \
1717 reduction(max : max_error) collapse(3)
1718 for (int number_of_fft = 0; number_of_fft < number_of_ffts;
1719 number_of_fft++) {
1720 for (int index_0 = 0; index_0 < fft_size[0]; index_0++) {
1721 for (int index_1 = 0; index_1 < fft_size[1]; index_1++) {
1722 const double my_value =
1723 real_buffer[index_0 * 2 * (fft_size[1] / 2 + 1) + index_1 +
1724 number_of_fft * fft_size[0] * 2 *
1725 (fft_size[1] / 2 + 1)];
1726 const double ref_value =
1727 index_0 == number_of_fft / fft_size[1] % fft_size[0] &&
1728 index_1 == number_of_fft % fft_size[1]
1729 ? (double)(fft_size[0] * fft_size[1])
1730 : 0.0;
1731 double current_error = fabs(my_value - ref_value);
1732 if (my_process == 0 && current_error > 1e-6)
1733 printf("Error %i %i %i/%i %i %i: %f %f\n", index_0, index_1,
1734 number_of_fft, fft_size[0], fft_size[1], number_of_ffts,
1735 my_value, ref_value);
1736 max_error = fmax(max_error, current_error);
1737 }
1738 }
1739 }
1740 }
1741 fflush(stdout);
1742
1743 fft_free_double(real_buffer);
1744
1745 if (max_error > 1e-8) {
1746 if (my_process == 0) {
1747 printf("The bw C2R 2D-FFT (inplace) does not work correctly (%i %i/%i): "
1748 "%f!\n",
1749 fft_size[0], fft_size[1], number_of_ffts, max_error);
1750 fflush(stdout);
1751 }
1752 errors++;
1753 }
1754
1755 if (errors == 0 && my_process == 0)
1756 printf("The 2D R2C/C2R FFT (inplace) does work correctly (%i %i/%i)!\n",
1757 fft_size[0], fft_size[1], number_of_ffts);
1758 return errors;
1759}
1760
1761/*******************************************************************************
1762 * \brief Function to test the local FFT backend.
1763 * \param fft_size Size of the transform in each dimension.
1764 * \param test_every Stride selecting the basis vectors to test.
1765 * \param transpose_in Whether the input array uses the transposed layout.
1766 * \param transpose_out Whether the output array uses the transposed layout.
1767 * \author Frederick Stein
1768 ******************************************************************************/
1769int fft_test_3d_local_low(const int fft_size[3], const int test_every,
1770 const bool transpose_in, const bool transpose_out) {
1771 cp_assert(test_every > 0);
1772 const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
1773
1774 int errors = 0;
1775
1776 const double pi = acos(-1);
1777 const int volume = product3(fft_size);
1778 const int number_of_ffts = (volume + test_every - 1) / test_every;
1779
1780 double complex *input_array = NULL, *output_array = NULL;
1781 fft_allocate_complex(volume * number_of_ffts, &input_array);
1782 fft_allocate_complex(volume * number_of_ffts, &output_array);
1783
1784 fft_register_3d_local(true, fft_size, number_of_ffts, transpose_in,
1785 transpose_out, input_array, output_array);
1786 fft_register_3d_local(false, fft_size, number_of_ffts, transpose_out,
1787 transpose_in, output_array, input_array);
1788
1789 double max_error = 0.0;
1790 memset(input_array, 0, volume * number_of_ffts * sizeof(double complex));
1791#pragma omp parallel for collapse(3)
1792 for (int mx = 0; mx < fft_size[0]; mx++) {
1793 for (int my = 0; my < fft_size[1]; my++) {
1794 for (int mz = 0; mz < fft_size[2]; mz++) {
1795 const int index = (mx * fft_size[1] + my) * fft_size[2] + mz;
1796 if (index % test_every != 0)
1797 continue;
1798 const int batch = index / test_every;
1799 input_array[fft3d_index(fft_size, mx, my, mz, batch, number_of_ffts,
1800 transpose_in)] = 1.0;
1801 }
1802 }
1803 }
1804 fft_3d_local(true, fft_size, number_of_ffts, transpose_in, transpose_out,
1805 input_array, output_array);
1806
1807#pragma omp parallel for default(none) firstprivate(test_every) \
1808 firstprivate(transpose_in, transpose_out) \
1809 shared(output_array, fft_size, pi, my_process, volume, number_of_ffts) \
1810 reduction(max : max_error) collapse(3)
1811 for (int mx = 0; mx < fft_size[0]; mx++) {
1812 for (int my = 0; my < fft_size[1]; my++) {
1813 for (int mz = 0; mz < fft_size[2]; mz++) {
1814 const int basis = (mx * fft_size[1] + my) * fft_size[2] + mz;
1815 if (basis % test_every != 0)
1816 continue;
1817 const int batch = basis / test_every;
1818 for (int nx = 0; nx < fft_size[0]; nx++) {
1819 for (int ny = 0; ny < fft_size[1]; ny++) {
1820 for (int nz = 0; nz < fft_size[2]; nz++) {
1821 const double complex my_value = output_array[fft3d_index(
1822 fft_size, nx, ny, nz, batch, number_of_ffts, transpose_out)];
1823 const double complex ref_value =
1824 cexp(-2.0 * I * pi *
1825 (((double)mx) * nx / fft_size[0] +
1826 ((double)my) * ny / fft_size[1] +
1827 ((double)mz) * nz / fft_size[2]));
1828 const double current_error = cabs(my_value - ref_value);
1829 if (my_process == 0 && current_error > 1e-6)
1830 printf("Error %i %i %i/%i %i %i: (%f %f) (%f %f)\n", nx, ny, nz,
1831 mx, my, mz, creal(my_value), cimag(my_value),
1832 creal(ref_value), cimag(ref_value));
1833 max_error = fmax(max_error, current_error);
1834 }
1835 }
1836 }
1837 }
1838 }
1839 }
1840 fflush(stdout);
1841
1842 if (max_error > 1.0e-12) {
1843 if (my_process == 0) {
1844 printf("The fw 3D-FFT does not work correctly (%i %i %i): %f!\n",
1845 fft_size[0], fft_size[1], fft_size[2], max_error);
1846 fflush(stdout);
1847 }
1848 errors++;
1849 }
1850
1851 max_error = 0.0;
1852 memset(output_array, 0, volume * number_of_ffts * sizeof(double complex));
1853#pragma omp parallel for collapse(3)
1854 for (int mx = 0; mx < fft_size[0]; mx++) {
1855 for (int my = 0; my < fft_size[1]; my++) {
1856 for (int mz = 0; mz < fft_size[2]; mz++) {
1857 const int index = (mx * fft_size[1] + my) * fft_size[2] + mz;
1858 if (index % test_every != 0)
1859 continue;
1860 const int batch = index / test_every;
1861 output_array[fft3d_index(fft_size, mx, my, mz, batch, number_of_ffts,
1862 transpose_out)] = 1.0;
1863 }
1864 }
1865 }
1866 fft_3d_local(false, fft_size, number_of_ffts, transpose_out, transpose_in,
1867 output_array, input_array);
1868
1869#pragma omp parallel for default(none) firstprivate(test_every) \
1870 firstprivate(transpose_in, transpose_out) \
1871 shared(input_array, fft_size, pi, my_process, volume, number_of_ffts) \
1872 reduction(max : max_error) collapse(3)
1873 for (int mx = 0; mx < fft_size[0]; mx++) {
1874 for (int my = 0; my < fft_size[1]; my++) {
1875 for (int mz = 0; mz < fft_size[2]; mz++) {
1876 const int basis = (mx * fft_size[1] + my) * fft_size[2] + mz;
1877 if (basis % test_every != 0)
1878 continue;
1879 const int batch = basis / test_every;
1880 for (int nx = 0; nx < fft_size[0]; nx++) {
1881 for (int ny = 0; ny < fft_size[1]; ny++) {
1882 for (int nz = 0; nz < fft_size[2]; nz++) {
1883 const double complex my_value = input_array[fft3d_index(
1884 fft_size, nx, ny, nz, batch, number_of_ffts, transpose_in)];
1885 const double complex ref_value =
1886 cexp(2.0 * I * pi *
1887 (((double)mx) * nx / fft_size[0] +
1888 ((double)my) * ny / fft_size[1] +
1889 ((double)mz) * nz / fft_size[2]));
1890 const double current_error = cabs(my_value - ref_value);
1891 if (my_process == 0 && current_error > 1e-6)
1892 printf("Error %i %i %i/%i %i %i: (%f %f) (%f %f)\n", nx, ny, nz,
1893 mx, my, mz, creal(my_value), cimag(my_value),
1894 creal(ref_value), cimag(ref_value));
1895 max_error = fmax(max_error, current_error);
1896 }
1897 }
1898 }
1899 }
1900 }
1901 }
1902 fflush(stdout);
1903
1904 fft_free_complex(input_array);
1905 fft_free_complex(output_array);
1906
1907 if (max_error > 1e-12) {
1908 if (my_process == 0) {
1909 printf("The bw 3D-FFT does not work correctly (%i %i %i): %f!\n",
1910 fft_size[0], fft_size[1], fft_size[2], max_error);
1911 fflush(stdout);
1912 }
1913 errors++;
1914 }
1915
1916 if (errors == 0 && my_process == 0)
1917 printf("The 3D FFT does work correctly (%i %i %i)!\n", fft_size[0],
1918 fft_size[1], fft_size[2]);
1919 return errors;
1920}
1921
1922/*******************************************************************************
1923 * \brief Function to test the local FFT backend.
1924 * \param fft_size Size of the transform in each dimension.
1925 * \param test_every Stride selecting the basis vectors to test.
1926 * \param transpose Whether the array uses the transposed layout.
1927 * \author Frederick Stein
1928 ******************************************************************************/
1929int fft_test_3d_local_inplace_low(const int fft_size[3], const int test_every,
1930 const bool transpose) {
1931 cp_assert(test_every > 0);
1932 const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
1933
1934 int errors = 0;
1935
1936 const double pi = acos(-1);
1937 const int volume = product3(fft_size);
1938 const int number_of_ffts = (volume + test_every - 1) / test_every;
1939
1940 double complex *input_array = NULL;
1941 fft_allocate_complex(volume * number_of_ffts, &input_array);
1942 double complex *output_array = input_array;
1943
1944 fft_register_3d_local(true, fft_size, number_of_ffts, transpose, transpose,
1945 input_array, output_array);
1946 fft_register_3d_local(false, fft_size, number_of_ffts, transpose, transpose,
1947 output_array, input_array);
1948
1949 double max_error = 0.0;
1950 memset(input_array, 0, volume * number_of_ffts * sizeof(double complex));
1951#pragma omp parallel for collapse(3)
1952 for (int mx = 0; mx < fft_size[0]; mx++) {
1953 for (int my = 0; my < fft_size[1]; my++) {
1954 for (int mz = 0; mz < fft_size[2]; mz++) {
1955 const int index = (mx * fft_size[1] + my) * fft_size[2] + mz;
1956 if (index % test_every != 0)
1957 continue;
1958 const int batch = index / test_every;
1959 input_array[fft3d_index(fft_size, mx, my, mz, batch, number_of_ffts,
1960 transpose)] = 1.0;
1961 }
1962 }
1963 }
1964 fft_3d_local(true, fft_size, number_of_ffts, transpose, transpose,
1965 input_array, output_array);
1966
1967#pragma omp parallel for default(none) firstprivate(test_every) \
1968 firstprivate(transpose) \
1969 shared(output_array, fft_size, pi, volume, number_of_ffts) \
1970 reduction(max : max_error) collapse(3)
1971 for (int mx = 0; mx < fft_size[0]; mx++) {
1972 for (int my = 0; my < fft_size[1]; my++) {
1973 for (int mz = 0; mz < fft_size[2]; mz++) {
1974 const int basis = (mx * fft_size[1] + my) * fft_size[2] + mz;
1975 if (basis % test_every != 0)
1976 continue;
1977 const int batch = basis / test_every;
1978 for (int nx = 0; nx < fft_size[0]; nx++) {
1979 for (int ny = 0; ny < fft_size[1]; ny++) {
1980 for (int nz = 0; nz < fft_size[2]; nz++) {
1981 const double complex my_value = output_array[fft3d_index(
1982 fft_size, nx, ny, nz, batch, number_of_ffts, transpose)];
1983 const double complex ref_value =
1984 cexp(-2.0 * I * pi *
1985 (((double)mx) * nx / fft_size[0] +
1986 ((double)my) * ny / fft_size[1] +
1987 ((double)mz) * nz / fft_size[2]));
1988 max_error = fmax(max_error, cabs(my_value - ref_value));
1989 }
1990 }
1991 }
1992 }
1993 }
1994 }
1995 fflush(stdout);
1996
1997 if (max_error > 1.0e-12) {
1998 if (my_process == 0) {
1999 printf(
2000 "The fw 3D-FFT (inplace) does not work correctly (%i %i %i): %f!\n",
2001 fft_size[0], fft_size[1], fft_size[2], max_error);
2002 fflush(stdout);
2003 }
2004 errors++;
2005 }
2006
2007 max_error = 0.0;
2008 memset(output_array, 0, volume * number_of_ffts * sizeof(double complex));
2009#pragma omp parallel for collapse(3)
2010 for (int mx = 0; mx < fft_size[0]; mx++) {
2011 for (int my = 0; my < fft_size[1]; my++) {
2012 for (int mz = 0; mz < fft_size[2]; mz++) {
2013 const int index = (mx * fft_size[1] + my) * fft_size[2] + mz;
2014 if (index % test_every != 0)
2015 continue;
2016 const int batch = index / test_every;
2017 output_array[fft3d_index(fft_size, mx, my, mz, batch, number_of_ffts,
2018 transpose)] = 1.0;
2019 }
2020 }
2021 }
2022 fft_3d_local(false, fft_size, number_of_ffts, transpose, transpose,
2023 output_array, input_array);
2024
2025#pragma omp parallel for default(none) firstprivate(test_every) \
2026 firstprivate(transpose) \
2027 shared(input_array, fft_size, pi, volume, number_of_ffts) \
2028 reduction(max : max_error) collapse(3)
2029 for (int mx = 0; mx < fft_size[0]; mx++) {
2030 for (int my = 0; my < fft_size[1]; my++) {
2031 for (int mz = 0; mz < fft_size[2]; mz++) {
2032 const int basis = (mx * fft_size[1] + my) * fft_size[2] + mz;
2033 if (basis % test_every != 0)
2034 continue;
2035 const int batch = basis / test_every;
2036 for (int nx = 0; nx < fft_size[0]; nx++) {
2037 for (int ny = 0; ny < fft_size[1]; ny++) {
2038 for (int nz = 0; nz < fft_size[2]; nz++) {
2039 const double complex my_value = input_array[fft3d_index(
2040 fft_size, nx, ny, nz, batch, number_of_ffts, transpose)];
2041 const double complex ref_value =
2042 cexp(2.0 * I * pi *
2043 (((double)mx) * nx / fft_size[0] +
2044 ((double)my) * ny / fft_size[1] +
2045 ((double)mz) * nz / fft_size[2]));
2046 max_error = fmax(max_error, cabs(my_value - ref_value));
2047 }
2048 }
2049 }
2050 }
2051 }
2052 }
2053 fflush(stdout);
2054
2055 fft_free_complex(input_array);
2056
2057 if (max_error > 1e-12) {
2058 if (my_process == 0) {
2059 printf(
2060 "The bw 3D-FFT (inplace) does not work correctly (%i %i %i): %f!\n",
2061 fft_size[0], fft_size[1], fft_size[2], max_error);
2062 fflush(stdout);
2063 }
2064 errors++;
2065 }
2066
2067 if (errors == 0 && my_process == 0)
2068 printf("The 3D FFT (inplace) does work correctly (%i %i %i)!\n",
2069 fft_size[0], fft_size[1], fft_size[2]);
2070 return errors;
2071}
2072
2073/*******************************************************************************
2074 * \brief Function to test the local FFT backend.
2075 * \param fft_size Size of the transform in each dimension.
2076 * \param test_every Stride selecting the basis vectors to test.
2077 * \param transpose_in Whether the input array uses the transposed layout.
2078 * \param transpose_out Whether the output array uses the transposed layout.
2079 * \author Frederick Stein
2080 ******************************************************************************/
2081int fft_test_3d_local_r2c_low(const int fft_size[3], const int test_every,
2082 const bool transpose_in,
2083 const bool transpose_out) {
2084 cp_assert(test_every > 0);
2085 const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
2086
2087 int errors = 0;
2088
2089 const double pi = acos(-1);
2090 const int volume = product3(fft_size);
2091 const int complex_volume = fft_size[0] * fft_size[1] * (fft_size[2] / 2 + 1);
2092 const int number_of_ffts = (volume + test_every - 1) / test_every;
2093
2094 double *double_buffer = NULL;
2095 double complex *complex_buffer = NULL;
2096 fft_allocate_double(volume * number_of_ffts, &double_buffer);
2097 fft_allocate_complex(complex_volume * number_of_ffts, &complex_buffer);
2098
2099 fft_register_3d_r2c_local(fft_size, number_of_ffts, transpose_in,
2100 transpose_out, double_buffer, complex_buffer);
2101 fft_register_3d_c2r_local(fft_size, number_of_ffts, transpose_out,
2102 transpose_in, complex_buffer, double_buffer);
2103
2104 double max_error = 0.0;
2105 memset(double_buffer, 0, volume * number_of_ffts * sizeof(double));
2106#pragma omp parallel for collapse(3)
2107 for (int mx = 0; mx < fft_size[0]; mx++) {
2108 for (int my = 0; my < fft_size[1]; my++) {
2109 for (int mz = 0; mz < fft_size[2]; mz++) {
2110 const int index = (mx * fft_size[1] + my) * fft_size[2] + mz;
2111 if (index % test_every != 0)
2112 continue;
2113 const int batch = index / test_every;
2114 double_buffer[fft3d_index(fft_size, mx, my, mz, batch, number_of_ffts,
2115 transpose_in)] = 1.0;
2116 }
2117 }
2118 }
2119 fft_3d_r2c_local(fft_size, number_of_ffts, transpose_in, transpose_out,
2120 double_buffer, complex_buffer);
2121
2122#pragma omp parallel for default(none) firstprivate(test_every) \
2123 firstprivate(transpose_in, transpose_out) \
2124 shared(complex_buffer, fft_size, pi, my_process, volume, complex_volume, \
2125 number_of_ffts) reduction(max : max_error) collapse(3)
2126 for (int mx = 0; mx < fft_size[0]; mx++) {
2127 for (int my = 0; my < fft_size[1]; my++) {
2128 for (int mz = 0; mz < fft_size[2]; mz++) {
2129 const int basis = (mx * fft_size[1] + my) * fft_size[2] + mz;
2130 if (basis % test_every != 0)
2131 continue;
2132 const int batch = basis / test_every;
2133 for (int nx = 0; nx < fft_size[0]; nx++) {
2134 for (int ny = 0; ny < fft_size[1]; ny++) {
2135 for (int nz = 0; nz < fft_size[2] / 2 + 1; nz++) {
2136 const double complex my_value =
2137 complex_buffer[fft3d_index_complex(fft_size, nx, ny, nz,
2138 batch, number_of_ffts,
2139 transpose_out)];
2140 const double complex ref_value =
2141 cexp(-2.0 * I * pi *
2142 (((double)mx) * nx / fft_size[0] +
2143 ((double)my) * ny / fft_size[1] +
2144 ((double)mz) * nz / fft_size[2]));
2145 const double current_error = cabs(my_value - ref_value);
2146 if (my_process == 0 && current_error > 1e-6)
2147 printf("ERROR %i %i %i/%i %i %i: (%f %f) (%f %f)\n", nx, ny, nz,
2148 mx, my, mz, creal(my_value), cimag(my_value),
2149 creal(ref_value), cimag(ref_value));
2150 max_error = fmax(max_error, current_error);
2151 }
2152 }
2153 }
2154 }
2155 }
2156 }
2157 fflush(stdout);
2158
2159 if (max_error > 1.0e-6) {
2160 if (my_process == 0) {
2161 printf("The fw R2C 3D-FFT does not work correctly (%i %i %i): %f!\n",
2162 fft_size[0], fft_size[1], fft_size[2], max_error);
2163 fflush(stdout);
2164 }
2165 errors++;
2166 }
2167
2168 max_error = 0.0;
2169#pragma omp parallel for collapse(3)
2170 for (int mx = 0; mx < fft_size[0]; mx++) {
2171 for (int my = 0; my < fft_size[1]; my++) {
2172 for (int mz = 0; mz < fft_size[2]; mz++) {
2173 const int basis = (mx * fft_size[1] + my) * fft_size[2] + mz;
2174 if (basis % test_every != 0)
2175 continue;
2176 const int batch = basis / test_every;
2177 for (int nx = 0; nx < fft_size[0]; nx++) {
2178 for (int ny = 0; ny < fft_size[1]; ny++) {
2179#if defined(__INTEL_LLVM_COMPILER) && __INTEL_LLVM_COMPILER >= 20250200 && \
2180 __INTEL_LLVM_COMPILER < 20260200
2181 // Affected icx versions can overwrite kz=0 when vectorizing.
2182#pragma clang loop vectorize(disable)
2183#endif
2184 for (int nz = 0; nz < fft_size[2] / 2 + 1; nz++) {
2185 complex_buffer[fft3d_index_complex(
2186 fft_size, nx, ny, nz, batch, number_of_ffts, transpose_out)] =
2187 cexp(-2.0 * I * pi *
2188 (((double)mx) * nx / fft_size[0] +
2189 ((double)my) * ny / fft_size[1] +
2190 ((double)mz) * nz / fft_size[2]));
2191 }
2192 }
2193 }
2194 }
2195 }
2196 }
2197 fft_3d_c2r_local(fft_size, number_of_ffts, transpose_out, transpose_in,
2198 complex_buffer, double_buffer);
2199
2200#pragma omp parallel for default(none) firstprivate(test_every) \
2201 firstprivate(transpose_in, transpose_out) \
2202 shared(double_buffer, fft_size, volume, number_of_ffts, my_process) \
2203 reduction(max : max_error) collapse(3)
2204 for (int mx = 0; mx < fft_size[0]; mx++) {
2205 for (int my = 0; my < fft_size[1]; my++) {
2206 for (int mz = 0; mz < fft_size[2]; mz++) {
2207 const int basis = (mx * fft_size[1] + my) * fft_size[2] + mz;
2208 if (basis % test_every != 0)
2209 continue;
2210 const int batch = basis / test_every;
2211 for (int nx = 0; nx < fft_size[0]; nx++) {
2212 for (int ny = 0; ny < fft_size[1]; ny++) {
2213 for (int nz = 0; nz < fft_size[2]; nz++) {
2214 const double my_value = double_buffer[fft3d_index(
2215 fft_size, nx, ny, nz, batch, number_of_ffts, transpose_in)];
2216 const double ref_value =
2217 (nx == mx && ny == my && nz == mz) ? (double)volume : 0.0;
2218 const double current_error = fabs(my_value - ref_value);
2219 if (my_process == 0 && current_error > 1e-6)
2220 printf("ERROR %i %i %i/%i %i %i: %f %f\n", nx, ny, nz, mx, my,
2221 mz, my_value, ref_value);
2222 max_error = fmax(max_error, current_error);
2223 }
2224 }
2225 }
2226 }
2227 }
2228 }
2229 fflush(stdout);
2230
2231 fft_free_double(double_buffer);
2232 fft_free_complex(complex_buffer);
2233
2234 if (max_error > 1e-6) {
2235 if (my_process == 0) {
2236 printf("The bw 3D C2R FFT does not work correctly (%i %i %i): %f!\n",
2237 fft_size[0], fft_size[1], fft_size[2], max_error);
2238 fflush(stdout);
2239 }
2240 errors++;
2241 }
2242
2243 if (errors == 0 && my_process == 0)
2244 printf("The 3D R2C/C2R FFT does work correctly (%i %i %i)!\n", fft_size[0],
2245 fft_size[1], fft_size[2]);
2246 return errors;
2247}
2248
2249/*******************************************************************************
2250 * \brief Function to test the local FFT backend.
2251 * \param fft_size Size of the transform in each dimension.
2252 * \param test_every Stride selecting the basis vectors to test.
2253 * \param transpose Whether the array uses the transposed layout.
2254 * \author Frederick Stein
2255 ******************************************************************************/
2256int fft_test_3d_local_r2c_inplace_low(const int fft_size[3],
2257 const int test_every,
2258 const bool transpose) {
2259 cp_assert(test_every > 0);
2260 const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
2261
2262 int errors = 0;
2263
2264 const double pi = acos(-1);
2265 const int volume = product3(fft_size);
2266 const int complex_volume = fft_size[0] * fft_size[1] * (fft_size[2] / 2 + 1);
2267 const int number_of_ffts = (volume + test_every - 1) / test_every;
2268 const int buffer_size = complex_volume * number_of_ffts;
2269 double *double_buffer = NULL;
2270 fft_allocate_double(2 * buffer_size, &double_buffer);
2271 double complex *complex_buffer = (double complex *)double_buffer;
2272
2273 fft_register_3d_r2c_local(fft_size, number_of_ffts, transpose, transpose,
2274 double_buffer, complex_buffer);
2275 fft_register_3d_c2r_local(fft_size, number_of_ffts, transpose, transpose,
2276 complex_buffer, double_buffer);
2277
2278 double max_error = 0.0;
2279 memset(double_buffer, 0, 2 * buffer_size * sizeof(double));
2280#pragma omp parallel for collapse(3)
2281 for (int mx = 0; mx < fft_size[0]; mx++) {
2282 for (int my = 0; my < fft_size[1]; my++) {
2283 for (int mz = 0; mz < fft_size[2]; mz++) {
2284 const int basis = (mx * fft_size[1] + my) * fft_size[2] + mz;
2285 if (basis % test_every != 0)
2286 continue;
2287 const int batch = basis / test_every;
2288 double_buffer[fft3d_index_padded(fft_size, mx, my, mz, batch,
2289 number_of_ffts, transpose)] = 1.0;
2290 }
2291 }
2292 }
2293 fft_3d_r2c_local(fft_size, number_of_ffts, transpose, transpose,
2294 double_buffer, complex_buffer);
2295
2296#pragma omp parallel for default(none) firstprivate(test_every) \
2297 firstprivate(transpose) shared(complex_buffer, fft_size, pi, my_process, \
2298 complex_volume, number_of_ffts) \
2299 reduction(max : max_error) collapse(3)
2300 for (int mx = 0; mx < fft_size[0]; mx++) {
2301 for (int my = 0; my < fft_size[1]; my++) {
2302 for (int mz = 0; mz < fft_size[2]; mz++) {
2303 const int basis = (mx * fft_size[1] + my) * fft_size[2] + mz;
2304 if (basis % test_every != 0)
2305 continue;
2306 const int batch = basis / test_every;
2307 for (int nx = 0; nx < fft_size[0]; nx++) {
2308 for (int ny = 0; ny < fft_size[1]; ny++) {
2309 for (int nz = 0; nz < fft_size[2] / 2 + 1; nz++) {
2310 const double complex my_value =
2311 complex_buffer[fft3d_index_complex(
2312 fft_size, nx, ny, nz, batch, number_of_ffts, transpose)];
2313 const double complex ref_value =
2314 cexp(-2.0 * I * pi *
2315 (((double)mx) * nx / fft_size[0] +
2316 ((double)my) * ny / fft_size[1] +
2317 ((double)mz) * nz / fft_size[2]));
2318 const double current_error = cabs(my_value - ref_value);
2319 if (my_process == 0 && current_error > 1e-6)
2320 printf("ERROR %i %i %i/%i %i %i: (%f %f) (%f %f)\n", nx, ny, nz,
2321 mx, my, mz, creal(my_value), cimag(my_value),
2322 creal(ref_value), cimag(ref_value));
2323 max_error = fmax(max_error, current_error);
2324 }
2325 }
2326 }
2327 }
2328 }
2329 }
2330 fflush(stdout);
2331
2332 if (max_error > 1.0e-6) {
2333 if (my_process == 0) {
2334 printf("The fw R2C 3D-FFT (inplace) does not work correctly (%i %i %i): "
2335 "%f!\n",
2336 fft_size[0], fft_size[1], fft_size[2], max_error);
2337 fflush(stdout);
2338 }
2339 errors++;
2340 }
2341
2342 max_error = 0.0;
2343#pragma omp parallel for collapse(3)
2344 for (int mx = 0; mx < fft_size[0]; mx++) {
2345 for (int my = 0; my < fft_size[1]; my++) {
2346 for (int mz = 0; mz < fft_size[2]; mz++) {
2347 const int basis = (mx * fft_size[1] + my) * fft_size[2] + mz;
2348 if (basis % test_every != 0)
2349 continue;
2350 const int batch = basis / test_every;
2351 for (int nx = 0; nx < fft_size[0]; nx++) {
2352 for (int ny = 0; ny < fft_size[1]; ny++) {
2353#if defined(__INTEL_LLVM_COMPILER) && __INTEL_LLVM_COMPILER >= 20250200 && \
2354 __INTEL_LLVM_COMPILER < 20260200
2355 // Affected icx versions can overwrite kz=0 when vectorizing.
2356#pragma clang loop vectorize(disable)
2357#endif
2358 for (int nz = 0; nz < fft_size[2] / 2 + 1; nz++) {
2359 complex_buffer[fft3d_index_complex(fft_size, nx, ny, nz, batch,
2360 number_of_ffts, transpose)] =
2361 cexp(-2.0 * I * pi *
2362 (((double)mx) * nx / fft_size[0] +
2363 ((double)my) * ny / fft_size[1] +
2364 ((double)mz) * nz / fft_size[2]));
2365 }
2366 }
2367 }
2368 }
2369 }
2370 }
2371 fft_3d_c2r_local(fft_size, number_of_ffts, transpose, transpose,
2372 complex_buffer, double_buffer);
2373
2374#pragma omp parallel for default(none) firstprivate(test_every) \
2375 firstprivate(transpose) \
2376 shared(double_buffer, fft_size, volume, complex_volume, number_of_ffts, \
2377 my_process) reduction(max : max_error) collapse(3)
2378 for (int mx = 0; mx < fft_size[0]; mx++) {
2379 for (int my = 0; my < fft_size[1]; my++) {
2380 for (int mz = 0; mz < fft_size[2]; mz++) {
2381 const int basis = (mx * fft_size[1] + my) * fft_size[2] + mz;
2382 if (basis % test_every != 0)
2383 continue;
2384 const int batch = basis / test_every;
2385 for (int nx = 0; nx < fft_size[0]; nx++) {
2386 for (int ny = 0; ny < fft_size[1]; ny++) {
2387 for (int nz = 0; nz < fft_size[2]; nz++) {
2388 const double my_value = double_buffer[fft3d_index_padded(
2389 fft_size, nx, ny, nz, batch, number_of_ffts, transpose)];
2390 const double ref_value =
2391 (nx == mx && ny == my && nz == mz) ? (double)volume : 0.0;
2392 const double current_error = fabs(my_value - ref_value);
2393 if (my_process == 0 && current_error > 1e-6)
2394 printf("ERROR %i %i %i/%i %i %i: %f %f\n", nx, ny, nz, mx, my,
2395 mz, my_value, ref_value);
2396 max_error = fmax(max_error, current_error);
2397 }
2398 }
2399 }
2400 }
2401 }
2402 }
2403 fflush(stdout);
2404
2405 fft_free_double(double_buffer);
2406
2407 if (max_error > 1e-6) {
2408 if (my_process == 0) {
2409 printf("The bw 3D C2R FFT (inplace) does not work correctly (%i %i %i): "
2410 "%f!\n",
2411 fft_size[0], fft_size[1], fft_size[2], max_error);
2412 fflush(stdout);
2413 }
2414 errors++;
2415 }
2416
2417 if (errors == 0 && my_process == 0)
2418 printf("The 3D R2C/C2R FFT (inplace) does work correctly (%i %i %i)!\n",
2419 fft_size[0], fft_size[1], fft_size[2]);
2420 return errors;
2421}
2422
2423/*******************************************************************************
2424 * \brief Test concurrent 1D C2C FFTs from independent OpenMP threads.
2425 * \author Frederick Stein
2426 ******************************************************************************/
2428 const int fft_size = 15;
2429 const int number_of_ffts = 2;
2430 int errors = 0;
2431
2432#pragma omp parallel default(none) shared(errors, fft_size, number_of_ffts)
2433 {
2434 const int thread_id = omp_get_thread_num();
2435 double complex *input = NULL, *output = NULL, *reference = NULL;
2436 fft_allocate_complex(fft_size * number_of_ffts, &input);
2437 fft_allocate_complex(fft_size * number_of_ffts, &output);
2438 fft_allocate_complex(fft_size * number_of_ffts, &reference);
2439 fft_register_1d_local(true, fft_size, number_of_ffts, false, false,
2440 fft_size, fft_size, input, output);
2441 fft_register_1d_local(false, fft_size, number_of_ffts, false, false,
2442 fft_size, fft_size, output, input);
2443
2444 for (int i = 0; i < fft_size * number_of_ffts; i++)
2445 input[i] = cexp(I * (0.11 * (i + 1) + 0.37 * thread_id));
2446 memcpy(reference, input,
2447 fft_size * number_of_ffts * sizeof(double complex));
2448
2449 fft_1d_local(true, fft_size, number_of_ffts, false, false, fft_size,
2450 fft_size, input, output);
2451 fft_1d_local(false, fft_size, number_of_ffts, false, false, fft_size,
2452 fft_size, output, input);
2453
2454 int thread_errors = 0;
2455 for (int i = 0; i < fft_size * number_of_ffts; i++)
2456 if (cabs(input[i] - (double)fft_size * reference[i]) > 1.0E-8)
2457 thread_errors = 1;
2458
2459 fft_free_complex(input);
2460 fft_free_complex(output);
2461 fft_free_complex(reference);
2462#pragma omp atomic
2463 errors += thread_errors;
2464 }
2465 return errors;
2466}
2467
2468/*******************************************************************************
2469 * \brief Test concurrent 1D R2C/C2R FFTs from independent OpenMP threads.
2470 * \author Frederick Stein
2471 ******************************************************************************/
2473 const int fft_size = 15;
2474 const int number_of_ffts = 2;
2475 const int complex_size = fft_size / 2 + 1;
2476 int errors = 0;
2477
2478#pragma omp parallel default(none) \
2479 shared(errors, fft_size, number_of_ffts, complex_size)
2480 {
2481 const int thread_id = omp_get_thread_num();
2482 double *input = NULL, *reference = NULL;
2483 double complex *output = NULL;
2484 fft_allocate_double(fft_size * number_of_ffts, &input);
2485 fft_allocate_double(fft_size * number_of_ffts, &reference);
2486 fft_allocate_complex(complex_size * number_of_ffts, &output);
2487 fft_register_1d_r2c_local(fft_size, number_of_ffts, false, false, fft_size,
2488 complex_size, input, output);
2489 fft_register_1d_c2r_local(fft_size, number_of_ffts, false, false,
2490 complex_size, fft_size, output, input);
2491
2492 for (int i = 0; i < fft_size * number_of_ffts; i++)
2493 input[i] = sin(0.13 * (i + 1) + 0.29 * thread_id);
2494 memcpy(reference, input, fft_size * number_of_ffts * sizeof(double));
2495
2496 fft_1d_r2c_local(fft_size, number_of_ffts, false, false, fft_size,
2497 complex_size, input, output);
2498 fft_1d_c2r_local(fft_size, number_of_ffts, false, false, complex_size,
2499 fft_size, output, input);
2500
2501 int thread_errors = 0;
2502 for (int i = 0; i < fft_size * number_of_ffts; i++)
2503 if (fabs(input[i] - (double)fft_size * reference[i]) > 1.0E-8)
2504 thread_errors = 1;
2505
2506 fft_free_double(input);
2507 fft_free_double(reference);
2508 fft_free_complex(output);
2509#pragma omp atomic
2510 errors += thread_errors;
2511 }
2512 return errors;
2513}
2514
2515/*******************************************************************************
2516 * \brief Test concurrent 2D C2C FFTs from independent OpenMP threads.
2517 * \author Frederick Stein
2518 ******************************************************************************/
2520 const int fft_size[2] = {8, 9};
2521 const int number_of_ffts = 2;
2522 const int total_size = fft_size[0] * fft_size[1] * number_of_ffts;
2523 int errors = 0;
2524
2525#pragma omp parallel default(none) \
2526 shared(errors, fft_size, number_of_ffts, total_size)
2527 {
2528 const int thread_id = omp_get_thread_num();
2529 double complex *input = NULL, *output = NULL, *reference = NULL;
2530 fft_allocate_complex(total_size, &input);
2531 fft_allocate_complex(total_size, &output);
2532 fft_allocate_complex(total_size, &reference);
2533 fft_register_2d_local(true, fft_size, number_of_ffts, false, false, input,
2534 output);
2535 fft_register_2d_local(false, fft_size, number_of_ffts, false, false, output,
2536 input);
2537
2538 for (int i = 0; i < total_size; i++)
2539 input[i] = cexp(I * (0.09 * (i + 1) + 0.31 * thread_id));
2540 memcpy(reference, input, total_size * sizeof(double complex));
2541
2542 fft_2d_local(true, fft_size, number_of_ffts, false, false, input, output);
2543 fft_2d_local(false, fft_size, number_of_ffts, false, false, output, input);
2544
2545 int thread_errors = 0;
2546 for (int i = 0; i < total_size; i++)
2547 if (cabs(input[i] - (double)(fft_size[0] * fft_size[1]) * reference[i]) >
2548 1.0E-8)
2549 thread_errors = 1;
2550
2551 fft_free_complex(input);
2552 fft_free_complex(output);
2553 fft_free_complex(reference);
2554#pragma omp atomic
2555 errors += thread_errors;
2556 }
2557 return errors;
2558}
2559
2560/*******************************************************************************
2561 * \brief Test concurrent 2D R2C/C2R FFTs from independent OpenMP threads.
2562 * \author Frederick Stein
2563 ******************************************************************************/
2565 const int fft_size[2] = {8, 9};
2566 const int number_of_ffts = 2;
2567 const int real_size = fft_size[0] * fft_size[1] * number_of_ffts;
2568 const int complex_size = fft_size[0] * (fft_size[1] / 2 + 1) * number_of_ffts;
2569 int errors = 0;
2570
2571#pragma omp parallel default(none) \
2572 shared(errors, fft_size, number_of_ffts, real_size, complex_size)
2573 {
2574 const int thread_id = omp_get_thread_num();
2575 double *input = NULL, *reference = NULL;
2576 double complex *output = NULL;
2577 fft_allocate_double(real_size, &input);
2578 fft_allocate_double(real_size, &reference);
2579 fft_allocate_complex(complex_size, &output);
2580 fft_register_2d_r2c_local(fft_size, number_of_ffts, false, false, input,
2581 output);
2582 fft_register_2d_c2r_local(fft_size, number_of_ffts, false, false, output,
2583 input);
2584
2585 for (int i = 0; i < real_size; i++)
2586 input[i] = cos(0.08 * (i + 1) + 0.23 * thread_id);
2587 memcpy(reference, input, real_size * sizeof(double));
2588
2589 fft_2d_r2c_local(fft_size, number_of_ffts, false, false, input, output);
2590 fft_2d_c2r_local(fft_size, number_of_ffts, false, false, output, input);
2591
2592 int thread_errors = 0;
2593 for (int i = 0; i < real_size; i++)
2594 if (fabs(input[i] - (double)(fft_size[0] * fft_size[1]) * reference[i]) >
2595 1.0E-8)
2596 thread_errors = 1;
2597
2598 fft_free_double(input);
2599 fft_free_double(reference);
2600 fft_free_complex(output);
2601#pragma omp atomic
2602 errors += thread_errors;
2603 }
2604 return errors;
2605}
2606
2607/*******************************************************************************
2608 * \brief Test concurrent 3D C2C FFTs from independent OpenMP threads.
2609 * \author Frederick Stein
2610 ******************************************************************************/
2612 const int fft_size[3] = {5, 4, 6};
2613 const int number_of_ffts = 2;
2614 const int total_size =
2615 fft_size[0] * fft_size[1] * fft_size[2] * number_of_ffts;
2616 int errors = 0;
2617
2618#pragma omp parallel default(none) \
2619 shared(errors, fft_size, number_of_ffts, total_size)
2620 {
2621 const int thread_id = omp_get_thread_num();
2622 double complex *input = NULL, *output = NULL, *reference = NULL;
2623 fft_allocate_complex(total_size, &input);
2624 fft_allocate_complex(total_size, &output);
2625 fft_allocate_complex(total_size, &reference);
2626 fft_register_3d_local(true, fft_size, number_of_ffts, false, false, input,
2627 output);
2628 fft_register_3d_local(false, fft_size, number_of_ffts, false, false, output,
2629 input);
2630
2631 for (int i = 0; i < total_size; i++)
2632 input[i] = cexp(I * (0.07 * (i + 1) + 0.27 * thread_id));
2633 memcpy(reference, input, total_size * sizeof(double complex));
2634
2635 fft_3d_local(true, fft_size, number_of_ffts, false, false, input, output);
2636 fft_3d_local(false, fft_size, number_of_ffts, false, false, output, input);
2637
2638 int thread_errors = 0;
2639 for (int i = 0; i < total_size; i++)
2640 if (cabs(input[i] - (double)(fft_size[0] * fft_size[1] * fft_size[2]) *
2641 reference[i]) > 1.0E-8)
2642 thread_errors = 1;
2643
2644 fft_free_complex(input);
2645 fft_free_complex(output);
2646 fft_free_complex(reference);
2647#pragma omp atomic
2648 errors += thread_errors;
2649 }
2650 return errors;
2651}
2652
2653/*******************************************************************************
2654 * \brief Test concurrent 3D R2C/C2R FFTs from independent OpenMP threads.
2655 * \author Frederick Stein
2656 ******************************************************************************/
2658 const int fft_size[3] = {5, 4, 6};
2659 const int number_of_ffts = 2;
2660 const int real_size =
2661 fft_size[0] * fft_size[1] * fft_size[2] * number_of_ffts;
2662 const int complex_size =
2663 fft_size[0] * fft_size[1] * (fft_size[2] / 2 + 1) * number_of_ffts;
2664 int errors = 0;
2665
2666#pragma omp parallel default(none) \
2667 shared(errors, fft_size, number_of_ffts, real_size, complex_size)
2668 {
2669 const int thread_id = omp_get_thread_num();
2670 double *input = NULL, *reference = NULL;
2671 double complex *output = NULL;
2672 fft_allocate_double(real_size, &input);
2673 fft_allocate_double(real_size, &reference);
2674 fft_allocate_complex(complex_size, &output);
2675 fft_register_3d_r2c_local(fft_size, number_of_ffts, false, false, input,
2676 output);
2677 fft_register_3d_c2r_local(fft_size, number_of_ffts, false, false, output,
2678 input);
2679
2680 for (int i = 0; i < real_size; i++)
2681 input[i] = sin(0.06 * (i + 1) + 0.19 * thread_id);
2682 memcpy(reference, input, real_size * sizeof(double));
2683
2684 fft_3d_r2c_local(fft_size, number_of_ffts, false, false, input, output);
2685 fft_3d_c2r_local(fft_size, number_of_ffts, false, false, output, input);
2686
2687 int thread_errors = 0;
2688 for (int i = 0; i < real_size; i++)
2689 if (fabs(input[i] - (double)(fft_size[0] * fft_size[1] * fft_size[2]) *
2690 reference[i]) > 1.0E-8)
2691 thread_errors = 1;
2692
2693 fft_free_double(input);
2694 fft_free_double(reference);
2695 fft_free_complex(output);
2696#pragma omp atomic
2697 errors += thread_errors;
2698 }
2699 return errors;
2700}
2701
2702/*******************************************************************************
2703 * \brief Function to test the local FFT backend (1-3D).
2704 * \author Frederick Stein
2705 ******************************************************************************/
2707 int errors = 0;
2708
2709 clock_t begin = clock();
2710 errors += fft_test_1d_local_low(15, 13, true, true);
2711 errors += fft_test_1d_local_low(9, 11, true, false);
2712 errors += fft_test_1d_local_low(10, 14, false, true);
2713 errors += fft_test_1d_local_low(14, 13, false, false);
2714
2715 errors += fft_test_1d_local_inplace_low(15, 13, true);
2716 errors += fft_test_1d_local_inplace_low(14, 13, false);
2717
2718 errors += fft_test_1d_local_r2c_low(15, 13, true, false);
2719 errors += fft_test_1d_local_r2c_low(9, 11, false, false);
2720 errors += fft_test_1d_local_r2c_low(10, 14, false, true);
2721 errors += fft_test_1d_local_r2c_low(14, 13, true, true);
2722
2723 errors += fft_test_1d_local_r2c_inplace_low(15, 11, false);
2724 errors += fft_test_1d_local_r2c_inplace_low(14, 13, true);
2725
2726 errors += fft_test_2d_local_low((const int[2]){10, 10}, 10, true, true);
2727 errors += fft_test_2d_local_low((const int[2]){8, 9}, 10, true, false);
2728 errors += fft_test_2d_local_low((const int[2]){7, 10}, 11, false, true);
2729 errors += fft_test_2d_local_low((const int[2]){6, 7}, 10, false, false);
2730
2731 errors += fft_test_2d_local_inplace_low((const int[2]){8, 9}, 10, true);
2732 errors += fft_test_2d_local_inplace_low((const int[2]){7, 10}, 11, false);
2733
2734 errors += fft_test_2d_local_r2c_low((const int[2]){10, 10}, 10, true, true);
2735 errors += fft_test_2d_local_r2c_low((const int[2]){8, 9}, 10, true, false);
2736 errors += fft_test_2d_local_r2c_low((const int[2]){7, 10}, 10, false, true);
2737 errors += fft_test_2d_local_r2c_low((const int[2]){6, 7}, 11, false, false);
2738
2739 errors += fft_test_2d_local_r2c_inplace_low((const int[2]){8, 9}, 10, true);
2740 errors += fft_test_2d_local_r2c_inplace_low((const int[2]){7, 10}, 10, false);
2741
2742 // Reduce tests to ca 10 per set
2743 errors += fft_test_3d_local_low((const int[3]){8, 8, 8}, 10, false, false);
2744 errors += fft_test_3d_local_low((const int[3]){7, 5, 3}, 10, true, true);
2745
2746 errors += fft_test_3d_local_inplace_low((const int[3]){8, 8, 8}, 10, false);
2747 errors += fft_test_3d_local_inplace_low((const int[3]){7, 5, 3}, 10, true);
2748
2749 errors +=
2750 fft_test_3d_local_r2c_low((const int[3]){8, 8, 8}, 10, false, false);
2751 errors += fft_test_3d_local_r2c_low((const int[3]){7, 5, 3}, 10, true, true);
2752
2753 errors +=
2754 fft_test_3d_local_r2c_inplace_low((const int[3]){8, 8, 8}, 10, false);
2755 errors +=
2756 fft_test_3d_local_r2c_inplace_low((const int[3]){7, 5, 3}, 10, true);
2757
2758 errors += fft_test_1d_local_omp();
2759 errors += fft_test_1d_local_omp_r2c();
2760 errors += fft_test_2d_local_omp();
2761 errors += fft_test_2d_local_omp_r2c();
2762 errors += fft_test_3d_local_omp();
2763 errors += fft_test_3d_local_omp_r2c();
2764
2765 clock_t end = clock();
2767 printf("Time to test local FFTs: %f\n",
2768 (double)(end - begin) / CLOCKS_PER_SEC);
2769
2770 return errors;
2771}
2772
2773// EOF
#define cp_assert(condition)
Definition cp_assert.h:22
cp_mpi_comm_t cp_mpi_get_comm_world(void)
Returns MPI_COMM_WORLD.
Definition cp_mpi.c:138
int cp_mpi_comm_rank(const cp_mpi_comm_t comm)
Wrapper around MPI_Comm_rank.
Definition cp_mpi.c:191
void fft_3d_r2c_local(const int fft_size[3], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double *grid_in, double complex *grid_out)
Perform a local 3D R2C FFT.
Definition fft_lib.c:712
void fft_2d_r2c_local(const int fft_size[2], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double *grid_in, double complex *grid_out)
Perform a local 2D R2C FFT.
Definition fft_lib.c:630
void fft_1d_local(const bool dir, const int fft_size, const int number_of_ffts, const bool transpose_in, const bool transpose_out, const int leading_dimension_in, const int leading_dimension_out, double complex *grid_in, double complex *grid_out)
Perform a local 1D FFT.
Definition fft_lib.c:506
void fft_1d_r2c_local(const int fft_size, const int number_of_ffts, const bool transpose_in, const bool transpose_out, const int leading_dimension_in, const int leading_dimension_out, double *grid_in, double complex *grid_out)
Perform a local 1D R2C FFT.
Definition fft_lib.c:538
void fft_register_1d_r2c_local(const int fft_size, const int number_of_ffts, const bool transpose_in, const bool transpose_out, const int leading_dimension_in, const int leading_dimension_out, double *grid_in, double complex *grid_out)
Register a local 1D R2C FFT.
Definition fft_lib.c:266
void fft_2d_local(const bool dir, const int fft_size[2], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double complex *grid_in, double complex *grid_out)
Perform a local 2D FFT.
Definition fft_lib.c:603
void fft_register_2d_r2c_local(const int fft_size[2], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double *grid_in, double complex *grid_out)
Register a local 2D R2C FFT.
Definition fft_lib.c:361
void fft_register_2d_c2r_local(const int fft_size[2], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double complex *grid_in, double *grid_out)
Register a local 2D C2R FFT.
Definition fft_lib.c:389
void fft_free_complex(double complex *buffer)
Allocate buffer of type double complex.
Definition fft_lib.c:210
void fft_register_1d_local(const bool dir, const int fft_size, const int number_of_ffts, const bool transpose_in, const bool transpose_out, const int leading_dimension_in, const int leading_dimension_out, double complex *grid_in, double complex *grid_out)
Register a local 1D C2C FFT.
Definition fft_lib.c:233
void fft_2d_c2r_local(const int fft_size[2], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double complex *grid_in, double *grid_out)
Perform a local 2D C2R FFT.
Definition fft_lib.c:657
void fft_free_double(double *buffer)
Allocate buffer of type double.
Definition fft_lib.c:195
void fft_3d_c2r_local(const int fft_size[3], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double complex *grid_in, double *grid_out)
Perform a local 3D C2R FFT.
Definition fft_lib.c:739
void fft_allocate_double(const int length, double **buffer)
Allocate buffer of type double.
Definition fft_lib.c:174
void fft_register_3d_local(const bool dir, const int fft_size[3], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double complex *grid_in, double complex *grid_out)
Register a local 3D FFT.
Definition fft_lib.c:420
void fft_3d_local(const bool dir, const int fft_size[3], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double complex *grid_in, double complex *grid_out)
Perform a local 3D FFT.
Definition fft_lib.c:685
void fft_register_2d_local(const bool dir, const int fft_size[2], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double complex *grid_in, double complex *grid_out)
Register a local 2D FFT.
Definition fft_lib.c:333
void fft_1d_c2r_local(const int fft_size, const int number_of_ffts, const bool transpose_in, const bool transpose_out, const int leading_dimension_in, const int leading_dimension_out, double complex *grid_in, double *grid_out)
Perform a local 1D C2R FFT.
Definition fft_lib.c:571
void fft_register_1d_c2r_local(const int fft_size, const int number_of_ffts, const bool transpose_in, const bool transpose_out, const int leading_dimension_in, const int leading_dimension_out, double complex *grid_in, double *grid_out)
Register a local 1D C2R FFT.
Definition fft_lib.c:300
void fft_register_3d_c2r_local(const int fft_size[3], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double complex *grid_in, double *grid_out)
Register a local 3D C2R FFT.
Definition fft_lib.c:475
void fft_register_3d_r2c_local(const int fft_size[3], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double *grid_in, double complex *grid_out)
Register a local 3D R2C FFT.
Definition fft_lib.c:447
void fft_allocate_complex(const int length, double complex **buffer)
Allocate buffer of type double complex.
Definition fft_lib.c:185
int fft_test_1d_local_r2c_inplace_low(const int fft_size, const int number_of_ffts, const int transpose)
Function to test the local FFT backend.
int fft_test_1d_local_r2c_low(const int fft_size, const int number_of_ffts, const int transpose_rs, const int transpose_gs)
Function to test the local FFT backend.
int fft_test_3d_local_r2c_low(const int fft_size[3], const int test_every, const bool transpose_in, const bool transpose_out)
Function to test the local FFT backend.
int fft_test_2d_local_inplace_low(const int fft_size[2], const int number_of_ffts, const int transpose)
Function to test the local FFT backend.
int fft_test_local()
Function to test the local FFT backend (1-3D).
static int fft3d_index_complex(const int fft_size[3], const int x, const int y, const int z, const int batch, const int number_of_ffts, const bool transpose)
Compute the linear index of a point in a batched 3D complex half-spectrum grid.
int fft_test_2d_local_omp(void)
Test concurrent 2D C2C FFTs from independent OpenMP threads.
int fft_test_2d_local_r2c_low(const int fft_size[2], const int number_of_ffts, const int transpose_rs, const int transpose_gs)
Function to test the local FFT backend.
int fft_test_3d_local_low(const int fft_size[3], const int test_every, const bool transpose_in, const bool transpose_out)
Function to test the local FFT backend.
int fft_test_1d_local_inplace_low(const int fft_size, const int number_of_ffts, const int transpose)
Function to test the local FFT backend (inplace).
int fft_test_3d_local_inplace_low(const int fft_size[3], const int test_every, const bool transpose)
Function to test the local FFT backend.
static int fft3d_index_padded(const int fft_size[3], const int x, const int y, const int z, const int batch, const int number_of_ffts, const bool transpose)
Compute the linear index of a point in a padded batched 3D grid.
int fft_test_3d_local_omp_r2c(void)
Test concurrent 3D R2C/C2R FFTs from independent OpenMP threads.
int fft_test_3d_local_omp(void)
Test concurrent 3D C2C FFTs from independent OpenMP threads.
int fft_test_3d_local_r2c_inplace_low(const int fft_size[3], const int test_every, const bool transpose)
Function to test the local FFT backend.
int fft_test_2d_local_omp_r2c(void)
Test concurrent 2D R2C/C2R FFTs from independent OpenMP threads.
int fft_test_1d_local_omp_r2c(void)
Test concurrent 1D R2C/C2R FFTs from independent OpenMP threads.
int fft_test_1d_local_low(const int fft_size, const int number_of_ffts, const int transpose_rs, const int transpose_gs)
Function to test the local FFT backend.
static int fft3d_index(const int fft_size[3], const int x, const int y, const int z, const int batch, const int number_of_ffts, const bool transpose)
Compute the linear index of a point in a batched 3D grid.
int fft_test_2d_local_r2c_inplace_low(const int fft_size[2], const int number_of_ffts, const int transpose)
Function to test the local FFT backend.
int fft_test_2d_local_low(const int fft_size[2], const int number_of_ffts, const int transpose_rs, const int transpose_gs)
Function to test the local FFT backend.
int fft_test_1d_local_omp(void)
Test concurrent 1D C2C FFTs from independent OpenMP threads.
static long int product3(const int array3[3])
Calculates the product of three numbers.
Definition fft_utils.h:66
static void const int const int i