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;
38 ? spatial * number_of_ffts + batch
39 : batch * (fft_size[0] * fft_size[1] * fft_size[2]) + spatial;
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;
60 ? spatial * number_of_ffts + batch
61 : batch * (fft_size[0] * fft_size[1] * (fft_size[2] / 2 + 1)) +
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;
82 ? spatial * number_of_ffts + batch
83 : batch * (2 * fft_size[0] * fft_size[1] * (fft_size[2] / 2 + 1)) +
97 const int transpose_rs,
const int transpose_gs) {
102 const double pi = acos(-1);
104 double complex *input_array = NULL, *output_array = NULL;
109 transpose_gs, transpose_rs ? number_of_ffts : fft_size,
110 transpose_gs ? number_of_ffts : fft_size, input_array,
113 transpose_rs, transpose_gs ? number_of_ffts : fft_size,
114 transpose_rs ? number_of_ffts : fft_size, output_array,
117 memset(input_array, 0, fft_size * number_of_ffts *
sizeof(
double complex));
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;
125 input_array[(number_of_fft % fft_size) * number_of_ffts + number_of_fft] =
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;
133 input_array[(number_of_fft % fft_size) + number_of_fft * fft_size] = 1.0;
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,
142 double max_error = 0.0;
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;
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);
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;
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);
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);
194 memset(output_array, 0, fft_size * number_of_ffts *
sizeof(
double complex));
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;
201 output_array[number_of_fft + number_of_fft % fft_size * number_of_ffts] =
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;
209 output_array[number_of_fft * fft_size + number_of_fft % fft_size] = 1.0;
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,
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;
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);
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;
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);
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);
272 if (errors == 0 && my_process == 0)
273 printf(
"The 1D FFT does work correctly (%i %i)!\n", fft_size,
286 const int transpose) {
291 const double pi = acos(-1);
293 double complex *input_array = NULL;
297 transpose ? number_of_ffts : fft_size,
298 transpose ? number_of_ffts : fft_size, input_array,
301 transpose ? number_of_ffts : fft_size,
302 transpose ? number_of_ffts : fft_size, input_array,
305 memset(input_array, 0, fft_size * number_of_ffts *
sizeof(
double complex));
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;
313 input_array[(number_of_fft % fft_size) * number_of_ffts + number_of_fft] =
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;
321 input_array[(number_of_fft % fft_size) + number_of_fft * fft_size] = 1.0;
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);
329 double max_error = 0.0;
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;
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);
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;
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);
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);
381 memset(input_array, 0, fft_size * number_of_ffts *
sizeof(
double complex));
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;
388 input_array[number_of_fft + number_of_fft % fft_size * number_of_ffts] =
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;
396 input_array[number_of_fft * fft_size + number_of_fft % fft_size] = 1.0;
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);
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;
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);
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;
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);
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);
457 if (errors == 0 && my_process == 0)
458 printf(
"The 1D FFT (inplace) does work correctly (%i %i)!\n", fft_size,
473 const int transpose_rs,
const int transpose_gs) {
478 const double pi = acos(-1);
480 double *input_array = NULL;
481 double complex *output_array = NULL;
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);
495 memset(input_array, 0, fft_size * number_of_ffts *
sizeof(
double));
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;
502 input_array[(number_of_fft % fft_size) * number_of_ffts + number_of_fft] =
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;
510 input_array[(number_of_fft % fft_size) + number_of_fft * fft_size] = 1.0;
515 transpose_rs ? number_of_ffts : fft_size,
516 transpose_gs ? number_of_ffts : fft_size / 2 + 1,
517 input_array, output_array);
519 double max_error = 0.0;
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;
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);
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;
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);
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);
571 memset(output_array, 0,
572 (fft_size / 2 + 1) * number_of_ffts *
sizeof(
double complex));
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;
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);
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;
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);
597 transpose_gs ? number_of_ffts : fft_size / 2 + 1,
598 transpose_rs ? number_of_ffts : fft_size, output_array,
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;
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);
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;
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);
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);
652 if (errors == 0 && my_process == 0)
653 printf(
"The 1D R/C FFT does work correctly (%i %i)!\n", fft_size,
666 const int number_of_ffts,
667 const int transpose) {
672 const double pi = acos(-1);
674 double *input_array = NULL;
676 double complex *output_array = (
double complex *)input_array;
679 transpose ? number_of_ffts : 2 * (fft_size / 2 + 1),
680 transpose ? number_of_ffts : fft_size / 2 + 1,
681 input_array, output_array);
683 transpose ? number_of_ffts : fft_size / 2 + 1,
684 transpose ? number_of_ffts : 2 * (fft_size / 2 + 1),
685 output_array, input_array);
687 memset(input_array, 0,
688 2 * (fft_size / 2 + 1) * number_of_ffts *
sizeof(
double));
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;
695 input_array[(number_of_fft % fft_size) * number_of_ffts + number_of_fft] =
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;
703 input_array[(number_of_fft % fft_size) +
704 number_of_fft * 2 * (fft_size / 2 + 1)] = 1.0;
709 transpose ? number_of_ffts : 2 * (fft_size / 2 + 1),
710 transpose ? number_of_ffts : fft_size / 2 + 1, input_array,
713 double max_error = 0.0;
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;
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);
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;
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);
755 if (max_error > 1.0e-8) {
756 if (my_process == 0) {
758 "The fw R2C 1D-FFT (inplace) does not work correctly (%i %i): %f!\n",
759 fft_size, number_of_ffts, max_error);
766 memset(output_array, 0,
767 (fft_size / 2 + 1) * number_of_ffts *
sizeof(
double complex));
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;
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);
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;
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);
792 transpose ? number_of_ffts : fft_size / 2 + 1,
793 transpose ? number_of_ffts : 2 * (fft_size / 2 + 1),
794 output_array, input_array);
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;
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);
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;
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);
836 if (max_error > 1e-8) {
837 if (my_process == 0) {
839 "The bw C2R-1D FFT (inplace) does not work correctly (%i %i): %f!\n",
840 fft_size, number_of_ffts, max_error);
848 if (errors == 0 && my_process == 0)
849 printf(
"The 1D R2C FFT (inplace) does work correctly (%i %i)!\n", fft_size,
864 const int transpose_rs,
const int transpose_gs) {
869 const double pi = acos(-1);
871 double complex *input_array = NULL, *output_array = NULL;
872 const int elements_per_fft = fft_size[0] * fft_size[1];
877 transpose_gs, input_array, output_array);
879 transpose_rs, output_array, input_array);
881 memset(input_array, 0,
882 elements_per_fft * number_of_ffts *
sizeof(
double complex));
883 double max_error = 0.0;
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;
890 input_array[number_of_fft % elements_per_fft * number_of_ffts +
891 number_of_fft] = 1.0;
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;
898 input_array[number_of_fft % elements_per_fft +
899 number_of_fft * elements_per_fft] = 1.0;
903 fft_2d_local(
true, fft_size, number_of_ffts, transpose_rs, transpose_gs,
904 input_array, output_array);
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;
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(
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);
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;
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) *
943 const double complex ref_value = cexp(
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);
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);
970 memset(output_array, 0,
971 elements_per_fft * number_of_ffts *
sizeof(
double complex));
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;
978 output_array[number_of_fft +
979 (number_of_fft % elements_per_fft) * number_of_ffts] = 1.0;
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;
986 output_array[number_of_fft * elements_per_fft +
987 number_of_fft % elements_per_fft] = 1.0;
991 fft_2d_local(
false, fft_size, number_of_ffts, transpose_gs, transpose_rs,
992 output_array, input_array);
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;
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 +
1006 const double complex ref_value = cexp(
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);
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;
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(
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);
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);
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);
1072 const int number_of_ffts,
1073 const int transpose) {
1078 const double pi = acos(-1);
1080 double complex *input_array = NULL;
1081 const int elements_per_fft = fft_size[0] * fft_size[1];
1083 double complex *output_array = input_array;
1086 input_array, output_array);
1088 output_array, input_array);
1090 memset(input_array, 0,
1091 elements_per_fft * number_of_ffts *
sizeof(
double complex));
1092 double max_error = 0.0;
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;
1099 input_array[number_of_fft % elements_per_fft * number_of_ffts +
1100 number_of_fft] = 1.0;
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;
1107 input_array[number_of_fft % elements_per_fft +
1108 number_of_fft * elements_per_fft] = 1.0;
1112 fft_2d_local(
true, fft_size, number_of_ffts, transpose, transpose,
1113 input_array, output_array);
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;
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(
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);
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;
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) *
1152 const double complex ref_value = cexp(
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);
1169 if (max_error > 1.0e-3) {
1170 if (my_process == 0) {
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);
1180 memset(output_array, 0,
1181 elements_per_fft * number_of_ffts *
sizeof(
double complex));
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;
1188 output_array[number_of_fft +
1189 (number_of_fft % elements_per_fft) * number_of_ffts] = 1.0;
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;
1196 output_array[number_of_fft * elements_per_fft +
1197 number_of_fft % elements_per_fft] = 1.0;
1201 fft_2d_local(
false, fft_size, number_of_ffts, transpose, transpose,
1202 output_array, input_array);
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;
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 +
1216 const double complex ref_value = cexp(
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);
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;
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(
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);
1258 if (max_error > 1e-12) {
1259 if (my_process == 0) {
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);
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);
1284 const int transpose_rs,
const int transpose_gs) {
1289 const double pi = acos(-1);
1291 double *real_buffer = NULL;
1292 double complex *complex_buffer = NULL;
1299 transpose_gs, real_buffer, complex_buffer);
1301 transpose_rs, complex_buffer, real_buffer);
1303 memset(real_buffer, 0,
1304 2 * (fft_size[1] / 2 + 1) * fft_size[0] * number_of_ffts *
1307 double max_error = 0.0;
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;
1314 real_buffer[(number_of_fft / fft_size[1] % fft_size[0] * fft_size[1] +
1315 number_of_fft % fft_size[1]) *
1317 number_of_fft] = 1.0;
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;
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;
1331 real_buffer, complex_buffer);
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;
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) *
1345 const double complex ref_value = cexp(
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);
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;
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(
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);
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);
1398 memset(complex_buffer, 0,
1399 fft_size[0] * (fft_size[1] / 2 + 1) * number_of_ffts *
1400 sizeof(
double complex));
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;
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) *
1413 cexp(-2.0 * I * pi *
1414 ((
double)(number_of_fft / fft_size[1]) * index_0 /
1416 (
double)(number_of_fft % fft_size[1]) * index_1 /
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;
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 /
1434 (
double)(number_of_fft % fft_size[1]) * index_1 /
1442 complex_buffer, real_buffer);
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;
1453 const double my_value =
1454 real_buffer[(index_0 * fft_size[1] + index_1) * number_of_ffts +
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])
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);
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;
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])
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);
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);
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);
1524 const int number_of_ffts,
1525 const int transpose) {
1530 const double pi = acos(-1);
1532 double *real_buffer = NULL;
1535 double complex *complex_buffer = (
double complex *)real_buffer;
1538 real_buffer, complex_buffer);
1540 complex_buffer, real_buffer);
1542 memset(real_buffer, 0,
1543 2 * (fft_size[1] / 2 + 1) * fft_size[0] * number_of_ffts *
1546 double max_error = 0.0;
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;
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]) *
1557 number_of_fft] = 1.0;
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;
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))] =
1572 fft_2d_r2c_local(fft_size, number_of_ffts, transpose, transpose, real_buffer,
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;
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) *
1587 const double complex ref_value = cexp(
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);
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;
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(
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);
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): "
1634 fft_size[0], fft_size[1], number_of_ffts, max_error);
1641 memset(complex_buffer, 0,
1642 fft_size[0] * (fft_size[1] / 2 + 1) * number_of_ffts *
1643 sizeof(
double complex));
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;
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) *
1656 cexp(-2.0 * I * pi *
1657 ((
double)(number_of_fft / fft_size[1]) * index_0 /
1659 (
double)(number_of_fft % fft_size[1]) * index_1 /
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;
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 /
1677 (
double)(number_of_fft % fft_size[1]) * index_1 /
1685 complex_buffer, real_buffer);
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;
1696 const double my_value =
1697 real_buffer[(index_0 * 2 * (fft_size[1] / 2 + 1) + index_1) *
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])
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);
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;
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])
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);
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): "
1749 fft_size[0], fft_size[1], number_of_ffts, max_error);
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);
1770 const bool transpose_in,
const bool transpose_out) {
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;
1780 double complex *input_array = NULL, *output_array = NULL;
1785 transpose_out, input_array, output_array);
1787 transpose_in, output_array, input_array);
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)
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;
1804 fft_3d_local(
true, fft_size, number_of_ffts, transpose_in, transpose_out,
1805 input_array, output_array);
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)
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);
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);
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)
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;
1866 fft_3d_local(
false, fft_size, number_of_ffts, transpose_out, transpose_in,
1867 output_array, input_array);
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)
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 =
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);
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);
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]);
1930 const bool transpose) {
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;
1940 double complex *input_array = NULL;
1942 double complex *output_array = input_array;
1945 input_array, output_array);
1947 output_array, input_array);
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)
1958 const int batch = index / test_every;
1959 input_array[
fft3d_index(fft_size, mx, my, mz, batch, number_of_ffts,
1964 fft_3d_local(
true, fft_size, number_of_ffts, transpose, transpose,
1965 input_array, output_array);
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)
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));
1997 if (max_error > 1.0e-12) {
1998 if (my_process == 0) {
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);
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)
2016 const int batch = index / test_every;
2017 output_array[
fft3d_index(fft_size, mx, my, mz, batch, number_of_ffts,
2022 fft_3d_local(
false, fft_size, number_of_ffts, transpose, transpose,
2023 output_array, input_array);
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)
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 =
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));
2057 if (max_error > 1e-12) {
2058 if (my_process == 0) {
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);
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]);
2082 const bool transpose_in,
2083 const bool transpose_out) {
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;
2094 double *double_buffer = NULL;
2095 double complex *complex_buffer = NULL;
2100 transpose_out, double_buffer, complex_buffer);
2102 transpose_in, complex_buffer, double_buffer);
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)
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;
2120 double_buffer, complex_buffer);
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)
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 =
2138 batch, number_of_ffts,
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);
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);
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)
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
2182#pragma clang loop vectorize(disable)
2184 for (
int nz = 0; nz < fft_size[2] / 2 + 1; nz++) {
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]));
2198 complex_buffer, double_buffer);
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)
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);
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);
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]);
2257 const int test_every,
2258 const bool transpose) {
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;
2271 double complex *complex_buffer = (
double complex *)double_buffer;
2274 double_buffer, complex_buffer);
2276 complex_buffer, double_buffer);
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)
2287 const int batch = basis / test_every;
2289 number_of_ffts, transpose)] = 1.0;
2294 double_buffer, complex_buffer);
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)
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 =
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);
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): "
2336 fft_size[0], fft_size[1], fft_size[2], max_error);
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)
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
2356#pragma clang loop vectorize(disable)
2358 for (
int nz = 0; nz < fft_size[2] / 2 + 1; nz++) {
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]));
2372 complex_buffer, double_buffer);
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)
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++) {
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);
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): "
2411 fft_size[0], fft_size[1], fft_size[2], max_error);
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]);
2428 const int fft_size = 15;
2429 const int number_of_ffts = 2;
2432#pragma omp parallel default(none) shared(errors, fft_size, number_of_ffts)
2434 const int thread_id = omp_get_thread_num();
2435 double complex *input = NULL, *output = NULL, *reference = NULL;
2440 fft_size, fft_size, input, output);
2442 fft_size, fft_size, output, input);
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));
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);
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)
2463 errors += thread_errors;
2473 const int fft_size = 15;
2474 const int number_of_ffts = 2;
2475 const int complex_size = fft_size / 2 + 1;
2478#pragma omp parallel default(none) \
2479 shared(errors, fft_size, number_of_ffts, complex_size)
2481 const int thread_id = omp_get_thread_num();
2482 double *input = NULL, *reference = NULL;
2483 double complex *output = NULL;
2488 complex_size, input, output);
2490 complex_size, fft_size, output, input);
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));
2497 complex_size, input, output);
2499 fft_size, output, input);
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)
2510 errors += thread_errors;
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;
2525#pragma omp parallel default(none) \
2526 shared(errors, fft_size, number_of_ffts, total_size)
2528 const int thread_id = omp_get_thread_num();
2529 double complex *input = NULL, *output = NULL, *reference = NULL;
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));
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);
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]) >
2555 errors += thread_errors;
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;
2571#pragma omp parallel default(none) \
2572 shared(errors, fft_size, number_of_ffts, real_size, complex_size)
2574 const int thread_id = omp_get_thread_num();
2575 double *input = NULL, *reference = NULL;
2576 double complex *output = NULL;
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));
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]) >
2602 errors += thread_errors;
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;
2618#pragma omp parallel default(none) \
2619 shared(errors, fft_size, number_of_ffts, total_size)
2621 const int thread_id = omp_get_thread_num();
2622 double complex *input = NULL, *output = NULL, *reference = NULL;
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));
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);
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)
2648 errors += thread_errors;
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;
2666#pragma omp parallel default(none) \
2667 shared(errors, fft_size, number_of_ffts, real_size, complex_size)
2669 const int thread_id = omp_get_thread_num();
2670 double *input = NULL, *reference = NULL;
2671 double complex *output = NULL;
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));
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)
2697 errors += thread_errors;
2709 clock_t begin = clock();
2765 clock_t end = clock();
2767 printf(
"Time to test local FFTs: %f\n",
2768 (
double)(end - begin) / CLOCKS_PER_SEC);
#define cp_assert(condition)
cp_mpi_comm_t cp_mpi_get_comm_world(void)
Returns MPI_COMM_WORLD.
int cp_mpi_comm_rank(const cp_mpi_comm_t comm)
Wrapper around MPI_Comm_rank.
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.
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.
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.
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.
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.
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.
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.
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.
void fft_free_complex(double complex *buffer)
Allocate buffer of type double complex.
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.
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.
void fft_free_double(double *buffer)
Allocate buffer of type double.
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.
void fft_allocate_double(const int length, double **buffer)
Allocate buffer of type double.
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.
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.
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.
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.
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.
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.
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.
void fft_allocate_complex(const int length, double complex **buffer)
Allocate buffer of type double complex.
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.
static void const int const int i