comparison src/fftw-3.3.3/mpi/dft-rank-geq2.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 /* Complex DFTs of rank >= 2, for the case where we are distributed
22 across the first dimension only, and the output is not transposed. */
23
24 #include "mpi-dft.h"
25 #include "dft.h"
26
27 typedef struct {
28 solver super;
29 int preserve_input; /* preserve input even if DESTROY_INPUT was passed */
30 } S;
31
32 typedef struct {
33 plan_mpi_dft super;
34
35 plan *cld1, *cld2;
36 INT roff, ioff;
37 int preserve_input;
38 } P;
39
40 static void apply(const plan *ego_, R *I, R *O)
41 {
42 const P *ego = (const P *) ego_;
43 plan_dft *cld1;
44 plan_rdft *cld2;
45 INT roff = ego->roff, ioff = ego->ioff;
46
47 /* DFT local dimensions */
48 cld1 = (plan_dft *) ego->cld1;
49 if (ego->preserve_input) {
50 cld1->apply(ego->cld1, I+roff, I+ioff, O+roff, O+ioff);
51 I = O;
52 }
53 else
54 cld1->apply(ego->cld1, I+roff, I+ioff, I+roff, I+ioff);
55
56 /* DFT non-local dimension (via dft-rank1-bigvec, usually): */
57 cld2 = (plan_rdft *) ego->cld2;
58 cld2->apply(ego->cld2, I, O);
59 }
60
61 static int applicable(const S *ego, const problem *p_,
62 const planner *plnr)
63 {
64 const problem_mpi_dft *p = (const problem_mpi_dft *) p_;
65 return (1
66 && p->sz->rnk > 1
67 && p->flags == 0 /* TRANSPOSED/SCRAMBLED_IN/OUT not supported */
68 && (!ego->preserve_input || (!NO_DESTROY_INPUTP(plnr)
69 && p->I != p->O))
70 && XM(is_local_after)(1, p->sz, IB)
71 && XM(is_local_after)(1, p->sz, OB)
72 && (!NO_SLOWP(plnr) /* slow if dft-serial is applicable */
73 || !XM(dft_serial_applicable)(p))
74 );
75 }
76
77 static void awake(plan *ego_, enum wakefulness wakefulness)
78 {
79 P *ego = (P *) ego_;
80 X(plan_awake)(ego->cld1, wakefulness);
81 X(plan_awake)(ego->cld2, wakefulness);
82 }
83
84 static void destroy(plan *ego_)
85 {
86 P *ego = (P *) ego_;
87 X(plan_destroy_internal)(ego->cld2);
88 X(plan_destroy_internal)(ego->cld1);
89 }
90
91 static void print(const plan *ego_, printer *p)
92 {
93 const P *ego = (const P *) ego_;
94 p->print(p, "(mpi-dft-rank-geq2%s%(%p%)%(%p%))",
95 ego->preserve_input==2 ?"/p":"", ego->cld1, ego->cld2);
96 }
97
98 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
99 {
100 const S *ego = (const S *) ego_;
101 const problem_mpi_dft *p;
102 P *pln;
103 plan *cld1 = 0, *cld2 = 0;
104 R *ri, *ii, *ro, *io, *I, *O;
105 tensor *sz;
106 dtensor *sz2;
107 int i, my_pe, n_pes;
108 INT nrest;
109 static const plan_adt padt = {
110 XM(dft_solve), awake, print, destroy
111 };
112
113 UNUSED(ego);
114
115 if (!applicable(ego, p_, plnr))
116 return (plan *) 0;
117
118 p = (const problem_mpi_dft *) p_;
119
120 X(extract_reim)(p->sign, I = p->I, &ri, &ii);
121 X(extract_reim)(p->sign, O = p->O, &ro, &io);
122 if (ego->preserve_input || NO_DESTROY_INPUTP(plnr))
123 I = O;
124 else {
125 ro = ri;
126 io = ii;
127 }
128 MPI_Comm_rank(p->comm, &my_pe);
129 MPI_Comm_size(p->comm, &n_pes);
130
131 sz = X(mktensor)(p->sz->rnk - 1); /* tensor of last rnk-1 dimensions */
132 i = p->sz->rnk - 2; A(i >= 0);
133 sz->dims[i].n = p->sz->dims[i+1].n;
134 sz->dims[i].is = sz->dims[i].os = 2 * p->vn;
135 for (--i; i >= 0; --i) {
136 sz->dims[i].n = p->sz->dims[i+1].n;
137 sz->dims[i].is = sz->dims[i].os = sz->dims[i+1].n * sz->dims[i+1].is;
138 }
139 nrest = X(tensor_sz)(sz);
140 {
141 INT is = sz->dims[0].n * sz->dims[0].is;
142 INT b = XM(block)(p->sz->dims[0].n, p->sz->dims[0].b[IB], my_pe);
143 cld1 = X(mkplan_d)(plnr,
144 X(mkproblem_dft_d)(sz,
145 X(mktensor_2d)(b, is, is,
146 p->vn, 2, 2),
147 ri, ii, ro, io));
148 if (XM(any_true)(!cld1, p->comm)) goto nada;
149 }
150
151 sz2 = XM(mkdtensor)(1); /* tensor for first (distributed) dimension */
152 sz2->dims[0] = p->sz->dims[0];
153 cld2 = X(mkplan_d)(plnr, XM(mkproblem_dft_d)(sz2, nrest * p->vn,
154 I, O, p->comm, p->sign,
155 RANK1_BIGVEC_ONLY));
156 if (XM(any_true)(!cld2, p->comm)) goto nada;
157
158 pln = MKPLAN_MPI_DFT(P, &padt, apply);
159 pln->cld1 = cld1;
160 pln->cld2 = cld2;
161 pln->preserve_input = ego->preserve_input ? 2 : NO_DESTROY_INPUTP(plnr);
162 pln->roff = ri - p->I;
163 pln->ioff = ii - p->I;
164
165 X(ops_add)(&cld1->ops, &cld2->ops, &pln->super.super.ops);
166
167 return &(pln->super.super);
168
169 nada:
170 X(plan_destroy_internal)(cld2);
171 X(plan_destroy_internal)(cld1);
172 return (plan *) 0;
173 }
174
175 static solver *mksolver(int preserve_input)
176 {
177 static const solver_adt sadt = { PROBLEM_MPI_DFT, mkplan, 0 };
178 S *slv = MKSOLVER(S, &sadt);
179 slv->preserve_input = preserve_input;
180 return &(slv->super);
181 }
182
183 void XM(dft_rank_geq2_register)(planner *p)
184 {
185 int preserve_input;
186 for (preserve_input = 0; preserve_input <= 1; ++preserve_input)
187 REGISTER_SOLVER(p, mksolver(preserve_input));
188 }