Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.3/mpi/dft-rank1-bigvec.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 == 1 when the vector length vn is >= # processes. | |
22 In this case, we don't need to use a six-step type algorithm, and can | |
23 instead transpose the DFT dimension with the vector dimension to | |
24 make the DFT local. */ | |
25 | |
26 #include "mpi-dft.h" | |
27 #include "mpi-transpose.h" | |
28 #include "dft.h" | |
29 | |
30 typedef struct { | |
31 solver super; | |
32 int preserve_input; /* preserve input even if DESTROY_INPUT was passed */ | |
33 rearrangement rearrange; | |
34 } S; | |
35 | |
36 typedef struct { | |
37 plan_mpi_dft super; | |
38 | |
39 plan *cldt_before, *cld, *cldt_after; | |
40 INT roff, ioff; | |
41 int preserve_input; | |
42 rearrangement rearrange; | |
43 } P; | |
44 | |
45 static void apply(const plan *ego_, R *I, R *O) | |
46 { | |
47 const P *ego = (const P *) ego_; | |
48 plan_dft *cld; | |
49 plan_rdft *cldt_before, *cldt_after; | |
50 INT roff = ego->roff, ioff = ego->ioff; | |
51 | |
52 /* global transpose */ | |
53 cldt_before = (plan_rdft *) ego->cldt_before; | |
54 cldt_before->apply(ego->cldt_before, I, O); | |
55 | |
56 if (ego->preserve_input) I = O; | |
57 | |
58 /* 1d DFT(s) */ | |
59 cld = (plan_dft *) ego->cld; | |
60 cld->apply(ego->cld, O+roff, O+ioff, I+roff, I+ioff); | |
61 | |
62 /* global transpose */ | |
63 cldt_after = (plan_rdft *) ego->cldt_after; | |
64 cldt_after->apply(ego->cldt_after, I, O); | |
65 } | |
66 | |
67 static int applicable(const S *ego, const problem *p_, | |
68 const planner *plnr) | |
69 { | |
70 const problem_mpi_dft *p = (const problem_mpi_dft *) p_; | |
71 int n_pes; | |
72 MPI_Comm_size(p->comm, &n_pes); | |
73 return (1 | |
74 && p->sz->rnk == 1 | |
75 && !(p->flags & ~RANK1_BIGVEC_ONLY) | |
76 && (!ego->preserve_input || (!NO_DESTROY_INPUTP(plnr) | |
77 && p->I != p->O)) | |
78 && (p->vn >= n_pes /* TODO: relax this, using more memory? */ | |
79 || (p->flags & RANK1_BIGVEC_ONLY)) | |
80 | |
81 && XM(rearrange_applicable)(ego->rearrange, | |
82 p->sz->dims[0], p->vn, n_pes) | |
83 | |
84 && (!NO_SLOWP(plnr) /* slow if dft-serial is applicable */ | |
85 || !XM(dft_serial_applicable)(p)) | |
86 ); | |
87 } | |
88 | |
89 static void awake(plan *ego_, enum wakefulness wakefulness) | |
90 { | |
91 P *ego = (P *) ego_; | |
92 X(plan_awake)(ego->cldt_before, wakefulness); | |
93 X(plan_awake)(ego->cld, wakefulness); | |
94 X(plan_awake)(ego->cldt_after, wakefulness); | |
95 } | |
96 | |
97 static void destroy(plan *ego_) | |
98 { | |
99 P *ego = (P *) ego_; | |
100 X(plan_destroy_internal)(ego->cldt_after); | |
101 X(plan_destroy_internal)(ego->cld); | |
102 X(plan_destroy_internal)(ego->cldt_before); | |
103 } | |
104 | |
105 static void print(const plan *ego_, printer *p) | |
106 { | |
107 const P *ego = (const P *) ego_; | |
108 const char descrip[][16] = { "contig", "discontig", "square-after", | |
109 "square-middle", "square-before" }; | |
110 p->print(p, "(mpi-dft-rank1-bigvec/%s%s %(%p%) %(%p%) %(%p%))", | |
111 descrip[ego->rearrange], ego->preserve_input==2 ?"/p":"", | |
112 ego->cldt_before, ego->cld, ego->cldt_after); | |
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_dft *p; | |
119 P *pln; | |
120 plan *cld = 0, *cldt_before = 0, *cldt_after = 0; | |
121 R *ri, *ii, *ro, *io, *I, *O; | |
122 INT yblock, yb, nx, ny, vn; | |
123 int my_pe, n_pes; | |
124 static const plan_adt padt = { | |
125 XM(dft_solve), awake, print, destroy | |
126 }; | |
127 | |
128 UNUSED(ego); | |
129 | |
130 if (!applicable(ego, p_, plnr)) | |
131 return (plan *) 0; | |
132 | |
133 p = (const problem_mpi_dft *) p_; | |
134 | |
135 MPI_Comm_rank(p->comm, &my_pe); | |
136 MPI_Comm_size(p->comm, &n_pes); | |
137 | |
138 nx = p->sz->dims[0].n; | |
139 if (!(ny = XM(rearrange_ny)(ego->rearrange, p->sz->dims[0],p->vn,n_pes))) | |
140 return (plan *) 0; | |
141 vn = p->vn / ny; | |
142 A(ny * vn == p->vn); | |
143 | |
144 yblock = XM(default_block)(ny, n_pes); | |
145 cldt_before = X(mkplan_d)(plnr, | |
146 XM(mkproblem_transpose)( | |
147 nx, ny, vn*2, | |
148 I = p->I, O = p->O, | |
149 p->sz->dims[0].b[IB], yblock, | |
150 p->comm, 0)); | |
151 if (XM(any_true)(!cldt_before, p->comm)) goto nada; | |
152 if (ego->preserve_input || NO_DESTROY_INPUTP(plnr)) { I = O; } | |
153 | |
154 X(extract_reim)(p->sign, I, &ri, &ii); | |
155 X(extract_reim)(p->sign, O, &ro, &io); | |
156 | |
157 yb = XM(block)(ny, yblock, my_pe); | |
158 cld = X(mkplan_d)(plnr, | |
159 X(mkproblem_dft_d)(X(mktensor_1d)(nx, vn*2, vn*2), | |
160 X(mktensor_2d)(yb, vn*2*nx, vn*2*nx, | |
161 vn, 2, 2), | |
162 ro, io, ri, ii)); | |
163 if (XM(any_true)(!cld, p->comm)) goto nada; | |
164 | |
165 cldt_after = X(mkplan_d)(plnr, | |
166 XM(mkproblem_transpose)( | |
167 ny, nx, vn*2, | |
168 I, O, | |
169 yblock, p->sz->dims[0].b[OB], | |
170 p->comm, 0)); | |
171 if (XM(any_true)(!cldt_after, p->comm)) goto nada; | |
172 | |
173 pln = MKPLAN_MPI_DFT(P, &padt, apply); | |
174 | |
175 pln->cldt_before = cldt_before; | |
176 pln->cld = cld; | |
177 pln->cldt_after = cldt_after; | |
178 pln->preserve_input = ego->preserve_input ? 2 : NO_DESTROY_INPUTP(plnr); | |
179 pln->roff = ro - p->O; | |
180 pln->ioff = io - p->O; | |
181 pln->rearrange = ego->rearrange; | |
182 | |
183 X(ops_add)(&cldt_before->ops, &cld->ops, &pln->super.super.ops); | |
184 X(ops_add2)(&cldt_after->ops, &pln->super.super.ops); | |
185 | |
186 return &(pln->super.super); | |
187 | |
188 nada: | |
189 X(plan_destroy_internal)(cldt_after); | |
190 X(plan_destroy_internal)(cld); | |
191 X(plan_destroy_internal)(cldt_before); | |
192 return (plan *) 0; | |
193 } | |
194 | |
195 static solver *mksolver(rearrangement rearrange, int preserve_input) | |
196 { | |
197 static const solver_adt sadt = { PROBLEM_MPI_DFT, mkplan, 0 }; | |
198 S *slv = MKSOLVER(S, &sadt); | |
199 slv->rearrange = rearrange; | |
200 slv->preserve_input = preserve_input; | |
201 return &(slv->super); | |
202 } | |
203 | |
204 void XM(dft_rank1_bigvec_register)(planner *p) | |
205 { | |
206 rearrangement rearrange; | |
207 int preserve_input; | |
208 FORALL_REARRANGE(rearrange) | |
209 for (preserve_input = 0; preserve_input <= 1; ++preserve_input) | |
210 REGISTER_SOLVER(p, mksolver(rearrange, preserve_input)); | |
211 } |