annotate src/fftw-3.3.8/mpi/rdft-rank-geq2-transposed.c @ 167:bd3cc4d1df30

Add FFTW 3.3.8 source, and a Linux build
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 19 Nov 2019 14:52:55 +0000
parents
children
rev   line source
cannam@167 1 /*
cannam@167 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
cannam@167 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
cannam@167 4 *
cannam@167 5 * This program is free software; you can redistribute it and/or modify
cannam@167 6 * it under the terms of the GNU General Public License as published by
cannam@167 7 * the Free Software Foundation; either version 2 of the License, or
cannam@167 8 * (at your option) any later version.
cannam@167 9 *
cannam@167 10 * This program is distributed in the hope that it will be useful,
cannam@167 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@167 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@167 13 * GNU General Public License for more details.
cannam@167 14 *
cannam@167 15 * You should have received a copy of the GNU General Public License
cannam@167 16 * along with this program; if not, write to the Free Software
cannam@167 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cannam@167 18 *
cannam@167 19 */
cannam@167 20
cannam@167 21 /* Complex RDFTs of rank >= 2, for the case where we are distributed
cannam@167 22 across the first dimension only, and the output is transposed both
cannam@167 23 in data distribution and in ordering (for the first 2 dimensions).
cannam@167 24
cannam@167 25 (Note that we don't have to handle the case where the input is
cannam@167 26 transposed, since this is equivalent to transposed output with the
cannam@167 27 first two dimensions swapped, and is automatically canonicalized as
cannam@167 28 such by rdft-problem.c. */
cannam@167 29
cannam@167 30 #include "mpi-rdft.h"
cannam@167 31 #include "mpi-transpose.h"
cannam@167 32
cannam@167 33 typedef struct {
cannam@167 34 solver super;
cannam@167 35 int preserve_input; /* preserve input even if DESTROY_INPUT was passed */
cannam@167 36 } S;
cannam@167 37
cannam@167 38 typedef struct {
cannam@167 39 plan_mpi_rdft super;
cannam@167 40
cannam@167 41 plan *cld1, *cldt, *cld2;
cannam@167 42 INT roff, ioff;
cannam@167 43 int preserve_input;
cannam@167 44 } P;
cannam@167 45
cannam@167 46 static void apply(const plan *ego_, R *I, R *O)
cannam@167 47 {
cannam@167 48 const P *ego = (const P *) ego_;
cannam@167 49 plan_rdft *cld1, *cld2, *cldt;
cannam@167 50
cannam@167 51 /* RDFT local dimensions */
cannam@167 52 cld1 = (plan_rdft *) ego->cld1;
cannam@167 53 if (ego->preserve_input) {
cannam@167 54 cld1->apply(ego->cld1, I, O);
cannam@167 55 I = O;
cannam@167 56 }
cannam@167 57 else
cannam@167 58 cld1->apply(ego->cld1, I, I);
cannam@167 59
cannam@167 60 /* global transpose */
cannam@167 61 cldt = (plan_rdft *) ego->cldt;
cannam@167 62 cldt->apply(ego->cldt, I, O);
cannam@167 63
cannam@167 64 /* RDFT final local dimension */
cannam@167 65 cld2 = (plan_rdft *) ego->cld2;
cannam@167 66 cld2->apply(ego->cld2, O, O);
cannam@167 67 }
cannam@167 68
cannam@167 69 static int applicable(const S *ego, const problem *p_,
cannam@167 70 const planner *plnr)
cannam@167 71 {
cannam@167 72 const problem_mpi_rdft *p = (const problem_mpi_rdft *) p_;
cannam@167 73 return (1
cannam@167 74 && p->sz->rnk > 1
cannam@167 75 && p->flags == TRANSPOSED_OUT
cannam@167 76 && (!ego->preserve_input || (!NO_DESTROY_INPUTP(plnr)
cannam@167 77 && p->I != p->O))
cannam@167 78 && XM(is_local_after)(1, p->sz, IB)
cannam@167 79 && XM(is_local_after)(2, p->sz, OB)
cannam@167 80 && XM(num_blocks)(p->sz->dims[0].n, p->sz->dims[0].b[OB]) == 1
cannam@167 81 && (!NO_SLOWP(plnr) /* slow if rdft-serial is applicable */
cannam@167 82 || !XM(rdft_serial_applicable)(p))
cannam@167 83 );
cannam@167 84 }
cannam@167 85
cannam@167 86 static void awake(plan *ego_, enum wakefulness wakefulness)
cannam@167 87 {
cannam@167 88 P *ego = (P *) ego_;
cannam@167 89 X(plan_awake)(ego->cld1, wakefulness);
cannam@167 90 X(plan_awake)(ego->cldt, wakefulness);
cannam@167 91 X(plan_awake)(ego->cld2, wakefulness);
cannam@167 92 }
cannam@167 93
cannam@167 94 static void destroy(plan *ego_)
cannam@167 95 {
cannam@167 96 P *ego = (P *) ego_;
cannam@167 97 X(plan_destroy_internal)(ego->cld2);
cannam@167 98 X(plan_destroy_internal)(ego->cldt);
cannam@167 99 X(plan_destroy_internal)(ego->cld1);
cannam@167 100 }
cannam@167 101
cannam@167 102 static void print(const plan *ego_, printer *p)
cannam@167 103 {
cannam@167 104 const P *ego = (const P *) ego_;
cannam@167 105 p->print(p, "(mpi-rdft-rank-geq2-transposed%s%(%p%)%(%p%)%(%p%))",
cannam@167 106 ego->preserve_input==2 ?"/p":"",
cannam@167 107 ego->cld1, ego->cldt, ego->cld2);
cannam@167 108 }
cannam@167 109
cannam@167 110 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
cannam@167 111 {
cannam@167 112 const S *ego = (const S *) ego_;
cannam@167 113 const problem_mpi_rdft *p;
cannam@167 114 P *pln;
cannam@167 115 plan *cld1 = 0, *cldt = 0, *cld2 = 0;
cannam@167 116 R *I, *O, *I2;
cannam@167 117 tensor *sz;
cannam@167 118 int i, my_pe, n_pes;
cannam@167 119 INT nrest;
cannam@167 120 static const plan_adt padt = {
cannam@167 121 XM(rdft_solve), awake, print, destroy
cannam@167 122 };
cannam@167 123
cannam@167 124 UNUSED(ego);
cannam@167 125
cannam@167 126 if (!applicable(ego, p_, plnr))
cannam@167 127 return (plan *) 0;
cannam@167 128
cannam@167 129 p = (const problem_mpi_rdft *) p_;
cannam@167 130
cannam@167 131 I2 = I = p->I;
cannam@167 132 O = p->O;
cannam@167 133 if (ego->preserve_input || NO_DESTROY_INPUTP(plnr))
cannam@167 134 I = O;
cannam@167 135 MPI_Comm_rank(p->comm, &my_pe);
cannam@167 136 MPI_Comm_size(p->comm, &n_pes);
cannam@167 137
cannam@167 138 sz = X(mktensor)(p->sz->rnk - 1); /* tensor of last rnk-1 dimensions */
cannam@167 139 i = p->sz->rnk - 2; A(i >= 0);
cannam@167 140 sz->dims[i].n = p->sz->dims[i+1].n;
cannam@167 141 sz->dims[i].is = sz->dims[i].os = p->vn;
cannam@167 142 for (--i; i >= 0; --i) {
cannam@167 143 sz->dims[i].n = p->sz->dims[i+1].n;
cannam@167 144 sz->dims[i].is = sz->dims[i].os = sz->dims[i+1].n * sz->dims[i+1].is;
cannam@167 145 }
cannam@167 146 nrest = 1; for (i = 1; i < sz->rnk; ++i) nrest *= sz->dims[i].n;
cannam@167 147 {
cannam@167 148 INT is = sz->dims[0].n * sz->dims[0].is;
cannam@167 149 INT b = XM(block)(p->sz->dims[0].n, p->sz->dims[0].b[IB], my_pe);
cannam@167 150 cld1 = X(mkplan_d)(plnr,
cannam@167 151 X(mkproblem_rdft_d)(sz,
cannam@167 152 X(mktensor_2d)(b, is, is,
cannam@167 153 p->vn, 1, 1),
cannam@167 154 I2, I, p->kind + 1));
cannam@167 155 if (XM(any_true)(!cld1, p->comm)) goto nada;
cannam@167 156 }
cannam@167 157
cannam@167 158 nrest *= p->vn;
cannam@167 159 cldt = X(mkplan_d)(plnr,
cannam@167 160 XM(mkproblem_transpose)(
cannam@167 161 p->sz->dims[0].n, p->sz->dims[1].n, nrest,
cannam@167 162 I, O,
cannam@167 163 p->sz->dims[0].b[IB], p->sz->dims[1].b[OB],
cannam@167 164 p->comm, 0));
cannam@167 165 if (XM(any_true)(!cldt, p->comm)) goto nada;
cannam@167 166
cannam@167 167 {
cannam@167 168 INT is = p->sz->dims[0].n * nrest;
cannam@167 169 INT b = XM(block)(p->sz->dims[1].n, p->sz->dims[1].b[OB], my_pe);
cannam@167 170 cld2 = X(mkplan_d)(plnr,
cannam@167 171 X(mkproblem_rdft_1_d)(X(mktensor_1d)(
cannam@167 172 p->sz->dims[0].n,
cannam@167 173 nrest, nrest),
cannam@167 174 X(mktensor_2d)(b, is, is,
cannam@167 175 nrest, 1, 1),
cannam@167 176 O, O, p->kind[0]));
cannam@167 177 if (XM(any_true)(!cld2, p->comm)) goto nada;
cannam@167 178 }
cannam@167 179
cannam@167 180 pln = MKPLAN_MPI_RDFT(P, &padt, apply);
cannam@167 181 pln->cld1 = cld1;
cannam@167 182 pln->cldt = cldt;
cannam@167 183 pln->cld2 = cld2;
cannam@167 184 pln->preserve_input = ego->preserve_input ? 2 : NO_DESTROY_INPUTP(plnr);
cannam@167 185
cannam@167 186 X(ops_add)(&cld1->ops, &cld2->ops, &pln->super.super.ops);
cannam@167 187 X(ops_add2)(&cldt->ops, &pln->super.super.ops);
cannam@167 188
cannam@167 189 return &(pln->super.super);
cannam@167 190
cannam@167 191 nada:
cannam@167 192 X(plan_destroy_internal)(cld2);
cannam@167 193 X(plan_destroy_internal)(cldt);
cannam@167 194 X(plan_destroy_internal)(cld1);
cannam@167 195 return (plan *) 0;
cannam@167 196 }
cannam@167 197
cannam@167 198 static solver *mksolver(int preserve_input)
cannam@167 199 {
cannam@167 200 static const solver_adt sadt = { PROBLEM_MPI_RDFT, mkplan, 0 };
cannam@167 201 S *slv = MKSOLVER(S, &sadt);
cannam@167 202 slv->preserve_input = preserve_input;
cannam@167 203 return &(slv->super);
cannam@167 204 }
cannam@167 205
cannam@167 206 void XM(rdft_rank_geq2_transposed_register)(planner *p)
cannam@167 207 {
cannam@167 208 int preserve_input;
cannam@167 209 for (preserve_input = 0; preserve_input <= 1; ++preserve_input)
cannam@167 210 REGISTER_SOLVER(p, mksolver(preserve_input));
cannam@167 211 }