comparison src/fftw-3.3.3/mpi/rdft-serial.c @ 10:37bf6b4a2645

Add FFTW3
author Chris Cannam
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
comparison
equal deleted inserted replaced
9:c0fb53affa76 10:37bf6b4a2645
1 /*
2 * Copyright (c) 2003, 2007-11 Matteo Frigo
3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21 /* "MPI" RDFTs where all of the data is on one processor...just
22 call through to serial API. */
23
24 #include "mpi-rdft.h"
25
26 typedef struct {
27 plan_mpi_rdft super;
28 plan *cld;
29 } P;
30
31 static void apply(const plan *ego_, R *I, R *O)
32 {
33 const P *ego = (const P *) ego_;
34 plan_rdft *cld = (plan_rdft *) ego->cld;
35 cld->apply(ego->cld, I, O);
36 }
37
38 static void awake(plan *ego_, enum wakefulness wakefulness)
39 {
40 P *ego = (P *) ego_;
41 X(plan_awake)(ego->cld, wakefulness);
42 }
43
44 static void destroy(plan *ego_)
45 {
46 P *ego = (P *) ego_;
47 X(plan_destroy_internal)(ego->cld);
48 }
49
50 static void print(const plan *ego_, printer *p)
51 {
52 const P *ego = (const P *) ego_;
53 p->print(p, "(mpi-rdft-serial %(%p%))", ego->cld);
54 }
55
56 int XM(rdft_serial_applicable)(const problem_mpi_rdft *p)
57 {
58 return (1
59 && p->flags == 0 /* TRANSPOSED/SCRAMBLED_IN/OUT not supported */
60 && ((XM(is_local)(p->sz, IB) && XM(is_local)(p->sz, OB))
61 || p->vn == 0));
62 }
63
64 static plan *mkplan(const solver *ego, const problem *p_, planner *plnr)
65 {
66 const problem_mpi_rdft *p = (const problem_mpi_rdft *) p_;
67 P *pln;
68 plan *cld;
69 int my_pe;
70 static const plan_adt padt = {
71 XM(rdft_solve), awake, print, destroy
72 };
73
74 UNUSED(ego);
75
76 /* check whether applicable: */
77 if (!XM(rdft_serial_applicable)(p))
78 return (plan *) 0;
79
80 MPI_Comm_rank(p->comm, &my_pe);
81 if (my_pe == 0 && p->vn > 0) {
82 int i, rnk = p->sz->rnk;
83 tensor *sz = X(mktensor)(rnk);
84 rdft_kind *kind
85 = (rdft_kind *) MALLOC(sizeof(rdft_kind) * rnk, PROBLEMS);
86 sz->dims[rnk - 1].is = sz->dims[rnk - 1].os = p->vn;
87 sz->dims[rnk - 1].n = p->sz->dims[rnk - 1].n;
88 for (i = rnk - 1; i > 0; --i) {
89 sz->dims[i - 1].is = sz->dims[i - 1].os =
90 sz->dims[i].is * sz->dims[i].n;
91 sz->dims[i - 1].n = p->sz->dims[i - 1].n;
92 }
93 for (i = 0; i < rnk; ++i)
94 kind[i] = p->kind[i];
95
96 cld = X(mkplan_d)(plnr,
97 X(mkproblem_rdft_d)(sz,
98 X(mktensor_1d)(p->vn, 1, 1),
99 p->I, p->O, kind));
100 X(ifree0)(kind);
101 }
102 else { /* idle process: make nop plan */
103 cld = X(mkplan_d)(plnr,
104 X(mkproblem_rdft_0_d)(X(mktensor_1d)(0,0,0),
105 p->I, p->O));
106 }
107 if (XM(any_true)(!cld, p->comm)) return (plan *) 0;
108
109 pln = MKPLAN_MPI_RDFT(P, &padt, apply);
110 pln->cld = cld;
111 X(ops_cpy)(&cld->ops, &pln->super.super.ops);
112 return &(pln->super.super);
113 }
114
115 static solver *mksolver(void)
116 {
117 static const solver_adt sadt = { PROBLEM_MPI_RDFT, mkplan, 0 };
118 return MKSOLVER(solver, &sadt);
119 }
120
121 void XM(rdft_serial_register)(planner *p)
122 {
123 REGISTER_SOLVER(p, mksolver());
124 }