annotate src/fftw-3.3.5/mpi/choose-radix.c @ 127:7867fa7e1b6b

Current fftw source
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 18 Oct 2016 13:40:26 +0100
parents
children
rev   line source
cannam@127 1 /*
cannam@127 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
cannam@127 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
cannam@127 4 *
cannam@127 5 * This program is free software; you can redistribute it and/or modify
cannam@127 6 * it under the terms of the GNU General Public License as published by
cannam@127 7 * the Free Software Foundation; either version 2 of the License, or
cannam@127 8 * (at your option) any later version.
cannam@127 9 *
cannam@127 10 * This program is distributed in the hope that it will be useful,
cannam@127 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@127 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@127 13 * GNU General Public License for more details.
cannam@127 14 *
cannam@127 15 * You should have received a copy of the GNU General Public License
cannam@127 16 * along with this program; if not, write to the Free Software
cannam@127 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cannam@127 18 *
cannam@127 19 */
cannam@127 20
cannam@127 21 #include "ifftw-mpi.h"
cannam@127 22
cannam@127 23 /* Return the radix r for a 1d MPI transform of a distributed dimension d,
cannam@127 24 with the given flags and transform size. That is, decomposes d.n
cannam@127 25 as r * m, Cooley-Tukey style. Also computes the block sizes rblock
cannam@127 26 and mblock. Returns 0 if such a decomposition is not feasible.
cannam@127 27 This is unfortunately somewhat complicated.
cannam@127 28
cannam@127 29 A distributed Cooley-Tukey algorithm works as follows (see dft-rank1.c):
cannam@127 30
cannam@127 31 d.n is initially distributed as an m x r array with block size mblock[IB].
cannam@127 32 Then it is internally transposed to an r x m array with block size
cannam@127 33 rblock[IB]. Then it is internally transposed to m x r again with block
cannam@127 34 size mblock[OB]. Finally, it is transposed to r x m with block size
cannam@127 35 rblock[IB].
cannam@127 36
cannam@127 37 If flags & SCRAMBLED_IN, then the first transpose is skipped (the array
cannam@127 38 starts out as r x m). If flags & SCRAMBLED_OUT, then the last transpose
cannam@127 39 is skipped (the array ends up as m x r). To make sure the forward
cannam@127 40 and backward transforms use the same "scrambling" format, we swap r
cannam@127 41 and m when sign != FFT_SIGN.
cannam@127 42
cannam@127 43 There are some downsides to this, especially in the case where
cannam@127 44 either m or r is not divisible by n_pes. For one thing, it means
cannam@127 45 that in general we can't use the same block size for the input and
cannam@127 46 output. For another thing, it means that we can't in general honor
cannam@127 47 a user's "requested" block sizes in d.b[]. Therefore, for simplicity,
cannam@127 48 we simply ignore d.b[] for now.
cannam@127 49 */
cannam@127 50 INT XM(choose_radix)(ddim d, int n_pes, unsigned flags, int sign,
cannam@127 51 INT rblock[2], INT mblock[2])
cannam@127 52 {
cannam@127 53 INT r, m;
cannam@127 54
cannam@127 55 UNUSED(flags); /* we would need this if we paid attention to d.b[*] */
cannam@127 56
cannam@127 57 /* If n_pes is a factor of d.n, then choose r to be d.n / n_pes.
cannam@127 58 This not only ensures that the input (the m dimension) is
cannam@127 59 equally distributed if possible, and at the r dimension is
cannam@127 60 maximally equally distributed (if d.n/n_pes >= n_pes), it also
cannam@127 61 makes one of the local transpositions in the algorithm
cannam@127 62 trivial. */
cannam@127 63 if (d.n % n_pes == 0 /* it's good if n_pes divides d.n ...*/
cannam@127 64 && d.n / n_pes >= n_pes /* .. unless we can't use n_pes processes */)
cannam@127 65 r = d.n / n_pes;
cannam@127 66 else { /* n_pes does not divide d.n, pick a factor close to sqrt(d.n) */
cannam@127 67 for (r = X(isqrt)(d.n); d.n % r != 0; ++r)
cannam@127 68 ;
cannam@127 69 }
cannam@127 70 if (r == 1 || r == d.n) return 0; /* punt if we can't reduce size */
cannam@127 71
cannam@127 72 if (sign != FFT_SIGN) { /* swap {m,r} so that scrambling is reversible */
cannam@127 73 m = r;
cannam@127 74 r = d.n / m;
cannam@127 75 }
cannam@127 76 else
cannam@127 77 m = d.n / r;
cannam@127 78
cannam@127 79 rblock[IB] = rblock[OB] = XM(default_block)(r, n_pes);
cannam@127 80 mblock[IB] = mblock[OB] = XM(default_block)(m, n_pes);
cannam@127 81
cannam@127 82 return r;
cannam@127 83 }