22typedef int fft_key_t[KEY_SIZE];
40#define FFT_KEY_INPLACE 8
43#define FFT_KEY_FORWARD 16
59static inline void set_nd_key(
int *key,
const int rank,
const int fft_size[3],
60 const int number_of_ffts,
const bool direction,
61 const bool inplace,
const bool is_r2c,
62 const int istride,
const int idist,
63 const int ostride,
const int odist) {
64 int inembed[3] = {0, 0, 0};
65 int onembed[3] = {0, 0, 0};
66 for (
int r = 0; r < rank; r++) {
67 inembed[r] = fft_size[r];
68 onembed[r] = fft_size[r];
70 if (is_r2c && rank > 0) {
71 const int r = rank - 1;
73 onembed[r] = fft_size[r] / 2 + 1;
75 inembed[r] = 2 * (fft_size[r] / 2 + 1);
77 inembed[r] = fft_size[r] / 2 + 1;
79 onembed[r] = 2 * (fft_size[r] / 2 + 1);
82 for (
int d = 0;
d < 4;
d++) {
87 for (
int d = 0;
d < rank;
d++)
88 key[3 + d] = fft_size[d];
89 key[3 + rank] = number_of_ffts;
91 for (
int d = 1;
d < rank;
d++)
92 key[7 + d] = key[7 + d - 1] * inembed[d - 1];
93 key[7 + rank] = idist;
95 for (
int d = 1;
d < rank;
d++)
96 key[11 + d] = key[11 + d - 1] * onembed[d - 1];
97 key[11 + rank] = odist;
105get_key_1d(
const bool direction,
const int fft_size,
const int number_of_ffts,
106 const bool transpose_in,
const bool transpose_out,
107 const int leading_dimension_in,
const int leading_dimension_out,
108 const int number_of_threads,
const bool inplace,
int *key) {
109 cp_assert((!inplace || (transpose_in == transpose_out)) &&
110 "Inplace plans need the same strides for input and output arrays!");
111 const int fft_size_3d[3] = {fft_size, 0, 0};
112 const int istride = transpose_in ? leading_dimension_in : 1;
113 const int idist = transpose_in ? 1 : leading_dimension_in;
114 const int ostride = transpose_out ? leading_dimension_out : 1;
115 const int odist = transpose_out ? 1 : leading_dimension_out;
116 key[0] = 1 + FFT_KEY_INPLACE * inplace + direction * FFT_KEY_FORWARD;
118 key[2] = number_of_threads;
119 set_nd_key(key, 1, fft_size_3d, number_of_ffts, direction, inplace,
false,
120 istride, idist, ostride, odist);
128get_key_1d_r2c(
const bool direction,
const int fft_size,
129 const int number_of_ffts,
const bool transpose_in,
130 const bool transpose_out,
const int leading_dimension_in,
131 const int leading_dimension_out,
const int number_of_threads,
132 const bool inplace,
int *key) {
133 cp_assert((!inplace || (transpose_in == transpose_out)) &&
134 "Inplace plans need the same strides for input and output arrays!");
135 const int fft_size_3d[3] = {fft_size, 0, 0};
136 const int istride = transpose_in ? leading_dimension_in : 1;
137 const int idist = transpose_in ? 1 : leading_dimension_in;
138 const int ostride = transpose_out ? leading_dimension_out : 1;
139 const int odist = transpose_out ? 1 : leading_dimension_out;
141 1 + FFT_KEY_R2C + FFT_KEY_INPLACE * inplace + direction * FFT_KEY_FORWARD;
143 key[2] = number_of_threads;
144 set_nd_key(key, 1, fft_size_3d, number_of_ffts, direction, inplace,
true,
145 istride, idist, ostride, odist);
152static inline void get_key_2d(
const bool direction,
const int fft_size[2],
153 const int number_of_ffts,
const bool transpose_in,
154 const bool transpose_out,
155 const int leading_dimension_in,
156 const int leading_dimension_out,
157 const int number_of_threads,
const bool inplace,
159 cp_assert((!inplace || (transpose_in == transpose_out)) &&
160 "Inplace plans need the same strides for input and output arrays!");
161 const int fft_size_3d[3] = {fft_size[0], fft_size[1], 0};
162 const int istride = transpose_in ? leading_dimension_in : 1;
163 const int idist = transpose_in ? 1 : leading_dimension_in;
164 const int ostride = transpose_out ? leading_dimension_out : 1;
165 const int odist = transpose_out ? 1 : leading_dimension_out;
166 key[0] = 2 + FFT_KEY_INPLACE * inplace + direction * FFT_KEY_FORWARD;
168 key[2] = number_of_threads;
169 set_nd_key(key, 2, fft_size_3d, number_of_ffts, direction, inplace,
false,
170 istride, idist, ostride, odist);
178get_key_2d_r2c(
const bool direction,
const int fft_size[2],
179 const int number_of_ffts,
const bool transpose_in,
180 const bool transpose_out,
const int leading_dimension_in,
181 const int leading_dimension_out,
const int number_of_threads,
182 const bool inplace,
int *key) {
183 cp_assert((!inplace || (transpose_in == transpose_out)) &&
184 "Inplace plans need the same strides for input and output arrays!");
185 const int fft_size_3d[3] = {fft_size[0], fft_size[1], 0};
186 const int istride = transpose_in ? leading_dimension_in : 1;
187 const int idist = transpose_in ? 1 : leading_dimension_in;
188 const int ostride = transpose_out ? leading_dimension_out : 1;
189 const int odist = transpose_out ? 1 : leading_dimension_out;
191 2 + FFT_KEY_R2C + FFT_KEY_INPLACE * inplace + direction * FFT_KEY_FORWARD;
193 key[2] = number_of_threads;
194 set_nd_key(key, 2, fft_size_3d, number_of_ffts, direction, inplace,
true,
195 istride, idist, ostride, odist);
202static inline void get_key_3d(
const bool direction,
const int fft_size[3],
203 const int number_of_ffts,
const bool transpose_in,
204 const bool transpose_out,
205 const int number_of_threads,
const bool inplace,
207 cp_assert((!inplace || (transpose_in == transpose_out)) &&
208 "Inplace plans need the same strides for input and output arrays!");
209 const int volume = fft_size[0] * fft_size[1] * fft_size[2];
210 const int istride = transpose_in ? number_of_ffts : 1;
211 const int idist = transpose_in ? 1 : volume;
212 const int ostride = transpose_out ? number_of_ffts : 1;
213 const int odist = transpose_out ? 1 : volume;
214 key[0] = 3 + FFT_KEY_INPLACE * inplace + direction * FFT_KEY_FORWARD;
216 key[2] = number_of_threads;
217 set_nd_key(key, 3, fft_size, number_of_ffts, direction, inplace,
false,
218 istride, idist, ostride, odist);
225static inline void get_key_3d_r2c(
const bool direction,
const int fft_size[3],
226 const int number_of_ffts,
227 const bool transpose_in,
228 const bool transpose_out,
229 const int number_of_threads,
230 const bool inplace,
int *key) {
231 cp_assert((!inplace || (transpose_in == transpose_out)) &&
232 "Inplace plans need the same strides for input and output arrays!");
233 const int real_volume = fft_size[0] * fft_size[1] * fft_size[2];
234 const int complex_volume = fft_size[0] * fft_size[1] * (fft_size[2] / 2 + 1);
235 const int input_volume =
236 direction ? (inplace ? 2 * complex_volume : real_volume) : complex_volume;
237 const int output_volume =
238 direction ? complex_volume : (inplace ? 2 * complex_volume : real_volume);
239 const int istride = transpose_in ? number_of_ffts : 1;
240 const int idist = transpose_in ? 1 : input_volume;
241 const int ostride = transpose_out ? number_of_ffts : 1;
242 const int odist = transpose_out ? 1 : output_volume;
244 3 + FFT_KEY_R2C + FFT_KEY_INPLACE * inplace + direction * FFT_KEY_FORWARD;
246 key[2] = number_of_threads;
247 set_nd_key(key, 3, fft_size, number_of_ffts, direction, inplace,
true,
248 istride, idist, ostride, odist);
255static inline void get_key_guru(
const bool direction,
int rank,
256 const fftw_iodim *dims,
int howmany_rank,
257 const fftw_iodim *howmany_dims,
258 const int number_of_threads,
const bool inplace,
260 key[0] = rank + FFT_KEY_INPLACE * inplace + direction * FFT_KEY_FORWARD;
262 "Larger combined ranks than 4 are not implemented\n");
265 key[2] = number_of_threads;
266 for (
int d = 0;
d < 4;
d++) {
271 for (
int d = 0;
d < rank;
d++) {
272 key[3 +
d] = dims[
d].n;
273 key[7 +
d] = dims[
d].is;
274 key[11 +
d] = dims[
d].os;
276 for (
int d = 0;
d < howmany_rank;
d++) {
277 key[3 + rank +
d] = howmany_dims[
d].n;
278 key[7 + rank +
d] = howmany_dims[
d].is;
279 key[11 + rank +
d] = howmany_dims[
d].os;
287static inline void get_key_guru_r2c(
const bool direction,
int rank,
288 const fftw_iodim *dims,
int howmany_rank,
289 const fftw_iodim *howmany_dims,
290 const int number_of_threads,
291 const bool inplace,
int *key) {
292 key[0] = rank + FFT_KEY_R2C + FFT_KEY_INPLACE * inplace +
293 direction * FFT_KEY_FORWARD;
295 "Larger combined ranks than 4 are not implemented\n");
298 key[2] = number_of_threads;
299 for (
int d = 0;
d < 4;
d++) {
304 for (
int d = 0;
d < rank;
d++) {
305 key[3 +
d] = dims[
d].n;
306 key[7 +
d] = dims[
d].is;
307 key[11 +
d] = dims[
d].os;
309 for (
int d = 0;
d < howmany_rank;
d++) {
310 key[3 + rank +
d] = howmany_dims[
d].n;
311 key[7 + rank +
d] = howmany_dims[
d].is;
312 key[11 + rank +
d] = howmany_dims[
d].os;
320static inline int get_buffer_size_from_key(
const fft_key_t key) {
321 const int rank = key[0] % 4;
322 const bool is_r2c = (key[0] & FFT_KEY_R2C) == FFT_KEY_R2C;
323 const bool direction = (key[0] & FFT_KEY_FORWARD) == FFT_KEY_FORWARD;
324 const bool inplace = (key[0] & FFT_KEY_INPLACE) == FFT_KEY_INPLACE;
326 while (used > 0 && key[3 + used - 1] == 0)
331 for (
int side = 0; side < 2; side++) {
332 const int *strides = (side == 0) ? &key[7] : &key[11];
334 for (
int d = 0;
d < used;
d++) {
336 const bool complex_side =
337 (side == 0 && !direction) || (side == 1 && direction);
338 if (is_r2c && d == rank - 1) {
339 const int half = n / 2 + 1;
343 n = inplace ? 2 *
half : n;
346 span += (n - 1) * strides[d];
370static inline void fetch_data_from_key_nd(
371 const fft_key_t key,
int *rank,
int *fft_size,
int *number_of_ffts,
372 int *number_of_threads,
bool *direction,
bool *inplace,
int *inembed,
373 int *onembed,
int *idist,
int *odist,
int *istride,
int *ostride) {
375 "Distributed FFTs are not supported in this function!");
377 *inplace = (key[0] & FFT_KEY_INPLACE) == FFT_KEY_INPLACE;
378 *number_of_threads = key[2];
379 *direction = (key[0] & FFT_KEY_FORWARD) == FFT_KEY_FORWARD;
380 const int is_r2c = (key[0] & FFT_KEY_R2C) == FFT_KEY_R2C;
381 for (
int r = 0; r < *rank; r++) {
382 fft_size[r] = key[3 + r];
384 inembed[r] = key[3 + r];
385 onembed[r] = key[3 + r];
388 inembed[r] = is_r2c && *inplace ? 2 * (key[3 + r] / 2 + 1) : key[3 + r];
389 onembed[r] = is_r2c ? key[3 + r] / 2 + 1 : key[3 + r];
391 inembed[r] = is_r2c ? key[3 + r] / 2 + 1 : key[3 + r];
392 onembed[r] = is_r2c && *inplace ? 2 * (key[3 + r] / 2 + 1) : key[3 + r];
396 *number_of_ffts = key[3 + *rank];
397 *idist = key[7 + *rank];
398 *odist = key[11 + *rank];
414static inline void fetch_data_from_key_guru(
const fft_key_t key,
415 bool *direction,
int *rank,
416 fftw_iodim *dims,
int *howmany_rank,
417 fftw_iodim *howmany_dims,
418 int *number_of_threads,
421 "Distributed FFTs are not supported in this function!");
422 *direction = (key[0] & FFT_KEY_FORWARD) == FFT_KEY_FORWARD;
423 *inplace = (key[0] & FFT_KEY_INPLACE) == FFT_KEY_INPLACE;
426 while (used > 0 && key[3 + used - 1] == 0)
428 *howmany_rank = used > *rank ? used - *rank : 0;
429 for (
int r = 0; r < *rank; r++) {
430 dims[r].n = key[3 + r];
431 dims[r].is = key[7 + r];
432 dims[r].os = key[11 + r];
434 for (
int r = 0; r < *howmany_rank; r++) {
435 howmany_dims[r].n = key[3 + *rank + r];
436 howmany_dims[r].is = key[7 + *rank + r];
437 howmany_dims[r].os = key[11 + *rank + r];
439 *number_of_threads = key[2];
#define cp_assert(condition)
int cp_mpi_comm_c2f(const cp_mpi_comm_t comm)
Wrapper around MPI_Comm_c2f.
cp_mpi_comm_t cp_mpi_get_comm_null(void)
Returns MPI_COMM_WORLD.
real(kind=dp), parameter, public half