annotate fft/fftw/fftw-3.3.4/mpi/block.c @ 40:223f770b5341 kissfft-double tip

Try a double-precision kissfft
author Chris Cannam
date Wed, 07 Sep 2016 10:40:32 +0100
parents 26056e866c29
children
rev   line source
Chris@19 1 /*
Chris@19 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@19 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
Chris@19 4 *
Chris@19 5 * This program is free software; you can redistribute it and/or modify
Chris@19 6 * it under the terms of the GNU General Public License as published by
Chris@19 7 * the Free Software Foundation; either version 2 of the License, or
Chris@19 8 * (at your option) any later version.
Chris@19 9 *
Chris@19 10 * This program is distributed in the hope that it will be useful,
Chris@19 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@19 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@19 13 * GNU General Public License for more details.
Chris@19 14 *
Chris@19 15 * You should have received a copy of the GNU General Public License
Chris@19 16 * along with this program; if not, write to the Free Software
Chris@19 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@19 18 *
Chris@19 19 */
Chris@19 20
Chris@19 21 #include "ifftw-mpi.h"
Chris@19 22
Chris@19 23 INT XM(num_blocks)(INT n, INT block)
Chris@19 24 {
Chris@19 25 return (n + block - 1) / block;
Chris@19 26 }
Chris@19 27
Chris@19 28 int XM(num_blocks_ok)(INT n, INT block, MPI_Comm comm)
Chris@19 29 {
Chris@19 30 int n_pes;
Chris@19 31 MPI_Comm_size(comm, &n_pes);
Chris@19 32 return n_pes >= XM(num_blocks)(n, block);
Chris@19 33 }
Chris@19 34
Chris@19 35 /* Pick a default block size for dividing a problem of size n among
Chris@19 36 n_pes processes. Divide as equally as possible, while minimizing
Chris@19 37 the maximum block size among the processes as well as the number of
Chris@19 38 processes with nonzero blocks. */
Chris@19 39 INT XM(default_block)(INT n, int n_pes)
Chris@19 40 {
Chris@19 41 return ((n + n_pes - 1) / n_pes);
Chris@19 42 }
Chris@19 43
Chris@19 44 /* For a given block size and dimension n, compute the block size
Chris@19 45 on the given process. */
Chris@19 46 INT XM(block)(INT n, INT block, int which_block)
Chris@19 47 {
Chris@19 48 INT d = n - which_block * block;
Chris@19 49 return d <= 0 ? 0 : (d > block ? block : d);
Chris@19 50 }
Chris@19 51
Chris@19 52 static INT num_blocks_kind(const ddim *dim, block_kind k)
Chris@19 53 {
Chris@19 54 return XM(num_blocks)(dim->n, dim->b[k]);
Chris@19 55 }
Chris@19 56
Chris@19 57 INT XM(num_blocks_total)(const dtensor *sz, block_kind k)
Chris@19 58 {
Chris@19 59 if (FINITE_RNK(sz->rnk)) {
Chris@19 60 int i;
Chris@19 61 INT ntot = 1;
Chris@19 62 for (i = 0; i < sz->rnk; ++i)
Chris@19 63 ntot *= num_blocks_kind(sz->dims + i, k);
Chris@19 64 return ntot;
Chris@19 65 }
Chris@19 66 else
Chris@19 67 return 0;
Chris@19 68 }
Chris@19 69
Chris@19 70 int XM(idle_process)(const dtensor *sz, block_kind k, int which_pe)
Chris@19 71 {
Chris@19 72 return (which_pe >= XM(num_blocks_total)(sz, k));
Chris@19 73 }
Chris@19 74
Chris@19 75 /* Given a non-idle process which_pe, computes the coordinate
Chris@19 76 vector coords[rnk] giving the coordinates of a block in the
Chris@19 77 matrix of blocks. k specifies whether we are talking about
Chris@19 78 the input or output data distribution. */
Chris@19 79 void XM(block_coords)(const dtensor *sz, block_kind k, int which_pe,
Chris@19 80 INT *coords)
Chris@19 81 {
Chris@19 82 int i;
Chris@19 83 A(!XM(idle_process)(sz, k, which_pe) && FINITE_RNK(sz->rnk));
Chris@19 84 for (i = sz->rnk - 1; i >= 0; --i) {
Chris@19 85 INT nb = num_blocks_kind(sz->dims + i, k);
Chris@19 86 coords[i] = which_pe % nb;
Chris@19 87 which_pe /= nb;
Chris@19 88 }
Chris@19 89 }
Chris@19 90
Chris@19 91 INT XM(total_block)(const dtensor *sz, block_kind k, int which_pe)
Chris@19 92 {
Chris@19 93 if (XM(idle_process)(sz, k, which_pe))
Chris@19 94 return 0;
Chris@19 95 else {
Chris@19 96 int i;
Chris@19 97 INT N = 1, *coords;
Chris@19 98 STACK_MALLOC(INT*, coords, sizeof(INT) * sz->rnk);
Chris@19 99 XM(block_coords)(sz, k, which_pe, coords);
Chris@19 100 for (i = 0; i < sz->rnk; ++i)
Chris@19 101 N *= XM(block)(sz->dims[i].n, sz->dims[i].b[k], coords[i]);
Chris@19 102 STACK_FREE(coords);
Chris@19 103 return N;
Chris@19 104 }
Chris@19 105 }
Chris@19 106
Chris@19 107 /* returns whether sz is local for dims >= dim */
Chris@19 108 int XM(is_local_after)(int dim, const dtensor *sz, block_kind k)
Chris@19 109 {
Chris@19 110 if (FINITE_RNK(sz->rnk))
Chris@19 111 for (; dim < sz->rnk; ++dim)
Chris@19 112 if (XM(num_blocks)(sz->dims[dim].n, sz->dims[dim].b[k]) > 1)
Chris@19 113 return 0;
Chris@19 114 return 1;
Chris@19 115 }
Chris@19 116
Chris@19 117 int XM(is_local)(const dtensor *sz, block_kind k)
Chris@19 118 {
Chris@19 119 return XM(is_local_after)(0, sz, k);
Chris@19 120 }
Chris@19 121
Chris@19 122 /* Return whether sz is distributed for k according to a simple
Chris@19 123 1d block distribution in the first or second dimensions */
Chris@19 124 int XM(is_block1d)(const dtensor *sz, block_kind k)
Chris@19 125 {
Chris@19 126 int i;
Chris@19 127 if (!FINITE_RNK(sz->rnk)) return 0;
Chris@19 128 for (i = 0; i < sz->rnk && num_blocks_kind(sz->dims + i, k) == 1; ++i) ;
Chris@19 129 return(i < sz->rnk && i < 2 && XM(is_local_after)(i + 1, sz, k));
Chris@19 130
Chris@19 131 }