Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.3/mpi/rdft2-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 RDFT2s 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 "mpi-rdft2.h" | |
26 #include "rdft.h" | |
27 | |
28 typedef struct { | |
29 solver super; | |
30 int preserve_input; /* preserve input even if DESTROY_INPUT was passed */ | |
31 } S; | |
32 | |
33 typedef struct { | |
34 plan_mpi_rdft2 super; | |
35 | |
36 plan *cld1, *cld2; | |
37 INT vn; | |
38 int preserve_input; | |
39 } P; | |
40 | |
41 static void apply_r2c(const plan *ego_, R *I, R *O) | |
42 { | |
43 const P *ego = (const P *) ego_; | |
44 plan_rdft2 *cld1; | |
45 plan_rdft *cld2; | |
46 | |
47 /* RDFT2 local dimensions */ | |
48 cld1 = (plan_rdft2 *) ego->cld1; | |
49 if (ego->preserve_input) { | |
50 cld1->apply(ego->cld1, I, I+ego->vn, O, O+1); | |
51 I = O; | |
52 } | |
53 else | |
54 cld1->apply(ego->cld1, I, I+ego->vn, I, I+1); | |
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 void apply_c2r(const plan *ego_, R *I, R *O) | |
62 { | |
63 const P *ego = (const P *) ego_; | |
64 plan_rdft2 *cld1; | |
65 plan_rdft *cld2; | |
66 | |
67 /* DFT non-local dimension (via dft-rank1-bigvec, usually): */ | |
68 cld2 = (plan_rdft *) ego->cld2; | |
69 cld2->apply(ego->cld2, I, O); | |
70 | |
71 /* RDFT2 local dimensions */ | |
72 cld1 = (plan_rdft2 *) ego->cld1; | |
73 cld1->apply(ego->cld1, O, O+ego->vn, O, O+1); | |
74 | |
75 } | |
76 | |
77 static int applicable(const S *ego, const problem *p_, | |
78 const planner *plnr) | |
79 { | |
80 const problem_mpi_rdft2 *p = (const problem_mpi_rdft2 *) p_; | |
81 return (1 | |
82 && p->sz->rnk > 1 | |
83 && p->flags == 0 /* TRANSPOSED/SCRAMBLED_IN/OUT not supported */ | |
84 && (!ego->preserve_input || (!NO_DESTROY_INPUTP(plnr) | |
85 && p->I != p->O | |
86 && p->kind == R2HC)) | |
87 && XM(is_local_after)(1, p->sz, IB) | |
88 && XM(is_local_after)(1, p->sz, OB) | |
89 && (!NO_SLOWP(plnr) /* slow if rdft2-serial is applicable */ | |
90 || !XM(rdft2_serial_applicable)(p)) | |
91 ); | |
92 } | |
93 | |
94 static void awake(plan *ego_, enum wakefulness wakefulness) | |
95 { | |
96 P *ego = (P *) ego_; | |
97 X(plan_awake)(ego->cld1, wakefulness); | |
98 X(plan_awake)(ego->cld2, wakefulness); | |
99 } | |
100 | |
101 static void destroy(plan *ego_) | |
102 { | |
103 P *ego = (P *) ego_; | |
104 X(plan_destroy_internal)(ego->cld2); | |
105 X(plan_destroy_internal)(ego->cld1); | |
106 } | |
107 | |
108 static void print(const plan *ego_, printer *p) | |
109 { | |
110 const P *ego = (const P *) ego_; | |
111 p->print(p, "(mpi-rdft2-rank-geq2%s%(%p%)%(%p%))", | |
112 ego->preserve_input==2 ?"/p":"", ego->cld1, ego->cld2); | |
113 } | |
114 | |
115 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr) | |
116 { | |
117 const S *ego = (const S *) ego_; | |
118 const problem_mpi_rdft2 *p; | |
119 P *pln; | |
120 plan *cld1 = 0, *cld2 = 0; | |
121 R *r0, *r1, *cr, *ci, *I, *O; | |
122 tensor *sz; | |
123 dtensor *sz2; | |
124 int i, my_pe, n_pes; | |
125 INT nrest; | |
126 static const plan_adt padt = { | |
127 XM(rdft2_solve), awake, print, destroy | |
128 }; | |
129 | |
130 UNUSED(ego); | |
131 | |
132 if (!applicable(ego, p_, plnr)) | |
133 return (plan *) 0; | |
134 | |
135 p = (const problem_mpi_rdft2 *) p_; | |
136 | |
137 I = p->I; O = p->O; | |
138 if (p->kind == R2HC) { | |
139 r1 = (r0 = p->I) + p->vn; | |
140 if (ego->preserve_input || NO_DESTROY_INPUTP(plnr)) { | |
141 ci = (cr = p->O) + 1; | |
142 I = O; | |
143 } | |
144 else | |
145 ci = (cr = p->I) + 1; | |
146 } | |
147 else { | |
148 r1 = (r0 = p->O) + p->vn; | |
149 ci = (cr = p->O) + 1; | |
150 } | |
151 | |
152 MPI_Comm_rank(p->comm, &my_pe); | |
153 MPI_Comm_size(p->comm, &n_pes); | |
154 | |
155 sz = X(mktensor)(p->sz->rnk - 1); /* tensor of last rnk-1 dimensions */ | |
156 i = p->sz->rnk - 2; A(i >= 0); | |
157 sz->dims[i].is = sz->dims[i].os = 2 * p->vn; | |
158 sz->dims[i].n = p->sz->dims[i+1].n / 2 + 1; | |
159 for (--i; i >= 0; --i) { | |
160 sz->dims[i].n = p->sz->dims[i+1].n; | |
161 sz->dims[i].is = sz->dims[i].os = sz->dims[i+1].n * sz->dims[i+1].is; | |
162 } | |
163 nrest = X(tensor_sz)(sz); | |
164 { | |
165 INT ivs = 1 + (p->kind == HC2R), ovs = 1 + (p->kind == R2HC); | |
166 INT is = sz->dims[0].n * sz->dims[0].is; | |
167 INT b = XM(block)(p->sz->dims[0].n, p->sz->dims[0].b[IB], my_pe); | |
168 sz->dims[p->sz->rnk - 2].n = p->sz->dims[p->sz->rnk - 1].n; | |
169 cld1 = X(mkplan_d)(plnr, | |
170 X(mkproblem_rdft2_d)(sz, | |
171 X(mktensor_2d)(b, is, is, | |
172 p->vn,ivs,ovs), | |
173 r0, r1, cr, ci, p->kind)); | |
174 if (XM(any_true)(!cld1, p->comm)) goto nada; | |
175 } | |
176 | |
177 sz2 = XM(mkdtensor)(1); /* tensor for first (distributed) dimension */ | |
178 sz2->dims[0] = p->sz->dims[0]; | |
179 cld2 = X(mkplan_d)(plnr, XM(mkproblem_dft_d)(sz2, nrest * p->vn, | |
180 I, O, p->comm, | |
181 p->kind == R2HC ? | |
182 FFT_SIGN : -FFT_SIGN, | |
183 RANK1_BIGVEC_ONLY)); | |
184 if (XM(any_true)(!cld2, p->comm)) goto nada; | |
185 | |
186 pln = MKPLAN_MPI_RDFT2(P, &padt, p->kind == R2HC ? apply_r2c : apply_c2r); | |
187 pln->cld1 = cld1; | |
188 pln->cld2 = cld2; | |
189 pln->preserve_input = ego->preserve_input ? 2 : NO_DESTROY_INPUTP(plnr); | |
190 pln->vn = p->vn; | |
191 | |
192 X(ops_add)(&cld1->ops, &cld2->ops, &pln->super.super.ops); | |
193 | |
194 return &(pln->super.super); | |
195 | |
196 nada: | |
197 X(plan_destroy_internal)(cld2); | |
198 X(plan_destroy_internal)(cld1); | |
199 return (plan *) 0; | |
200 } | |
201 | |
202 static solver *mksolver(int preserve_input) | |
203 { | |
204 static const solver_adt sadt = { PROBLEM_MPI_RDFT2, mkplan, 0 }; | |
205 S *slv = MKSOLVER(S, &sadt); | |
206 slv->preserve_input = preserve_input; | |
207 return &(slv->super); | |
208 } | |
209 | |
210 void XM(rdft2_rank_geq2_register)(planner *p) | |
211 { | |
212 int preserve_input; | |
213 for (preserve_input = 0; preserve_input <= 1; ++preserve_input) | |
214 REGISTER_SOLVER(p, mksolver(preserve_input)); | |
215 } |