Chris@10: /* Chris@10: * Copyright (c) 2003, 2007-11 Matteo Frigo Chris@10: * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology Chris@10: * Chris@10: * This program is free software; you can redistribute it and/or modify Chris@10: * it under the terms of the GNU General Public License as published by Chris@10: * the Free Software Foundation; either version 2 of the License, or Chris@10: * (at your option) any later version. Chris@10: * Chris@10: * This program is distributed in the hope that it will be useful, Chris@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@10: * GNU General Public License for more details. Chris@10: * Chris@10: * You should have received a copy of the GNU General Public License Chris@10: * along with this program; if not, write to the Free Software Chris@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Chris@10: * Chris@10: */ Chris@10: Chris@10: /* Complex DFTs of rank == 1 when the vector length vn is >= # processes. Chris@10: In this case, we don't need to use a six-step type algorithm, and can Chris@10: instead transpose the DFT dimension with the vector dimension to Chris@10: make the DFT local. */ Chris@10: Chris@10: #include "mpi-dft.h" Chris@10: #include "mpi-transpose.h" Chris@10: #include "dft.h" Chris@10: Chris@10: typedef struct { Chris@10: solver super; Chris@10: int preserve_input; /* preserve input even if DESTROY_INPUT was passed */ Chris@10: rearrangement rearrange; Chris@10: } S; Chris@10: Chris@10: typedef struct { Chris@10: plan_mpi_dft super; Chris@10: Chris@10: plan *cldt_before, *cld, *cldt_after; Chris@10: INT roff, ioff; Chris@10: int preserve_input; Chris@10: rearrangement rearrange; Chris@10: } P; Chris@10: Chris@10: static void apply(const plan *ego_, R *I, R *O) Chris@10: { Chris@10: const P *ego = (const P *) ego_; Chris@10: plan_dft *cld; Chris@10: plan_rdft *cldt_before, *cldt_after; Chris@10: INT roff = ego->roff, ioff = ego->ioff; Chris@10: Chris@10: /* global transpose */ Chris@10: cldt_before = (plan_rdft *) ego->cldt_before; Chris@10: cldt_before->apply(ego->cldt_before, I, O); Chris@10: Chris@10: if (ego->preserve_input) I = O; Chris@10: Chris@10: /* 1d DFT(s) */ Chris@10: cld = (plan_dft *) ego->cld; Chris@10: cld->apply(ego->cld, O+roff, O+ioff, I+roff, I+ioff); Chris@10: Chris@10: /* global transpose */ Chris@10: cldt_after = (plan_rdft *) ego->cldt_after; Chris@10: cldt_after->apply(ego->cldt_after, I, O); Chris@10: } Chris@10: Chris@10: static int applicable(const S *ego, const problem *p_, Chris@10: const planner *plnr) Chris@10: { Chris@10: const problem_mpi_dft *p = (const problem_mpi_dft *) p_; Chris@10: int n_pes; Chris@10: MPI_Comm_size(p->comm, &n_pes); Chris@10: return (1 Chris@10: && p->sz->rnk == 1 Chris@10: && !(p->flags & ~RANK1_BIGVEC_ONLY) Chris@10: && (!ego->preserve_input || (!NO_DESTROY_INPUTP(plnr) Chris@10: && p->I != p->O)) Chris@10: && (p->vn >= n_pes /* TODO: relax this, using more memory? */ Chris@10: || (p->flags & RANK1_BIGVEC_ONLY)) Chris@10: Chris@10: && XM(rearrange_applicable)(ego->rearrange, Chris@10: p->sz->dims[0], p->vn, n_pes) Chris@10: Chris@10: && (!NO_SLOWP(plnr) /* slow if dft-serial is applicable */ Chris@10: || !XM(dft_serial_applicable)(p)) Chris@10: ); Chris@10: } Chris@10: Chris@10: static void awake(plan *ego_, enum wakefulness wakefulness) Chris@10: { Chris@10: P *ego = (P *) ego_; Chris@10: X(plan_awake)(ego->cldt_before, wakefulness); Chris@10: X(plan_awake)(ego->cld, wakefulness); Chris@10: X(plan_awake)(ego->cldt_after, wakefulness); Chris@10: } Chris@10: Chris@10: static void destroy(plan *ego_) Chris@10: { Chris@10: P *ego = (P *) ego_; Chris@10: X(plan_destroy_internal)(ego->cldt_after); Chris@10: X(plan_destroy_internal)(ego->cld); Chris@10: X(plan_destroy_internal)(ego->cldt_before); Chris@10: } Chris@10: Chris@10: static void print(const plan *ego_, printer *p) Chris@10: { Chris@10: const P *ego = (const P *) ego_; Chris@10: const char descrip[][16] = { "contig", "discontig", "square-after", Chris@10: "square-middle", "square-before" }; Chris@10: p->print(p, "(mpi-dft-rank1-bigvec/%s%s %(%p%) %(%p%) %(%p%))", Chris@10: descrip[ego->rearrange], ego->preserve_input==2 ?"/p":"", Chris@10: ego->cldt_before, ego->cld, ego->cldt_after); Chris@10: } Chris@10: Chris@10: static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr) Chris@10: { Chris@10: const S *ego = (const S *) ego_; Chris@10: const problem_mpi_dft *p; Chris@10: P *pln; Chris@10: plan *cld = 0, *cldt_before = 0, *cldt_after = 0; Chris@10: R *ri, *ii, *ro, *io, *I, *O; Chris@10: INT yblock, yb, nx, ny, vn; Chris@10: int my_pe, n_pes; Chris@10: static const plan_adt padt = { Chris@10: XM(dft_solve), awake, print, destroy Chris@10: }; Chris@10: Chris@10: UNUSED(ego); Chris@10: Chris@10: if (!applicable(ego, p_, plnr)) Chris@10: return (plan *) 0; Chris@10: Chris@10: p = (const problem_mpi_dft *) p_; Chris@10: Chris@10: MPI_Comm_rank(p->comm, &my_pe); Chris@10: MPI_Comm_size(p->comm, &n_pes); Chris@10: Chris@10: nx = p->sz->dims[0].n; Chris@10: if (!(ny = XM(rearrange_ny)(ego->rearrange, p->sz->dims[0],p->vn,n_pes))) Chris@10: return (plan *) 0; Chris@10: vn = p->vn / ny; Chris@10: A(ny * vn == p->vn); Chris@10: Chris@10: yblock = XM(default_block)(ny, n_pes); Chris@10: cldt_before = X(mkplan_d)(plnr, Chris@10: XM(mkproblem_transpose)( Chris@10: nx, ny, vn*2, Chris@10: I = p->I, O = p->O, Chris@10: p->sz->dims[0].b[IB], yblock, Chris@10: p->comm, 0)); Chris@10: if (XM(any_true)(!cldt_before, p->comm)) goto nada; Chris@10: if (ego->preserve_input || NO_DESTROY_INPUTP(plnr)) { I = O; } Chris@10: Chris@10: X(extract_reim)(p->sign, I, &ri, &ii); Chris@10: X(extract_reim)(p->sign, O, &ro, &io); Chris@10: Chris@10: yb = XM(block)(ny, yblock, my_pe); Chris@10: cld = X(mkplan_d)(plnr, Chris@10: X(mkproblem_dft_d)(X(mktensor_1d)(nx, vn*2, vn*2), Chris@10: X(mktensor_2d)(yb, vn*2*nx, vn*2*nx, Chris@10: vn, 2, 2), Chris@10: ro, io, ri, ii)); Chris@10: if (XM(any_true)(!cld, p->comm)) goto nada; Chris@10: Chris@10: cldt_after = X(mkplan_d)(plnr, Chris@10: XM(mkproblem_transpose)( Chris@10: ny, nx, vn*2, Chris@10: I, O, Chris@10: yblock, p->sz->dims[0].b[OB], Chris@10: p->comm, 0)); Chris@10: if (XM(any_true)(!cldt_after, p->comm)) goto nada; Chris@10: Chris@10: pln = MKPLAN_MPI_DFT(P, &padt, apply); Chris@10: Chris@10: pln->cldt_before = cldt_before; Chris@10: pln->cld = cld; Chris@10: pln->cldt_after = cldt_after; Chris@10: pln->preserve_input = ego->preserve_input ? 2 : NO_DESTROY_INPUTP(plnr); Chris@10: pln->roff = ro - p->O; Chris@10: pln->ioff = io - p->O; Chris@10: pln->rearrange = ego->rearrange; Chris@10: Chris@10: X(ops_add)(&cldt_before->ops, &cld->ops, &pln->super.super.ops); Chris@10: X(ops_add2)(&cldt_after->ops, &pln->super.super.ops); Chris@10: Chris@10: return &(pln->super.super); Chris@10: Chris@10: nada: Chris@10: X(plan_destroy_internal)(cldt_after); Chris@10: X(plan_destroy_internal)(cld); Chris@10: X(plan_destroy_internal)(cldt_before); Chris@10: return (plan *) 0; Chris@10: } Chris@10: Chris@10: static solver *mksolver(rearrangement rearrange, int preserve_input) Chris@10: { Chris@10: static const solver_adt sadt = { PROBLEM_MPI_DFT, mkplan, 0 }; Chris@10: S *slv = MKSOLVER(S, &sadt); Chris@10: slv->rearrange = rearrange; Chris@10: slv->preserve_input = preserve_input; Chris@10: return &(slv->super); Chris@10: } Chris@10: Chris@10: void XM(dft_rank1_bigvec_register)(planner *p) Chris@10: { Chris@10: rearrangement rearrange; Chris@10: int preserve_input; Chris@10: FORALL_REARRANGE(rearrange) Chris@10: for (preserve_input = 0; preserve_input <= 1; ++preserve_input) Chris@10: REGISTER_SOLVER(p, mksolver(rearrange, preserve_input)); Chris@10: }