annotate fft/fftw/fftw-3.3.4/mpi/rdft-rank1-bigvec.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 /* Complex RDFTs of rank == 1 when the vector length vn is >= # processes.
Chris@19 22 In this case, we don't need to use a six-step type algorithm, and can
Chris@19 23 instead transpose the RDFT dimension with the vector dimension to
Chris@19 24 make the RDFT local. */
Chris@19 25
Chris@19 26 #include "mpi-rdft.h"
Chris@19 27 #include "mpi-transpose.h"
Chris@19 28
Chris@19 29 typedef struct {
Chris@19 30 solver super;
Chris@19 31 int preserve_input; /* preserve input even if DESTROY_INPUT was passed */
Chris@19 32 rearrangement rearrange;
Chris@19 33 } S;
Chris@19 34
Chris@19 35 typedef struct {
Chris@19 36 plan_mpi_rdft super;
Chris@19 37
Chris@19 38 plan *cldt_before, *cld, *cldt_after;
Chris@19 39 int preserve_input;
Chris@19 40 rearrangement rearrange;
Chris@19 41 } P;
Chris@19 42
Chris@19 43 static void apply(const plan *ego_, R *I, R *O)
Chris@19 44 {
Chris@19 45 const P *ego = (const P *) ego_;
Chris@19 46 plan_rdft *cld, *cldt_before, *cldt_after;
Chris@19 47
Chris@19 48 /* global transpose */
Chris@19 49 cldt_before = (plan_rdft *) ego->cldt_before;
Chris@19 50 cldt_before->apply(ego->cldt_before, I, O);
Chris@19 51
Chris@19 52 if (ego->preserve_input) I = O;
Chris@19 53
Chris@19 54 /* 1d RDFT(s) */
Chris@19 55 cld = (plan_rdft *) ego->cld;
Chris@19 56 cld->apply(ego->cld, O, I);
Chris@19 57
Chris@19 58 /* global transpose */
Chris@19 59 cldt_after = (plan_rdft *) ego->cldt_after;
Chris@19 60 cldt_after->apply(ego->cldt_after, I, O);
Chris@19 61 }
Chris@19 62
Chris@19 63 static int applicable(const S *ego, const problem *p_,
Chris@19 64 const planner *plnr)
Chris@19 65 {
Chris@19 66 const problem_mpi_rdft *p = (const problem_mpi_rdft *) p_;
Chris@19 67 int n_pes;
Chris@19 68 MPI_Comm_size(p->comm, &n_pes);
Chris@19 69 return (1
Chris@19 70 && p->sz->rnk == 1
Chris@19 71 && !(p->flags & ~RANK1_BIGVEC_ONLY)
Chris@19 72 && (!ego->preserve_input || (!NO_DESTROY_INPUTP(plnr)
Chris@19 73 && p->I != p->O))
Chris@19 74
Chris@19 75 #if 0 /* don't need this check since no other rank-1 rdft solver */
Chris@19 76 && (p->vn >= n_pes /* TODO: relax this, using more memory? */
Chris@19 77 || (p->flags & RANK1_BIGVEC_ONLY))
Chris@19 78 #endif
Chris@19 79
Chris@19 80 && XM(rearrange_applicable)(ego->rearrange,
Chris@19 81 p->sz->dims[0], p->vn, n_pes)
Chris@19 82
Chris@19 83 && (!NO_SLOWP(plnr) /* slow if rdft-serial is applicable */
Chris@19 84 || !XM(rdft_serial_applicable)(p))
Chris@19 85 );
Chris@19 86 }
Chris@19 87
Chris@19 88 static void awake(plan *ego_, enum wakefulness wakefulness)
Chris@19 89 {
Chris@19 90 P *ego = (P *) ego_;
Chris@19 91 X(plan_awake)(ego->cldt_before, wakefulness);
Chris@19 92 X(plan_awake)(ego->cld, wakefulness);
Chris@19 93 X(plan_awake)(ego->cldt_after, wakefulness);
Chris@19 94 }
Chris@19 95
Chris@19 96 static void destroy(plan *ego_)
Chris@19 97 {
Chris@19 98 P *ego = (P *) ego_;
Chris@19 99 X(plan_destroy_internal)(ego->cldt_after);
Chris@19 100 X(plan_destroy_internal)(ego->cld);
Chris@19 101 X(plan_destroy_internal)(ego->cldt_before);
Chris@19 102 }
Chris@19 103
Chris@19 104 static void print(const plan *ego_, printer *p)
Chris@19 105 {
Chris@19 106 const P *ego = (const P *) ego_;
Chris@19 107 const char descrip[][16] = { "contig", "discontig", "square-after",
Chris@19 108 "square-middle", "square-before" };
Chris@19 109 p->print(p, "(mpi-rdft-rank1-bigvec/%s%s %(%p%) %(%p%) %(%p%))",
Chris@19 110 descrip[ego->rearrange], ego->preserve_input==2 ?"/p":"",
Chris@19 111 ego->cldt_before, ego->cld, ego->cldt_after);
Chris@19 112 }
Chris@19 113
Chris@19 114 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
Chris@19 115 {
Chris@19 116 const S *ego = (const S *) ego_;
Chris@19 117 const problem_mpi_rdft *p;
Chris@19 118 P *pln;
Chris@19 119 plan *cld = 0, *cldt_before = 0, *cldt_after = 0;
Chris@19 120 R *I, *O;
Chris@19 121 INT yblock, yb, nx, ny, vn;
Chris@19 122 int my_pe, n_pes;
Chris@19 123 static const plan_adt padt = {
Chris@19 124 XM(rdft_solve), awake, print, destroy
Chris@19 125 };
Chris@19 126
Chris@19 127 UNUSED(ego);
Chris@19 128
Chris@19 129 if (!applicable(ego, p_, plnr))
Chris@19 130 return (plan *) 0;
Chris@19 131
Chris@19 132 p = (const problem_mpi_rdft *) p_;
Chris@19 133
Chris@19 134 MPI_Comm_rank(p->comm, &my_pe);
Chris@19 135 MPI_Comm_size(p->comm, &n_pes);
Chris@19 136
Chris@19 137 nx = p->sz->dims[0].n;
Chris@19 138 if (!(ny = XM(rearrange_ny)(ego->rearrange, p->sz->dims[0],p->vn,n_pes)))
Chris@19 139 return (plan *) 0;
Chris@19 140 vn = p->vn / ny;
Chris@19 141 A(ny * vn == p->vn);
Chris@19 142
Chris@19 143 yblock = XM(default_block)(ny, n_pes);
Chris@19 144 cldt_before = X(mkplan_d)(plnr,
Chris@19 145 XM(mkproblem_transpose)(
Chris@19 146 nx, ny, vn,
Chris@19 147 I = p->I, O = p->O,
Chris@19 148 p->sz->dims[0].b[IB], yblock,
Chris@19 149 p->comm, 0));
Chris@19 150 if (XM(any_true)(!cldt_before, p->comm)) goto nada;
Chris@19 151 if (ego->preserve_input || NO_DESTROY_INPUTP(plnr)) { I = O; }
Chris@19 152
Chris@19 153 yb = XM(block)(ny, yblock, my_pe);
Chris@19 154 cld = X(mkplan_d)(plnr,
Chris@19 155 X(mkproblem_rdft_1_d)(X(mktensor_1d)(nx, vn, vn),
Chris@19 156 X(mktensor_2d)(yb, vn*nx, vn*nx,
Chris@19 157 vn, 1, 1),
Chris@19 158 O, I, p->kind[0]));
Chris@19 159 if (XM(any_true)(!cld, p->comm)) goto nada;
Chris@19 160
Chris@19 161 cldt_after = X(mkplan_d)(plnr,
Chris@19 162 XM(mkproblem_transpose)(
Chris@19 163 ny, nx, vn,
Chris@19 164 I, O,
Chris@19 165 yblock, p->sz->dims[0].b[OB],
Chris@19 166 p->comm, 0));
Chris@19 167 if (XM(any_true)(!cldt_after, p->comm)) goto nada;
Chris@19 168
Chris@19 169 pln = MKPLAN_MPI_RDFT(P, &padt, apply);
Chris@19 170
Chris@19 171 pln->cldt_before = cldt_before;
Chris@19 172 pln->cld = cld;
Chris@19 173 pln->cldt_after = cldt_after;
Chris@19 174 pln->preserve_input = ego->preserve_input ? 2 : NO_DESTROY_INPUTP(plnr);
Chris@19 175 pln->rearrange = ego->rearrange;
Chris@19 176
Chris@19 177 X(ops_add)(&cldt_before->ops, &cld->ops, &pln->super.super.ops);
Chris@19 178 X(ops_add2)(&cldt_after->ops, &pln->super.super.ops);
Chris@19 179
Chris@19 180 return &(pln->super.super);
Chris@19 181
Chris@19 182 nada:
Chris@19 183 X(plan_destroy_internal)(cldt_after);
Chris@19 184 X(plan_destroy_internal)(cld);
Chris@19 185 X(plan_destroy_internal)(cldt_before);
Chris@19 186 return (plan *) 0;
Chris@19 187 }
Chris@19 188
Chris@19 189 static solver *mksolver(rearrangement rearrange, int preserve_input)
Chris@19 190 {
Chris@19 191 static const solver_adt sadt = { PROBLEM_MPI_RDFT, mkplan, 0 };
Chris@19 192 S *slv = MKSOLVER(S, &sadt);
Chris@19 193 slv->rearrange = rearrange;
Chris@19 194 slv->preserve_input = preserve_input;
Chris@19 195 return &(slv->super);
Chris@19 196 }
Chris@19 197
Chris@19 198 void XM(rdft_rank1_bigvec_register)(planner *p)
Chris@19 199 {
Chris@19 200 rearrangement rearrange;
Chris@19 201 int preserve_input;
Chris@19 202 FORALL_REARRANGE(rearrange)
Chris@19 203 for (preserve_input = 0; preserve_input <= 1; ++preserve_input)
Chris@19 204 REGISTER_SOLVER(p, mksolver(rearrange, preserve_input));
Chris@19 205 }