LCOV - code coverage report
Current view: top level - src/fft - fft_lib_test.c (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:1be8651) Lines: 86.1 % 606 522
Test Date: 2026-11-24 01:22:08 Functions: 100.0 % 21 21

            Line data    Source code
       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              :  ******************************************************************************/
      33              : static 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              :  ******************************************************************************/
      54       557120 : static 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       557120 :   const int spatial = (x * fft_size[1] + y) * (fft_size[2] / 2 + 1) + z;
      59       557120 :   return transpose
      60        24640 :              ? spatial * number_of_ffts + batch
      61       557120 :              : 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              :  ******************************************************************************/
      76       222736 : static 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       222736 :   const int spatial = (x * fft_size[1] + y) * 2 * (fft_size[2] / 2 + 1) + z;
      81       222736 :   return transpose
      82         9328 :              ? spatial * number_of_ffts + batch
      83       222736 :              : 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              :  ******************************************************************************/
      96           32 : int fft_test_1d_local_low(const int fft_size, const int number_of_ffts,
      97              :                           const int transpose_rs, const int transpose_gs) {
      98           32 :   const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
      99              : 
     100           32 :   int errors = 0;
     101              : 
     102           32 :   const double pi = acos(-1);
     103              : 
     104           32 :   double complex *input_array = NULL, *output_array = NULL;
     105           32 :   fft_allocate_complex(fft_size * number_of_ffts, &input_array);
     106           32 :   fft_allocate_complex(fft_size * number_of_ffts, &output_array);
     107              : 
     108           64 :   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           32 :   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           32 :   memset(input_array, 0, fft_size * number_of_ffts * sizeof(double complex));
     118              : 
     119              :   // Check the forward FFT
     120           32 :   if (transpose_rs) {
     121           16 : #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           16 : #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           32 :   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           32 :   double max_error = 0.0;
     143           32 :   if (transpose_gs) {
     144           16 : #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           16 : #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           32 :   fflush(stdout);
     183              : 
     184           32 :   if (max_error > 1.0e-4) {
     185            0 :     if (my_process == 0) {
     186            0 :       printf("The fw 1D-FFT does not work correctly (%i %i): %f!\n", fft_size,
     187              :              number_of_ffts, max_error);
     188            0 :       fflush(stdout);
     189              :     }
     190              :     errors++;
     191              :   }
     192              : 
     193              :   // Check the backward FFT
     194           32 :   memset(output_array, 0, fft_size * number_of_ffts * sizeof(double complex));
     195              : 
     196           32 :   if (transpose_gs) {
     197           16 : #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           16 : #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           32 :   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           32 :   max_error = 0.0;
     219           32 :   if (transpose_rs) {
     220           16 : #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           16 : #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           32 :   fflush(stdout);
     259              : 
     260           32 :   fft_free_complex(input_array);
     261           32 :   fft_free_complex(output_array);
     262              : 
     263           32 :   if (max_error > 1e-12) {
     264            0 :     if (my_process == 0) {
     265            0 :       printf("The bw 1D FFT does not work correctly (%i %i): %f!\n", fft_size,
     266              :              number_of_ffts, max_error);
     267            0 :       fflush(stdout);
     268              :     }
     269            0 :     errors++;
     270              :   }
     271              : 
     272           32 :   if (errors == 0 && my_process == 0)
     273           16 :     printf("The 1D FFT does work correctly (%i %i)!\n", fft_size,
     274              :            number_of_ffts);
     275           32 :   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              :  ******************************************************************************/
     285           16 : int fft_test_1d_local_inplace_low(const int fft_size, const int number_of_ffts,
     286              :                                   const int transpose) {
     287           16 :   const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
     288              : 
     289           16 :   int errors = 0;
     290              : 
     291           16 :   const double pi = acos(-1);
     292              : 
     293           16 :   double complex *input_array = NULL;
     294           16 :   fft_allocate_complex(fft_size * number_of_ffts, &input_array);
     295              : 
     296           24 :   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           16 :   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           16 :   memset(input_array, 0, fft_size * number_of_ffts * sizeof(double complex));
     306              : 
     307              :   // Check the forward FFT
     308           16 :   if (transpose) {
     309            8 : #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            8 : #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           16 :   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           16 :   double max_error = 0.0;
     330           16 :   if (transpose) {
     331            8 : #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            8 : #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           16 :   fflush(stdout);
     370              : 
     371           16 :   if (max_error > 1.0e-4) {
     372            0 :     if (my_process == 0) {
     373            0 :       printf("The fw 1D-FFT (inplace) does not work correctly (%i %i): %f!\n",
     374              :              fft_size, number_of_ffts, max_error);
     375            0 :       fflush(stdout);
     376              :     }
     377              :     errors++;
     378              :   }
     379              : 
     380              :   // Check the backward FFT
     381           16 :   memset(input_array, 0, fft_size * number_of_ffts * sizeof(double complex));
     382              : 
     383           16 :   if (transpose) {
     384            8 : #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            8 : #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           16 :   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           16 :   max_error = 0.0;
     405           16 :   if (transpose) {
     406            8 : #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            8 : #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           16 :   fflush(stdout);
     445              : 
     446           16 :   fft_free_complex(input_array);
     447              : 
     448           16 :   if (max_error > 1e-12) {
     449            0 :     if (my_process == 0) {
     450            0 :       printf("The bw 1D FFT (inplace) does not work correctly (%i %i): %f!\n",
     451              :              fft_size, number_of_ffts, max_error);
     452            0 :       fflush(stdout);
     453              :     }
     454            0 :     errors++;
     455              :   }
     456              : 
     457           16 :   if (errors == 0 && my_process == 0)
     458            8 :     printf("The 1D FFT (inplace) does work correctly (%i %i)!\n", fft_size,
     459              :            number_of_ffts);
     460           16 :   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              :  ******************************************************************************/
     472           32 : int 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           32 :   const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
     475              : 
     476           32 :   int errors = 0;
     477              : 
     478           32 :   const double pi = acos(-1);
     479              : 
     480           32 :   double *input_array = NULL;
     481           32 :   double complex *output_array = NULL;
     482           32 :   fft_allocate_double(2 * (fft_size / 2 + 1) * number_of_ffts, &input_array);
     483           32 :   fft_allocate_complex((fft_size / 2 + 1) * number_of_ffts + 4, &output_array);
     484              : 
     485           64 :   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);
     490           32 :   fft_register_1d_c2r_local(
     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           32 :   memset(input_array, 0, fft_size * number_of_ffts * sizeof(double));
     496              :   // Check the forward FFT
     497           32 :   if (transpose_rs) {
     498           16 : #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           16 : #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           32 :   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           32 :   double max_error = 0.0;
     520           32 :   if (transpose_gs) {
     521           16 : #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           16 : #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           32 :   fflush(stdout);
     560              : 
     561           32 :   if (max_error > 1.0e-8) {
     562            0 :     if (my_process == 0) {
     563            0 :       printf("The fw R2C 1D-FFT does not work correctly (%i %i): %f!\n",
     564              :              fft_size, number_of_ffts, max_error);
     565            0 :       fflush(stdout);
     566              :     }
     567              :     errors++;
     568              :   }
     569              : 
     570              :   // Check the backward FFT
     571           32 :   memset(output_array, 0,
     572           32 :          (fft_size / 2 + 1) * number_of_ffts * sizeof(double complex));
     573              : 
     574           32 :   if (transpose_gs) {
     575           16 : #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           16 : #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           32 :   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           32 :   max_error = 0.0;
     602           32 :   if (transpose_rs) {
     603           16 : #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           16 : #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           32 :   fflush(stdout);
     639              : 
     640           32 :   if (max_error > 1e-8) {
     641            0 :     if (my_process == 0) {
     642            0 :       printf("The bw C2R-1D FFT does not work correctly (%i %i): %f!\n",
     643              :              fft_size, number_of_ffts, max_error);
     644            0 :       fflush(stdout);
     645              :     }
     646            0 :     errors++;
     647              :   }
     648              : 
     649           32 :   fft_free_double(input_array);
     650           32 :   fft_free_complex(output_array);
     651              : 
     652           32 :   if (errors == 0 && my_process == 0)
     653           16 :     printf("The 1D R/C FFT does work correctly (%i %i)!\n", fft_size,
     654              :            number_of_ffts);
     655           32 :   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              :  ******************************************************************************/
     665           16 : int fft_test_1d_local_r2c_inplace_low(const int fft_size,
     666              :                                       const int number_of_ffts,
     667              :                                       const int transpose) {
     668           16 :   const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
     669              : 
     670           16 :   int errors = 0;
     671              : 
     672           16 :   const double pi = acos(-1);
     673              : 
     674           16 :   double *input_array = NULL;
     675           16 :   fft_allocate_double(2 * (fft_size / 2 + 1) * number_of_ffts, &input_array);
     676           16 :   double complex *output_array = (double complex *)input_array;
     677              : 
     678           16 :   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           16 :   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           16 :   memset(input_array, 0,
     688           16 :          2 * (fft_size / 2 + 1) * number_of_ffts * sizeof(double));
     689              :   // Check the forward FFT
     690           16 :   if (transpose) {
     691            8 : #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            8 : #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           16 :   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           16 :   double max_error = 0.0;
     714           16 :   if (transpose) {
     715            8 : #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            8 : #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           16 :   fflush(stdout);
     754              : 
     755           16 :   if (max_error > 1.0e-8) {
     756            0 :     if (my_process == 0) {
     757            0 :       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            0 :       fflush(stdout);
     761              :     }
     762              :     errors++;
     763              :   }
     764              : 
     765              :   // Check the backward FFT
     766           16 :   memset(output_array, 0,
     767           16 :          (fft_size / 2 + 1) * number_of_ffts * sizeof(double complex));
     768              : 
     769           16 :   if (transpose) {
     770            8 : #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            8 : #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           16 :   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           16 :   max_error = 0.0;
     797           16 :   if (transpose) {
     798            8 : #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            8 : #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           16 :   fflush(stdout);
     835              : 
     836           16 :   if (max_error > 1e-8) {
     837            0 :     if (my_process == 0) {
     838            0 :       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            0 :       fflush(stdout);
     842              :     }
     843            0 :     errors++;
     844              :   }
     845              : 
     846           16 :   fft_free_double(input_array);
     847              : 
     848           16 :   if (errors == 0 && my_process == 0)
     849            8 :     printf("The 1D R2C FFT (inplace) does work correctly (%i %i)!\n", fft_size,
     850              :            number_of_ffts);
     851           16 :   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              :  ******************************************************************************/
     863           32 : int 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           32 :   const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
     866              : 
     867           32 :   int errors = 0;
     868              : 
     869           32 :   const double pi = acos(-1);
     870              : 
     871           32 :   double complex *input_array = NULL, *output_array = NULL;
     872           32 :   const int elements_per_fft = fft_size[0] * fft_size[1];
     873           32 :   fft_allocate_complex(elements_per_fft * number_of_ffts, &input_array);
     874           32 :   fft_allocate_complex(elements_per_fft * number_of_ffts, &output_array);
     875              : 
     876           32 :   fft_register_2d_local(true, fft_size, number_of_ffts, transpose_rs,
     877              :                         transpose_gs, input_array, output_array);
     878           32 :   fft_register_2d_local(false, fft_size, number_of_ffts, transpose_gs,
     879              :                         transpose_rs, output_array, input_array);
     880              : 
     881           32 :   memset(input_array, 0,
     882           32 :          elements_per_fft * number_of_ffts * sizeof(double complex));
     883           32 :   double max_error = 0.0;
     884              :   // Check the forward FFT
     885           32 :   if (transpose_rs) {
     886           16 : #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           16 : #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           32 :   fft_2d_local(true, fft_size, number_of_ffts, transpose_rs, transpose_gs,
     904              :                input_array, output_array);
     905              : 
     906           32 :   if (transpose_gs) {
     907           16 : #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           16 : #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           32 :   fflush(stdout);
     959              : 
     960           32 :   if (max_error > 1.0e-3) {
     961            0 :     if (my_process == 0) {
     962            0 :       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            0 :       fflush(stdout);
     965              :     }
     966              :     errors++;
     967              :   }
     968              : 
     969              :   // Check the backward FFT
     970           32 :   memset(output_array, 0,
     971              :          elements_per_fft * number_of_ffts * sizeof(double complex));
     972              : 
     973           32 :   if (transpose_gs) {
     974           16 : #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           16 : #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           32 :   fft_2d_local(false, fft_size, number_of_ffts, transpose_gs, transpose_rs,
     992              :                output_array, input_array);
     993              : 
     994           32 :   max_error = 0.0;
     995           32 :   if (transpose_rs) {
     996           16 : #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           16 : #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           32 :   fflush(stdout);
    1045              : 
    1046           32 :   fft_free_complex(input_array);
    1047           32 :   fft_free_complex(output_array);
    1048              : 
    1049           32 :   if (max_error > 1e-12) {
    1050            0 :     if (my_process == 0) {
    1051            0 :       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            0 :       fflush(stdout);
    1054              :     }
    1055            0 :     errors++;
    1056              :   }
    1057              : 
    1058           32 :   if (errors == 0 && my_process == 0)
    1059           16 :     printf("The 2D FFT does work correctly (%i %i/%i)!\n", fft_size[0],
    1060              :            fft_size[1], number_of_ffts);
    1061           32 :   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              :  ******************************************************************************/
    1071           16 : int fft_test_2d_local_inplace_low(const int fft_size[2],
    1072              :                                   const int number_of_ffts,
    1073              :                                   const int transpose) {
    1074           16 :   const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
    1075              : 
    1076           16 :   int errors = 0;
    1077              : 
    1078           16 :   const double pi = acos(-1);
    1079              : 
    1080           16 :   double complex *input_array = NULL;
    1081           16 :   const int elements_per_fft = fft_size[0] * fft_size[1];
    1082           16 :   fft_allocate_complex(elements_per_fft * number_of_ffts, &input_array);
    1083           16 :   double complex *output_array = input_array;
    1084              : 
    1085           16 :   fft_register_2d_local(true, fft_size, number_of_ffts, transpose, transpose,
    1086              :                         input_array, output_array);
    1087           16 :   fft_register_2d_local(false, fft_size, number_of_ffts, transpose, transpose,
    1088              :                         output_array, input_array);
    1089              : 
    1090           16 :   memset(input_array, 0,
    1091           16 :          elements_per_fft * number_of_ffts * sizeof(double complex));
    1092           16 :   double max_error = 0.0;
    1093              :   // Check the forward FFT
    1094           16 :   if (transpose) {
    1095            8 : #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            8 : #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           16 :   fft_2d_local(true, fft_size, number_of_ffts, transpose, transpose,
    1113              :                input_array, output_array);
    1114              : 
    1115           16 :   if (transpose) {
    1116            8 : #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            8 : #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           16 :   fflush(stdout);
    1168              : 
    1169           16 :   if (max_error > 1.0e-3) {
    1170            0 :     if (my_process == 0) {
    1171            0 :       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            0 :       fflush(stdout);
    1175              :     }
    1176              :     errors++;
    1177              :   }
    1178              : 
    1179              :   // Check the backward FFT
    1180           16 :   memset(output_array, 0,
    1181              :          elements_per_fft * number_of_ffts * sizeof(double complex));
    1182              : 
    1183           16 :   if (transpose) {
    1184            8 : #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            8 : #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           16 :   fft_2d_local(false, fft_size, number_of_ffts, transpose, transpose,
    1202              :                output_array, input_array);
    1203              : 
    1204           16 :   max_error = 0.0;
    1205           16 :   if (transpose) {
    1206            8 : #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            8 : #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           16 :   fflush(stdout);
    1255              : 
    1256           16 :   fft_free_complex(input_array);
    1257              : 
    1258           16 :   if (max_error > 1e-12) {
    1259            0 :     if (my_process == 0) {
    1260            0 :       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            0 :       fflush(stdout);
    1264              :     }
    1265            0 :     errors++;
    1266              :   }
    1267              : 
    1268           16 :   if (errors == 0 && my_process == 0)
    1269            8 :     printf("The 2D FFT (inplace) does work correctly (%i %i/%i)!\n",
    1270              :            fft_size[0], fft_size[1], number_of_ffts);
    1271           16 :   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              :  ******************************************************************************/
    1283           32 : int 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           32 :   const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
    1286              : 
    1287           32 :   int errors = 0;
    1288              : 
    1289           32 :   const double pi = acos(-1);
    1290              : 
    1291           32 :   double *real_buffer = NULL;
    1292           32 :   double complex *complex_buffer = NULL;
    1293           32 :   fft_allocate_double(2 * (fft_size[1] / 2 + 1) * fft_size[0] * number_of_ffts,
    1294              :                       &real_buffer);
    1295           32 :   fft_allocate_complex((fft_size[1] / 2 + 1) * fft_size[0] * number_of_ffts,
    1296              :                        &complex_buffer);
    1297              : 
    1298           32 :   fft_register_2d_r2c_local(fft_size, number_of_ffts, transpose_rs,
    1299              :                             transpose_gs, real_buffer, complex_buffer);
    1300           32 :   fft_register_2d_c2r_local(fft_size, number_of_ffts, transpose_gs,
    1301              :                             transpose_rs, complex_buffer, real_buffer);
    1302              : 
    1303           32 :   memset(real_buffer, 0,
    1304           32 :          2 * (fft_size[1] / 2 + 1) * fft_size[0] * number_of_ffts *
    1305              :              sizeof(double));
    1306              : 
    1307           32 :   double max_error = 0.0;
    1308              :   // Check the forward FFT
    1309           32 :   if (transpose_rs) {
    1310           16 : #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           16 : #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           32 :   fft_2d_r2c_local(fft_size, number_of_ffts, transpose_rs, transpose_gs,
    1331              :                    real_buffer, complex_buffer);
    1332              : 
    1333           32 :   if (transpose_gs) {
    1334           16 : #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           16 : #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           32 :   fflush(stdout);
    1387              : 
    1388           32 :   if (max_error > 1.0e-12) {
    1389            0 :     if (my_process == 0) {
    1390            0 :       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            0 :       fflush(stdout);
    1393              :     }
    1394              :     errors++;
    1395              :   }
    1396              : 
    1397              :   // Check the backward FFT
    1398           32 :   memset(complex_buffer, 0,
    1399           32 :          fft_size[0] * (fft_size[1] / 2 + 1) * number_of_ffts *
    1400              :              sizeof(double complex));
    1401              : 
    1402           32 :   if (transpose_gs) {
    1403           16 : #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           16 : #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           32 :   fft_2d_c2r_local(fft_size, number_of_ffts, transpose_gs, transpose_rs,
    1442              :                    complex_buffer, real_buffer);
    1443              : 
    1444           32 :   max_error = 0.0;
    1445           32 :   if (transpose_rs) {
    1446           16 : #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           16 : #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           32 :   fflush(stdout);
    1497              : 
    1498           32 :   fft_free_double(real_buffer);
    1499           32 :   fft_free_complex(complex_buffer);
    1500              : 
    1501           32 :   if (max_error > 1e-8) {
    1502            0 :     if (my_process == 0) {
    1503            0 :       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            0 :       fflush(stdout);
    1506              :     }
    1507            0 :     errors++;
    1508              :   }
    1509              : 
    1510           32 :   if (errors == 0 && my_process == 0)
    1511           16 :     printf("The 2D R2C/C2R FFT does work correctly (%i %i/%i)!\n", fft_size[0],
    1512              :            fft_size[1], number_of_ffts);
    1513           32 :   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              :  ******************************************************************************/
    1523           16 : int fft_test_2d_local_r2c_inplace_low(const int fft_size[2],
    1524              :                                       const int number_of_ffts,
    1525              :                                       const int transpose) {
    1526           16 :   const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
    1527              : 
    1528           16 :   int errors = 0;
    1529              : 
    1530           16 :   const double pi = acos(-1);
    1531              : 
    1532           16 :   double *real_buffer = NULL;
    1533           16 :   fft_allocate_double(2 * (fft_size[1] / 2 + 1) * fft_size[0] * number_of_ffts,
    1534              :                       &real_buffer);
    1535           16 :   double complex *complex_buffer = (double complex *)real_buffer;
    1536              : 
    1537           16 :   fft_register_2d_r2c_local(fft_size, number_of_ffts, transpose, transpose,
    1538              :                             real_buffer, complex_buffer);
    1539           16 :   fft_register_2d_c2r_local(fft_size, number_of_ffts, transpose, transpose,
    1540              :                             complex_buffer, real_buffer);
    1541              : 
    1542           16 :   memset(real_buffer, 0,
    1543           16 :          2 * (fft_size[1] / 2 + 1) * fft_size[0] * number_of_ffts *
    1544              :              sizeof(double));
    1545              : 
    1546           16 :   double max_error = 0.0;
    1547              :   // Check the forward FFT
    1548           16 :   if (transpose) {
    1549            8 : #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            8 : #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           16 :   fft_2d_r2c_local(fft_size, number_of_ffts, transpose, transpose, real_buffer,
    1573              :                    complex_buffer);
    1574              : 
    1575           16 :   if (transpose) {
    1576            8 : #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            8 : #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           16 :   fflush(stdout);
    1629              : 
    1630           16 :   if (max_error > 1.0e-12) {
    1631            0 :     if (my_process == 0) {
    1632            0 :       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            0 :       fflush(stdout);
    1636              :     }
    1637              :     errors++;
    1638              :   }
    1639              : 
    1640              :   // Check the backward FFT
    1641           16 :   memset(complex_buffer, 0,
    1642           16 :          fft_size[0] * (fft_size[1] / 2 + 1) * number_of_ffts *
    1643              :              sizeof(double complex));
    1644              : 
    1645           16 :   if (transpose) {
    1646            8 : #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            8 : #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           16 :   fft_2d_c2r_local(fft_size, number_of_ffts, transpose, transpose,
    1685              :                    complex_buffer, real_buffer);
    1686              : 
    1687           16 :   max_error = 0.0;
    1688           16 :   if (transpose) {
    1689            8 : #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            8 : #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           16 :   fflush(stdout);
    1742              : 
    1743           16 :   fft_free_double(real_buffer);
    1744              : 
    1745           16 :   if (max_error > 1e-8) {
    1746            0 :     if (my_process == 0) {
    1747            0 :       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            0 :       fflush(stdout);
    1751              :     }
    1752            0 :     errors++;
    1753              :   }
    1754              : 
    1755           16 :   if (errors == 0 && my_process == 0)
    1756            8 :     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           16 :   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              :  ******************************************************************************/
    1769           16 : int fft_test_3d_local_low(const int fft_size[3], const int test_every,
    1770              :                           const bool transpose_in, const bool transpose_out) {
    1771           16 :   cp_assert(test_every > 0);
    1772           16 :   const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
    1773              : 
    1774           16 :   int errors = 0;
    1775              : 
    1776           16 :   const double pi = acos(-1);
    1777           16 :   const int volume = product3(fft_size);
    1778           16 :   const int number_of_ffts = (volume + test_every - 1) / test_every;
    1779              : 
    1780           16 :   double complex *input_array = NULL, *output_array = NULL;
    1781           16 :   fft_allocate_complex(volume * number_of_ffts, &input_array);
    1782           16 :   fft_allocate_complex(volume * number_of_ffts, &output_array);
    1783              : 
    1784           16 :   fft_register_3d_local(true, fft_size, number_of_ffts, transpose_in,
    1785              :                         transpose_out, input_array, output_array);
    1786           16 :   fft_register_3d_local(false, fft_size, number_of_ffts, transpose_out,
    1787              :                         transpose_in, output_array, input_array);
    1788              : 
    1789           16 :   double max_error = 0.0;
    1790           16 :   memset(input_array, 0, volume * number_of_ffts * sizeof(double complex));
    1791           16 : #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           16 :   fft_3d_local(true, fft_size, number_of_ffts, transpose_in, transpose_out,
    1805              :                input_array, output_array);
    1806              : 
    1807           16 : #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           16 :   fflush(stdout);
    1841              : 
    1842           16 :   if (max_error > 1.0e-12) {
    1843            0 :     if (my_process == 0) {
    1844            0 :       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            0 :       fflush(stdout);
    1847              :     }
    1848              :     errors++;
    1849              :   }
    1850              : 
    1851           16 :   max_error = 0.0;
    1852           16 :   memset(output_array, 0, volume * number_of_ffts * sizeof(double complex));
    1853           16 : #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           16 :   fft_3d_local(false, fft_size, number_of_ffts, transpose_out, transpose_in,
    1867              :                output_array, input_array);
    1868              : 
    1869           16 : #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           16 :   fflush(stdout);
    1903              : 
    1904           16 :   fft_free_complex(input_array);
    1905           16 :   fft_free_complex(output_array);
    1906              : 
    1907           16 :   if (max_error > 1e-12) {
    1908            0 :     if (my_process == 0) {
    1909            0 :       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            0 :       fflush(stdout);
    1912              :     }
    1913            0 :     errors++;
    1914              :   }
    1915              : 
    1916           16 :   if (errors == 0 && my_process == 0)
    1917            8 :     printf("The 3D FFT does work correctly (%i %i %i)!\n", fft_size[0],
    1918              :            fft_size[1], fft_size[2]);
    1919           16 :   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              :  ******************************************************************************/
    1929           16 : int fft_test_3d_local_inplace_low(const int fft_size[3], const int test_every,
    1930              :                                   const bool transpose) {
    1931           16 :   cp_assert(test_every > 0);
    1932           16 :   const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
    1933              : 
    1934           16 :   int errors = 0;
    1935              : 
    1936           16 :   const double pi = acos(-1);
    1937           16 :   const int volume = product3(fft_size);
    1938           16 :   const int number_of_ffts = (volume + test_every - 1) / test_every;
    1939              : 
    1940           16 :   double complex *input_array = NULL;
    1941           16 :   fft_allocate_complex(volume * number_of_ffts, &input_array);
    1942           16 :   double complex *output_array = input_array;
    1943              : 
    1944           16 :   fft_register_3d_local(true, fft_size, number_of_ffts, transpose, transpose,
    1945              :                         input_array, output_array);
    1946           16 :   fft_register_3d_local(false, fft_size, number_of_ffts, transpose, transpose,
    1947              :                         output_array, input_array);
    1948              : 
    1949           16 :   double max_error = 0.0;
    1950           16 :   memset(input_array, 0, volume * number_of_ffts * sizeof(double complex));
    1951           16 : #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           16 :   fft_3d_local(true, fft_size, number_of_ffts, transpose, transpose,
    1965              :                input_array, output_array);
    1966              : 
    1967           16 : #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           16 :   fflush(stdout);
    1996              : 
    1997           16 :   if (max_error > 1.0e-12) {
    1998            0 :     if (my_process == 0) {
    1999            0 :       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            0 :       fflush(stdout);
    2003              :     }
    2004              :     errors++;
    2005              :   }
    2006              : 
    2007           16 :   max_error = 0.0;
    2008           16 :   memset(output_array, 0, volume * number_of_ffts * sizeof(double complex));
    2009           16 : #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           16 :   fft_3d_local(false, fft_size, number_of_ffts, transpose, transpose,
    2023              :                output_array, input_array);
    2024              : 
    2025           16 : #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           16 :   fflush(stdout);
    2054              : 
    2055           16 :   fft_free_complex(input_array);
    2056              : 
    2057           16 :   if (max_error > 1e-12) {
    2058            0 :     if (my_process == 0) {
    2059            0 :       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            0 :       fflush(stdout);
    2063              :     }
    2064            0 :     errors++;
    2065              :   }
    2066              : 
    2067           16 :   if (errors == 0 && my_process == 0)
    2068            8 :     printf("The 3D FFT (inplace) does work correctly (%i %i %i)!\n",
    2069              :            fft_size[0], fft_size[1], fft_size[2]);
    2070           16 :   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              :  ******************************************************************************/
    2081           16 : int 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           16 :   cp_assert(test_every > 0);
    2085           16 :   const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
    2086              : 
    2087           16 :   int errors = 0;
    2088              : 
    2089           16 :   const double pi = acos(-1);
    2090           16 :   const int volume = product3(fft_size);
    2091           16 :   const int complex_volume = fft_size[0] * fft_size[1] * (fft_size[2] / 2 + 1);
    2092           16 :   const int number_of_ffts = (volume + test_every - 1) / test_every;
    2093              : 
    2094           16 :   double *double_buffer = NULL;
    2095           16 :   double complex *complex_buffer = NULL;
    2096           16 :   fft_allocate_double(volume * number_of_ffts, &double_buffer);
    2097           16 :   fft_allocate_complex(complex_volume * number_of_ffts, &complex_buffer);
    2098              : 
    2099           16 :   fft_register_3d_r2c_local(fft_size, number_of_ffts, transpose_in,
    2100              :                             transpose_out, double_buffer, complex_buffer);
    2101           16 :   fft_register_3d_c2r_local(fft_size, number_of_ffts, transpose_out,
    2102              :                             transpose_in, complex_buffer, double_buffer);
    2103              : 
    2104           16 :   double max_error = 0.0;
    2105           16 :   memset(double_buffer, 0, volume * number_of_ffts * sizeof(double));
    2106           16 : #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           16 :   fft_3d_r2c_local(fft_size, number_of_ffts, transpose_in, transpose_out,
    2120              :                    double_buffer, complex_buffer);
    2121              : 
    2122           16 : #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           16 :   fflush(stdout);
    2158              : 
    2159           16 :   if (max_error > 1.0e-6) {
    2160            0 :     if (my_process == 0) {
    2161            0 :       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            0 :       fflush(stdout);
    2164              :     }
    2165              :     errors++;
    2166              :   }
    2167              : 
    2168           16 :   max_error = 0.0;
    2169           16 : #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           16 :   fft_3d_c2r_local(fft_size, number_of_ffts, transpose_out, transpose_in,
    2198              :                    complex_buffer, double_buffer);
    2199              : 
    2200           16 : #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           16 :   fflush(stdout);
    2230              : 
    2231           16 :   fft_free_double(double_buffer);
    2232           16 :   fft_free_complex(complex_buffer);
    2233              : 
    2234           16 :   if (max_error > 1e-6) {
    2235            0 :     if (my_process == 0) {
    2236            0 :       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            0 :       fflush(stdout);
    2239              :     }
    2240            0 :     errors++;
    2241              :   }
    2242              : 
    2243           16 :   if (errors == 0 && my_process == 0)
    2244            8 :     printf("The 3D R2C/C2R FFT does work correctly (%i %i %i)!\n", fft_size[0],
    2245              :            fft_size[1], fft_size[2]);
    2246           16 :   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              :  ******************************************************************************/
    2256           16 : int fft_test_3d_local_r2c_inplace_low(const int fft_size[3],
    2257              :                                       const int test_every,
    2258              :                                       const bool transpose) {
    2259           16 :   cp_assert(test_every > 0);
    2260           16 :   const int my_process = cp_mpi_comm_rank(cp_mpi_get_comm_world());
    2261              : 
    2262           16 :   int errors = 0;
    2263              : 
    2264           16 :   const double pi = acos(-1);
    2265           16 :   const int volume = product3(fft_size);
    2266           16 :   const int complex_volume = fft_size[0] * fft_size[1] * (fft_size[2] / 2 + 1);
    2267           16 :   const int number_of_ffts = (volume + test_every - 1) / test_every;
    2268           16 :   const int buffer_size = complex_volume * number_of_ffts;
    2269           16 :   double *double_buffer = NULL;
    2270           16 :   fft_allocate_double(2 * buffer_size, &double_buffer);
    2271           16 :   double complex *complex_buffer = (double complex *)double_buffer;
    2272              : 
    2273           16 :   fft_register_3d_r2c_local(fft_size, number_of_ffts, transpose, transpose,
    2274              :                             double_buffer, complex_buffer);
    2275           16 :   fft_register_3d_c2r_local(fft_size, number_of_ffts, transpose, transpose,
    2276              :                             complex_buffer, double_buffer);
    2277              : 
    2278           16 :   double max_error = 0.0;
    2279           16 :   memset(double_buffer, 0, 2 * buffer_size * sizeof(double));
    2280           16 : #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           16 :   fft_3d_r2c_local(fft_size, number_of_ffts, transpose, transpose,
    2294              :                    double_buffer, complex_buffer);
    2295              : 
    2296           16 : #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           16 :   fflush(stdout);
    2331              : 
    2332           16 :   if (max_error > 1.0e-6) {
    2333            0 :     if (my_process == 0) {
    2334            0 :       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            0 :       fflush(stdout);
    2338              :     }
    2339              :     errors++;
    2340              :   }
    2341              : 
    2342           16 :   max_error = 0.0;
    2343           16 : #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           16 :   fft_3d_c2r_local(fft_size, number_of_ffts, transpose, transpose,
    2372              :                    complex_buffer, double_buffer);
    2373              : 
    2374           16 : #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           16 :   fflush(stdout);
    2404              : 
    2405           16 :   fft_free_double(double_buffer);
    2406              : 
    2407           16 :   if (max_error > 1e-6) {
    2408            0 :     if (my_process == 0) {
    2409            0 :       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            0 :       fflush(stdout);
    2413              :     }
    2414            0 :     errors++;
    2415              :   }
    2416              : 
    2417           16 :   if (errors == 0 && my_process == 0)
    2418            8 :     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           16 :   return errors;
    2421              : }
    2422              : 
    2423              : /*******************************************************************************
    2424              :  * \brief Test concurrent 1D C2C FFTs from independent OpenMP threads.
    2425              :  * \author Frederick Stein
    2426              :  ******************************************************************************/
    2427            8 : int fft_test_1d_local_omp(void) {
    2428            8 :   const int fft_size = 15;
    2429            8 :   const int number_of_ffts = 2;
    2430            8 :   int errors = 0;
    2431              : 
    2432            8 : #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            8 :   return errors;
    2466              : }
    2467              : 
    2468              : /*******************************************************************************
    2469              :  * \brief Test concurrent 1D R2C/C2R FFTs from independent OpenMP threads.
    2470              :  * \author Frederick Stein
    2471              :  ******************************************************************************/
    2472            8 : int fft_test_1d_local_omp_r2c(void) {
    2473            8 :   const int fft_size = 15;
    2474            8 :   const int number_of_ffts = 2;
    2475            8 :   const int complex_size = fft_size / 2 + 1;
    2476            8 :   int errors = 0;
    2477              : 
    2478            8 : #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            8 :   return errors;
    2513              : }
    2514              : 
    2515              : /*******************************************************************************
    2516              :  * \brief Test concurrent 2D C2C FFTs from independent OpenMP threads.
    2517              :  * \author Frederick Stein
    2518              :  ******************************************************************************/
    2519            8 : int fft_test_2d_local_omp(void) {
    2520            8 :   const int fft_size[2] = {8, 9};
    2521            8 :   const int number_of_ffts = 2;
    2522            8 :   const int total_size = fft_size[0] * fft_size[1] * number_of_ffts;
    2523            8 :   int errors = 0;
    2524              : 
    2525            8 : #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            8 :   return errors;
    2558              : }
    2559              : 
    2560              : /*******************************************************************************
    2561              :  * \brief Test concurrent 2D R2C/C2R FFTs from independent OpenMP threads.
    2562              :  * \author Frederick Stein
    2563              :  ******************************************************************************/
    2564            8 : int fft_test_2d_local_omp_r2c(void) {
    2565            8 :   const int fft_size[2] = {8, 9};
    2566            8 :   const int number_of_ffts = 2;
    2567            8 :   const int real_size = fft_size[0] * fft_size[1] * number_of_ffts;
    2568            8 :   const int complex_size = fft_size[0] * (fft_size[1] / 2 + 1) * number_of_ffts;
    2569            8 :   int errors = 0;
    2570              : 
    2571            8 : #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            8 :   return errors;
    2605              : }
    2606              : 
    2607              : /*******************************************************************************
    2608              :  * \brief Test concurrent 3D C2C FFTs from independent OpenMP threads.
    2609              :  * \author Frederick Stein
    2610              :  ******************************************************************************/
    2611            8 : int fft_test_3d_local_omp(void) {
    2612            8 :   const int fft_size[3] = {5, 4, 6};
    2613            8 :   const int number_of_ffts = 2;
    2614            8 :   const int total_size =
    2615              :       fft_size[0] * fft_size[1] * fft_size[2] * number_of_ffts;
    2616            8 :   int errors = 0;
    2617              : 
    2618            8 : #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            8 :   return errors;
    2651              : }
    2652              : 
    2653              : /*******************************************************************************
    2654              :  * \brief Test concurrent 3D R2C/C2R FFTs from independent OpenMP threads.
    2655              :  * \author Frederick Stein
    2656              :  ******************************************************************************/
    2657            8 : int fft_test_3d_local_omp_r2c(void) {
    2658            8 :   const int fft_size[3] = {5, 4, 6};
    2659            8 :   const int number_of_ffts = 2;
    2660            8 :   const int real_size =
    2661              :       fft_size[0] * fft_size[1] * fft_size[2] * number_of_ffts;
    2662            8 :   const int complex_size =
    2663              :       fft_size[0] * fft_size[1] * (fft_size[2] / 2 + 1) * number_of_ffts;
    2664            8 :   int errors = 0;
    2665              : 
    2666            8 : #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            8 :   return errors;
    2700              : }
    2701              : 
    2702              : /*******************************************************************************
    2703              :  * \brief Function to test the local FFT backend (1-3D).
    2704              :  * \author Frederick Stein
    2705              :  ******************************************************************************/
    2706            8 : int fft_test_local() {
    2707            8 :   int errors = 0;
    2708              : 
    2709            8 :   clock_t begin = clock();
    2710            8 :   errors += fft_test_1d_local_low(15, 13, true, true);
    2711            8 :   errors += fft_test_1d_local_low(9, 11, true, false);
    2712            8 :   errors += fft_test_1d_local_low(10, 14, false, true);
    2713            8 :   errors += fft_test_1d_local_low(14, 13, false, false);
    2714              : 
    2715            8 :   errors += fft_test_1d_local_inplace_low(15, 13, true);
    2716            8 :   errors += fft_test_1d_local_inplace_low(14, 13, false);
    2717              : 
    2718            8 :   errors += fft_test_1d_local_r2c_low(15, 13, true, false);
    2719            8 :   errors += fft_test_1d_local_r2c_low(9, 11, false, false);
    2720            8 :   errors += fft_test_1d_local_r2c_low(10, 14, false, true);
    2721            8 :   errors += fft_test_1d_local_r2c_low(14, 13, true, true);
    2722              : 
    2723            8 :   errors += fft_test_1d_local_r2c_inplace_low(15, 11, false);
    2724            8 :   errors += fft_test_1d_local_r2c_inplace_low(14, 13, true);
    2725              : 
    2726            8 :   errors += fft_test_2d_local_low((const int[2]){10, 10}, 10, true, true);
    2727            8 :   errors += fft_test_2d_local_low((const int[2]){8, 9}, 10, true, false);
    2728            8 :   errors += fft_test_2d_local_low((const int[2]){7, 10}, 11, false, true);
    2729            8 :   errors += fft_test_2d_local_low((const int[2]){6, 7}, 10, false, false);
    2730              : 
    2731            8 :   errors += fft_test_2d_local_inplace_low((const int[2]){8, 9}, 10, true);
    2732            8 :   errors += fft_test_2d_local_inplace_low((const int[2]){7, 10}, 11, false);
    2733              : 
    2734            8 :   errors += fft_test_2d_local_r2c_low((const int[2]){10, 10}, 10, true, true);
    2735            8 :   errors += fft_test_2d_local_r2c_low((const int[2]){8, 9}, 10, true, false);
    2736            8 :   errors += fft_test_2d_local_r2c_low((const int[2]){7, 10}, 10, false, true);
    2737            8 :   errors += fft_test_2d_local_r2c_low((const int[2]){6, 7}, 11, false, false);
    2738              : 
    2739            8 :   errors += fft_test_2d_local_r2c_inplace_low((const int[2]){8, 9}, 10, true);
    2740            8 :   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            8 :   errors += fft_test_3d_local_low((const int[3]){8, 8, 8}, 10, false, false);
    2744            8 :   errors += fft_test_3d_local_low((const int[3]){7, 5, 3}, 10, true, true);
    2745              : 
    2746            8 :   errors += fft_test_3d_local_inplace_low((const int[3]){8, 8, 8}, 10, false);
    2747            8 :   errors += fft_test_3d_local_inplace_low((const int[3]){7, 5, 3}, 10, true);
    2748              : 
    2749           16 :   errors +=
    2750            8 :       fft_test_3d_local_r2c_low((const int[3]){8, 8, 8}, 10, false, false);
    2751            8 :   errors += fft_test_3d_local_r2c_low((const int[3]){7, 5, 3}, 10, true, true);
    2752              : 
    2753           16 :   errors +=
    2754            8 :       fft_test_3d_local_r2c_inplace_low((const int[3]){8, 8, 8}, 10, false);
    2755           16 :   errors +=
    2756            8 :       fft_test_3d_local_r2c_inplace_low((const int[3]){7, 5, 3}, 10, true);
    2757              : 
    2758            8 :   errors += fft_test_1d_local_omp();
    2759            8 :   errors += fft_test_1d_local_omp_r2c();
    2760            8 :   errors += fft_test_2d_local_omp();
    2761            8 :   errors += fft_test_2d_local_omp_r2c();
    2762            8 :   errors += fft_test_3d_local_omp();
    2763            8 :   errors += fft_test_3d_local_omp_r2c();
    2764              : 
    2765            8 :   clock_t end = clock();
    2766            8 :   if (cp_mpi_comm_rank(cp_mpi_get_comm_world()) == 0)
    2767            4 :     printf("Time to test local FFTs: %f\n",
    2768            4 :            (double)(end - begin) / CLOCKS_PER_SEC);
    2769              : 
    2770            8 :   return errors;
    2771              : }
    2772              : 
    2773              : // EOF
        

Generated by: LCOV version 2.0-1