cannam@127: /* cannam@127: * Copyright (c) 2003, 2007-14 Matteo Frigo cannam@127: * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology cannam@127: * cannam@127: * This program is free software; you can redistribute it and/or modify cannam@127: * it under the terms of the GNU General Public License as published by cannam@127: * the Free Software Foundation; either version 2 of the License, or cannam@127: * (at your option) any later version. cannam@127: * cannam@127: * This program is distributed in the hope that it will be useful, cannam@127: * but WITHOUT ANY WARRANTY; without even the implied warranty of cannam@127: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the cannam@127: * GNU General Public License for more details. cannam@127: * cannam@127: * You should have received a copy of the GNU General Public License cannam@127: * along with this program; if not, write to the Free Software cannam@127: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA cannam@127: * cannam@127: */ cannam@127: cannam@127: /* FFTW-MPI internal header file */ cannam@127: #ifndef __IFFTW_MPI_H__ cannam@127: #define __IFFTW_MPI_H__ cannam@127: cannam@127: #include "ifftw.h" cannam@127: #include "rdft.h" cannam@127: cannam@127: #include cannam@127: cannam@127: /* mpi problem flags: problem-dependent meaning, but in general cannam@127: SCRAMBLED means some reordering *within* the dimensions, while cannam@127: TRANSPOSED means some reordering *of* the dimensions */ cannam@127: #define SCRAMBLED_IN (1 << 0) cannam@127: #define SCRAMBLED_OUT (1 << 1) cannam@127: #define TRANSPOSED_IN (1 << 2) cannam@127: #define TRANSPOSED_OUT (1 << 3) cannam@127: #define RANK1_BIGVEC_ONLY (1 << 4) /* for rank=1, allow only bigvec solver */ cannam@127: cannam@127: #define ONLY_SCRAMBLEDP(flags) (!((flags) & ~(SCRAMBLED_IN|SCRAMBLED_OUT))) cannam@127: #define ONLY_TRANSPOSEDP(flags) (!((flags) & ~(TRANSPOSED_IN|TRANSPOSED_OUT))) cannam@127: cannam@127: #if defined(FFTW_SINGLE) cannam@127: # define FFTW_MPI_TYPE MPI_FLOAT cannam@127: #elif defined(FFTW_LDOUBLE) cannam@127: # define FFTW_MPI_TYPE MPI_LONG_DOUBLE cannam@127: #elif defined(FFTW_QUAD) cannam@127: # error MPI quad-precision type is unknown cannam@127: #else cannam@127: # define FFTW_MPI_TYPE MPI_DOUBLE cannam@127: #endif cannam@127: cannam@127: /* all fftw-mpi identifiers start with fftw_mpi (or fftwf_mpi etc.) */ cannam@127: #define XM(name) X(CONCAT(mpi_, name)) cannam@127: cannam@127: /***********************************************************************/ cannam@127: /* block distributions */ cannam@127: cannam@127: /* a distributed dimension of length n with input and output block cannam@127: sizes ib and ob, respectively. */ cannam@127: typedef enum { IB = 0, OB } block_kind; cannam@127: typedef struct { cannam@127: INT n; cannam@127: INT b[2]; /* b[IB], b[OB] */ cannam@127: } ddim; cannam@127: cannam@127: /* Loop over k in {IB, OB}. Note: need explicit casts for C++. */ cannam@127: #define FORALL_BLOCK_KIND(k) for (k = IB; k <= OB; k = (block_kind) (((int) k) + 1)) cannam@127: cannam@127: /* unlike tensors in the serial FFTW, the ordering of the dtensor cannam@127: dimensions matters - both the array and the block layout are cannam@127: row-major order. */ cannam@127: typedef struct { cannam@127: int rnk; cannam@127: #if defined(STRUCT_HACK_KR) cannam@127: ddim dims[1]; cannam@127: #elif defined(STRUCT_HACK_C99) cannam@127: ddim dims[]; cannam@127: #else cannam@127: ddim *dims; cannam@127: #endif cannam@127: } dtensor; cannam@127: cannam@127: cannam@127: /* dtensor.c: */ cannam@127: dtensor *XM(mkdtensor)(int rnk); cannam@127: void XM(dtensor_destroy)(dtensor *sz); cannam@127: dtensor *XM(dtensor_copy)(const dtensor *sz); cannam@127: dtensor *XM(dtensor_canonical)(const dtensor *sz, int compress); cannam@127: int XM(dtensor_validp)(const dtensor *sz); cannam@127: void XM(dtensor_md5)(md5 *p, const dtensor *t); cannam@127: void XM(dtensor_print)(const dtensor *t, printer *p); cannam@127: cannam@127: /* block.c: */ cannam@127: cannam@127: /* for a single distributed dimension: */ cannam@127: INT XM(num_blocks)(INT n, INT block); cannam@127: int XM(num_blocks_ok)(INT n, INT block, MPI_Comm comm); cannam@127: INT XM(default_block)(INT n, int n_pes); cannam@127: INT XM(block)(INT n, INT block, int which_block); cannam@127: cannam@127: /* for multiple distributed dimensions: */ cannam@127: INT XM(num_blocks_total)(const dtensor *sz, block_kind k); cannam@127: int XM(idle_process)(const dtensor *sz, block_kind k, int which_pe); cannam@127: void XM(block_coords)(const dtensor *sz, block_kind k, int which_pe, cannam@127: INT *coords); cannam@127: INT XM(total_block)(const dtensor *sz, block_kind k, int which_pe); cannam@127: int XM(is_local_after)(int dim, const dtensor *sz, block_kind k); cannam@127: int XM(is_local)(const dtensor *sz, block_kind k); cannam@127: int XM(is_block1d)(const dtensor *sz, block_kind k); cannam@127: cannam@127: /* choose-radix.c */ cannam@127: INT XM(choose_radix)(ddim d, int n_pes, unsigned flags, int sign, cannam@127: INT rblock[2], INT mblock[2]); cannam@127: cannam@127: /***********************************************************************/ cannam@127: /* any_true.c */ cannam@127: int XM(any_true)(int condition, MPI_Comm comm); cannam@127: int XM(md5_equal)(md5 m, MPI_Comm comm); cannam@127: cannam@127: /* conf.c */ cannam@127: void XM(conf_standard)(planner *p); cannam@127: cannam@127: /***********************************************************************/ cannam@127: /* rearrange.c */ cannam@127: cannam@127: /* Different ways to rearrange the vector dimension vn during transposition, cannam@127: reflecting different tradeoffs between ease of transposition and cannam@127: contiguity during the subsequent DFTs. cannam@127: cannam@127: TODO: can we pare this down to CONTIG and DISCONTIG, at least cannam@127: in MEASURE mode? SQUARE_MIDDLE is also used for 1d destroy-input DFTs. */ cannam@127: typedef enum { cannam@127: CONTIG = 0, /* vn x 1: make subsequent DFTs contiguous */ cannam@127: DISCONTIG, /* P x (vn/P) for P processes */ cannam@127: SQUARE_BEFORE, /* try to get square transpose at beginning */ cannam@127: SQUARE_MIDDLE, /* try to get square transpose in the middle */ cannam@127: SQUARE_AFTER /* try to get square transpose at end */ cannam@127: } rearrangement; cannam@127: cannam@127: /* skipping SQUARE_AFTER since it doesn't seem to offer any advantage cannam@127: over SQUARE_BEFORE */ cannam@127: #define FORALL_REARRANGE(rearrange) for (rearrange = CONTIG; rearrange <= SQUARE_MIDDLE; rearrange = (rearrangement) (((int) rearrange) + 1)) cannam@127: cannam@127: int XM(rearrange_applicable)(rearrangement rearrange, cannam@127: ddim dim0, INT vn, int n_pes); cannam@127: INT XM(rearrange_ny)(rearrangement rearrange, ddim dim0, INT vn, int n_pes); cannam@127: cannam@127: /***********************************************************************/ cannam@127: cannam@127: #endif /* __IFFTW_MPI_H__ */ cannam@127: