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