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