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