comparison src/fftw-3.3.3/mpi/rdft2-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" DFTs where all of the data is on one processor...just
22 call through to serial API. */
23
24 #include "mpi-rdft2.h"
25 #include "rdft.h"
26
27 typedef struct {
28 plan_mpi_rdft2 super;
29 plan *cld;
30 INT vn;
31 } P;
32
33 static void apply_r2c(const plan *ego_, R *I, R *O)
34 {
35 const P *ego = (const P *) ego_;
36 plan_rdft2 *cld;
37 cld = (plan_rdft2 *) ego->cld;
38 cld->apply(ego->cld, I, I+ego->vn, O, O+1);
39 }
40
41 static void apply_c2r(const plan *ego_, R *I, R *O)
42 {
43 const P *ego = (const P *) ego_;
44 plan_rdft2 *cld;
45 cld = (plan_rdft2 *) ego->cld;
46 cld->apply(ego->cld, O, O+ego->vn, I, I+1);
47 }
48
49 static void awake(plan *ego_, enum wakefulness wakefulness)
50 {
51 P *ego = (P *) ego_;
52 X(plan_awake)(ego->cld, wakefulness);
53 }
54
55 static void destroy(plan *ego_)
56 {
57 P *ego = (P *) ego_;
58 X(plan_destroy_internal)(ego->cld);
59 }
60
61 static void print(const plan *ego_, printer *p)
62 {
63 const P *ego = (const P *) ego_;
64 p->print(p, "(mpi-rdft2-serial %(%p%))", ego->cld);
65 }
66
67 int XM(rdft2_serial_applicable)(const problem_mpi_rdft2 *p)
68 {
69 return (1
70 && p->flags == 0 /* TRANSPOSED/SCRAMBLED_IN/OUT not supported */
71 && ((XM(is_local)(p->sz, IB) && XM(is_local)(p->sz, OB))
72 || p->vn == 0));
73 }
74
75 static plan *mkplan(const solver *ego, const problem *p_, planner *plnr)
76 {
77 const problem_mpi_rdft2 *p = (const problem_mpi_rdft2 *) p_;
78 P *pln;
79 plan *cld;
80 int my_pe;
81 R *r0, *r1, *cr, *ci;
82 static const plan_adt padt = {
83 XM(rdft2_solve), awake, print, destroy
84 };
85
86 UNUSED(ego);
87
88 /* check whether applicable: */
89 if (!XM(rdft2_serial_applicable)(p))
90 return (plan *) 0;
91
92 if (p->kind == R2HC) {
93 r1 = (r0 = p->I) + p->vn;
94 ci = (cr = p->O) + 1;
95 }
96 else {
97 r1 = (r0 = p->O) + p->vn;
98 ci = (cr = p->I) + 1;
99 }
100
101 MPI_Comm_rank(p->comm, &my_pe);
102 if (my_pe == 0 && p->vn > 0) {
103 INT ivs = 1 + (p->kind == HC2R), ovs = 1 + (p->kind == R2HC);
104 int i, rnk = p->sz->rnk;
105 tensor *sz = X(mktensor)(p->sz->rnk);
106 sz->dims[rnk - 1].is = sz->dims[rnk - 1].os = 2 * p->vn;
107 sz->dims[rnk - 1].n = p->sz->dims[rnk - 1].n / 2 + 1;
108 for (i = rnk - 1; i > 0; --i) {
109 sz->dims[i - 1].is = sz->dims[i - 1].os =
110 sz->dims[i].is * sz->dims[i].n;
111 sz->dims[i - 1].n = p->sz->dims[i - 1].n;
112 }
113 sz->dims[rnk - 1].n = p->sz->dims[rnk - 1].n;
114
115 cld = X(mkplan_d)(plnr,
116 X(mkproblem_rdft2_d)(sz,
117 X(mktensor_1d)(p->vn,ivs,ovs),
118 r0, r1, cr, ci, p->kind));
119 }
120 else { /* idle process: make nop plan */
121 cld = X(mkplan_d)(plnr,
122 X(mkproblem_rdft2_d)(X(mktensor_0d)(),
123 X(mktensor_1d)(0,0,0),
124 cr, ci, cr, ci, HC2R));
125 }
126 if (XM(any_true)(!cld, p->comm)) return (plan *) 0;
127
128 pln = MKPLAN_MPI_RDFT2(P, &padt, p->kind == R2HC ? apply_r2c : apply_c2r);
129 pln->cld = cld;
130 pln->vn = p->vn;
131 X(ops_cpy)(&cld->ops, &pln->super.super.ops);
132 return &(pln->super.super);
133 }
134
135 static solver *mksolver(void)
136 {
137 static const solver_adt sadt = { PROBLEM_MPI_RDFT2, mkplan, 0 };
138 return MKSOLVER(solver, &sadt);
139 }
140
141 void XM(rdft2_serial_register)(planner *p)
142 {
143 REGISTER_SOLVER(p, mksolver());
144 }