annotate src/fftw-3.3.5/mpi/rdft-rank-geq2-transposed.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 /* Complex RDFTs of rank >= 2, for the case where we are distributed
cannam@127 22 across the first dimension only, and the output is transposed both
cannam@127 23 in data distribution and in ordering (for the first 2 dimensions).
cannam@127 24
cannam@127 25 (Note that we don't have to handle the case where the input is
cannam@127 26 transposed, since this is equivalent to transposed output with the
cannam@127 27 first two dimensions swapped, and is automatically canonicalized as
cannam@127 28 such by rdft-problem.c. */
cannam@127 29
cannam@127 30 #include "mpi-rdft.h"
cannam@127 31 #include "mpi-transpose.h"
cannam@127 32
cannam@127 33 typedef struct {
cannam@127 34 solver super;
cannam@127 35 int preserve_input; /* preserve input even if DESTROY_INPUT was passed */
cannam@127 36 } S;
cannam@127 37
cannam@127 38 typedef struct {
cannam@127 39 plan_mpi_rdft super;
cannam@127 40
cannam@127 41 plan *cld1, *cldt, *cld2;
cannam@127 42 INT roff, ioff;
cannam@127 43 int preserve_input;
cannam@127 44 } P;
cannam@127 45
cannam@127 46 static void apply(const plan *ego_, R *I, R *O)
cannam@127 47 {
cannam@127 48 const P *ego = (const P *) ego_;
cannam@127 49 plan_rdft *cld1, *cld2, *cldt;
cannam@127 50
cannam@127 51 /* RDFT local dimensions */
cannam@127 52 cld1 = (plan_rdft *) ego->cld1;
cannam@127 53 if (ego->preserve_input) {
cannam@127 54 cld1->apply(ego->cld1, I, O);
cannam@127 55 I = O;
cannam@127 56 }
cannam@127 57 else
cannam@127 58 cld1->apply(ego->cld1, I, I);
cannam@127 59
cannam@127 60 /* global transpose */
cannam@127 61 cldt = (plan_rdft *) ego->cldt;
cannam@127 62 cldt->apply(ego->cldt, I, O);
cannam@127 63
cannam@127 64 /* RDFT final local dimension */
cannam@127 65 cld2 = (plan_rdft *) ego->cld2;
cannam@127 66 cld2->apply(ego->cld2, O, O);
cannam@127 67 }
cannam@127 68
cannam@127 69 static int applicable(const S *ego, const problem *p_,
cannam@127 70 const planner *plnr)
cannam@127 71 {
cannam@127 72 const problem_mpi_rdft *p = (const problem_mpi_rdft *) p_;
cannam@127 73 return (1
cannam@127 74 && p->sz->rnk > 1
cannam@127 75 && p->flags == TRANSPOSED_OUT
cannam@127 76 && (!ego->preserve_input || (!NO_DESTROY_INPUTP(plnr)
cannam@127 77 && p->I != p->O))
cannam@127 78 && XM(is_local_after)(1, p->sz, IB)
cannam@127 79 && XM(is_local_after)(2, p->sz, OB)
cannam@127 80 && XM(num_blocks)(p->sz->dims[0].n, p->sz->dims[0].b[OB]) == 1
cannam@127 81 && (!NO_SLOWP(plnr) /* slow if rdft-serial is applicable */
cannam@127 82 || !XM(rdft_serial_applicable)(p))
cannam@127 83 );
cannam@127 84 }
cannam@127 85
cannam@127 86 static void awake(plan *ego_, enum wakefulness wakefulness)
cannam@127 87 {
cannam@127 88 P *ego = (P *) ego_;
cannam@127 89 X(plan_awake)(ego->cld1, wakefulness);
cannam@127 90 X(plan_awake)(ego->cldt, wakefulness);
cannam@127 91 X(plan_awake)(ego->cld2, wakefulness);
cannam@127 92 }
cannam@127 93
cannam@127 94 static void destroy(plan *ego_)
cannam@127 95 {
cannam@127 96 P *ego = (P *) ego_;
cannam@127 97 X(plan_destroy_internal)(ego->cld2);
cannam@127 98 X(plan_destroy_internal)(ego->cldt);
cannam@127 99 X(plan_destroy_internal)(ego->cld1);
cannam@127 100 }
cannam@127 101
cannam@127 102 static void print(const plan *ego_, printer *p)
cannam@127 103 {
cannam@127 104 const P *ego = (const P *) ego_;
cannam@127 105 p->print(p, "(mpi-rdft-rank-geq2-transposed%s%(%p%)%(%p%)%(%p%))",
cannam@127 106 ego->preserve_input==2 ?"/p":"",
cannam@127 107 ego->cld1, ego->cldt, ego->cld2);
cannam@127 108 }
cannam@127 109
cannam@127 110 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
cannam@127 111 {
cannam@127 112 const S *ego = (const S *) ego_;
cannam@127 113 const problem_mpi_rdft *p;
cannam@127 114 P *pln;
cannam@127 115 plan *cld1 = 0, *cldt = 0, *cld2 = 0;
cannam@127 116 R *I, *O, *I2;
cannam@127 117 tensor *sz;
cannam@127 118 int i, my_pe, n_pes;
cannam@127 119 INT nrest;
cannam@127 120 static const plan_adt padt = {
cannam@127 121 XM(rdft_solve), awake, print, destroy
cannam@127 122 };
cannam@127 123
cannam@127 124 UNUSED(ego);
cannam@127 125
cannam@127 126 if (!applicable(ego, p_, plnr))
cannam@127 127 return (plan *) 0;
cannam@127 128
cannam@127 129 p = (const problem_mpi_rdft *) p_;
cannam@127 130
cannam@127 131 I2 = I = p->I;
cannam@127 132 O = p->O;
cannam@127 133 if (ego->preserve_input || NO_DESTROY_INPUTP(plnr))
cannam@127 134 I = O;
cannam@127 135 MPI_Comm_rank(p->comm, &my_pe);
cannam@127 136 MPI_Comm_size(p->comm, &n_pes);
cannam@127 137
cannam@127 138 sz = X(mktensor)(p->sz->rnk - 1); /* tensor of last rnk-1 dimensions */
cannam@127 139 i = p->sz->rnk - 2; A(i >= 0);
cannam@127 140 sz->dims[i].n = p->sz->dims[i+1].n;
cannam@127 141 sz->dims[i].is = sz->dims[i].os = p->vn;
cannam@127 142 for (--i; i >= 0; --i) {
cannam@127 143 sz->dims[i].n = p->sz->dims[i+1].n;
cannam@127 144 sz->dims[i].is = sz->dims[i].os = sz->dims[i+1].n * sz->dims[i+1].is;
cannam@127 145 }
cannam@127 146 nrest = 1; for (i = 1; i < sz->rnk; ++i) nrest *= sz->dims[i].n;
cannam@127 147 {
cannam@127 148 INT is = sz->dims[0].n * sz->dims[0].is;
cannam@127 149 INT b = XM(block)(p->sz->dims[0].n, p->sz->dims[0].b[IB], my_pe);
cannam@127 150 cld1 = X(mkplan_d)(plnr,
cannam@127 151 X(mkproblem_rdft_d)(sz,
cannam@127 152 X(mktensor_2d)(b, is, is,
cannam@127 153 p->vn, 1, 1),
cannam@127 154 I2, I, p->kind + 1));
cannam@127 155 if (XM(any_true)(!cld1, p->comm)) goto nada;
cannam@127 156 }
cannam@127 157
cannam@127 158 nrest *= p->vn;
cannam@127 159 cldt = X(mkplan_d)(plnr,
cannam@127 160 XM(mkproblem_transpose)(
cannam@127 161 p->sz->dims[0].n, p->sz->dims[1].n, nrest,
cannam@127 162 I, O,
cannam@127 163 p->sz->dims[0].b[IB], p->sz->dims[1].b[OB],
cannam@127 164 p->comm, 0));
cannam@127 165 if (XM(any_true)(!cldt, p->comm)) goto nada;
cannam@127 166
cannam@127 167 {
cannam@127 168 INT is = p->sz->dims[0].n * nrest;
cannam@127 169 INT b = XM(block)(p->sz->dims[1].n, p->sz->dims[1].b[OB], my_pe);
cannam@127 170 cld2 = X(mkplan_d)(plnr,
cannam@127 171 X(mkproblem_rdft_1_d)(X(mktensor_1d)(
cannam@127 172 p->sz->dims[0].n,
cannam@127 173 nrest, nrest),
cannam@127 174 X(mktensor_2d)(b, is, is,
cannam@127 175 nrest, 1, 1),
cannam@127 176 O, O, p->kind[0]));
cannam@127 177 if (XM(any_true)(!cld2, p->comm)) goto nada;
cannam@127 178 }
cannam@127 179
cannam@127 180 pln = MKPLAN_MPI_RDFT(P, &padt, apply);
cannam@127 181 pln->cld1 = cld1;
cannam@127 182 pln->cldt = cldt;
cannam@127 183 pln->cld2 = cld2;
cannam@127 184 pln->preserve_input = ego->preserve_input ? 2 : NO_DESTROY_INPUTP(plnr);
cannam@127 185
cannam@127 186 X(ops_add)(&cld1->ops, &cld2->ops, &pln->super.super.ops);
cannam@127 187 X(ops_add2)(&cldt->ops, &pln->super.super.ops);
cannam@127 188
cannam@127 189 return &(pln->super.super);
cannam@127 190
cannam@127 191 nada:
cannam@127 192 X(plan_destroy_internal)(cld2);
cannam@127 193 X(plan_destroy_internal)(cldt);
cannam@127 194 X(plan_destroy_internal)(cld1);
cannam@127 195 return (plan *) 0;
cannam@127 196 }
cannam@127 197
cannam@127 198 static solver *mksolver(int preserve_input)
cannam@127 199 {
cannam@127 200 static const solver_adt sadt = { PROBLEM_MPI_RDFT, mkplan, 0 };
cannam@127 201 S *slv = MKSOLVER(S, &sadt);
cannam@127 202 slv->preserve_input = preserve_input;
cannam@127 203 return &(slv->super);
cannam@127 204 }
cannam@127 205
cannam@127 206 void XM(rdft_rank_geq2_transposed_register)(planner *p)
cannam@127 207 {
cannam@127 208 int preserve_input;
cannam@127 209 for (preserve_input = 0; preserve_input <= 1; ++preserve_input)
cannam@127 210 REGISTER_SOLVER(p, mksolver(preserve_input));
cannam@127 211 }