cannam@95: /* cannam@95: * Copyright (c) 2003, 2007-11 Matteo Frigo cannam@95: * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology cannam@95: * cannam@95: * This program is free software; you can redistribute it and/or modify cannam@95: * it under the terms of the GNU General Public License as published by cannam@95: * the Free Software Foundation; either version 2 of the License, or cannam@95: * (at your option) any later version. cannam@95: * cannam@95: * This program is distributed in the hope that it will be useful, cannam@95: * but WITHOUT ANY WARRANTY; without even the implied warranty of cannam@95: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the cannam@95: * GNU General Public License for more details. cannam@95: * cannam@95: * You should have received a copy of the GNU General Public License cannam@95: * along with this program; if not, write to the Free Software cannam@95: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA cannam@95: * cannam@95: */ cannam@95: cannam@95: /* "MPI" RDFTs where all of the data is on one processor...just cannam@95: call through to serial API. */ cannam@95: cannam@95: #include "mpi-rdft.h" cannam@95: cannam@95: typedef struct { cannam@95: plan_mpi_rdft super; cannam@95: plan *cld; cannam@95: } P; cannam@95: cannam@95: static void apply(const plan *ego_, R *I, R *O) cannam@95: { cannam@95: const P *ego = (const P *) ego_; cannam@95: plan_rdft *cld = (plan_rdft *) ego->cld; cannam@95: cld->apply(ego->cld, I, O); cannam@95: } cannam@95: cannam@95: static void awake(plan *ego_, enum wakefulness wakefulness) cannam@95: { cannam@95: P *ego = (P *) ego_; cannam@95: X(plan_awake)(ego->cld, wakefulness); cannam@95: } cannam@95: cannam@95: static void destroy(plan *ego_) cannam@95: { cannam@95: P *ego = (P *) ego_; cannam@95: X(plan_destroy_internal)(ego->cld); cannam@95: } cannam@95: cannam@95: static void print(const plan *ego_, printer *p) cannam@95: { cannam@95: const P *ego = (const P *) ego_; cannam@95: p->print(p, "(mpi-rdft-serial %(%p%))", ego->cld); cannam@95: } cannam@95: cannam@95: int XM(rdft_serial_applicable)(const problem_mpi_rdft *p) cannam@95: { cannam@95: return (1 cannam@95: && p->flags == 0 /* TRANSPOSED/SCRAMBLED_IN/OUT not supported */ cannam@95: && ((XM(is_local)(p->sz, IB) && XM(is_local)(p->sz, OB)) cannam@95: || p->vn == 0)); cannam@95: } cannam@95: cannam@95: static plan *mkplan(const solver *ego, const problem *p_, planner *plnr) cannam@95: { cannam@95: const problem_mpi_rdft *p = (const problem_mpi_rdft *) p_; cannam@95: P *pln; cannam@95: plan *cld; cannam@95: int my_pe; cannam@95: static const plan_adt padt = { cannam@95: XM(rdft_solve), awake, print, destroy cannam@95: }; cannam@95: cannam@95: UNUSED(ego); cannam@95: cannam@95: /* check whether applicable: */ cannam@95: if (!XM(rdft_serial_applicable)(p)) cannam@95: return (plan *) 0; cannam@95: cannam@95: MPI_Comm_rank(p->comm, &my_pe); cannam@95: if (my_pe == 0 && p->vn > 0) { cannam@95: int i, rnk = p->sz->rnk; cannam@95: tensor *sz = X(mktensor)(rnk); cannam@95: rdft_kind *kind cannam@95: = (rdft_kind *) MALLOC(sizeof(rdft_kind) * rnk, PROBLEMS); cannam@95: sz->dims[rnk - 1].is = sz->dims[rnk - 1].os = p->vn; cannam@95: sz->dims[rnk - 1].n = p->sz->dims[rnk - 1].n; cannam@95: for (i = rnk - 1; i > 0; --i) { cannam@95: sz->dims[i - 1].is = sz->dims[i - 1].os = cannam@95: sz->dims[i].is * sz->dims[i].n; cannam@95: sz->dims[i - 1].n = p->sz->dims[i - 1].n; cannam@95: } cannam@95: for (i = 0; i < rnk; ++i) cannam@95: kind[i] = p->kind[i]; cannam@95: cannam@95: cld = X(mkplan_d)(plnr, cannam@95: X(mkproblem_rdft_d)(sz, cannam@95: X(mktensor_1d)(p->vn, 1, 1), cannam@95: p->I, p->O, kind)); cannam@95: X(ifree0)(kind); cannam@95: } cannam@95: else { /* idle process: make nop plan */ cannam@95: cld = X(mkplan_d)(plnr, cannam@95: X(mkproblem_rdft_0_d)(X(mktensor_1d)(0,0,0), cannam@95: p->I, p->O)); cannam@95: } cannam@95: if (XM(any_true)(!cld, p->comm)) return (plan *) 0; cannam@95: cannam@95: pln = MKPLAN_MPI_RDFT(P, &padt, apply); cannam@95: pln->cld = cld; cannam@95: X(ops_cpy)(&cld->ops, &pln->super.super.ops); cannam@95: return &(pln->super.super); cannam@95: } cannam@95: cannam@95: static solver *mksolver(void) cannam@95: { cannam@95: static const solver_adt sadt = { PROBLEM_MPI_RDFT, mkplan, 0 }; cannam@95: return MKSOLVER(solver, &sadt); cannam@95: } cannam@95: cannam@95: void XM(rdft_serial_register)(planner *p) cannam@95: { cannam@95: REGISTER_SOLVER(p, mksolver()); cannam@95: }