cannam@95
|
1 /*
|
cannam@95
|
2 * Copyright (c) 2003, 2007-11 Matteo Frigo
|
cannam@95
|
3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
|
cannam@95
|
4 *
|
cannam@95
|
5 * This program is free software; you can redistribute it and/or modify
|
cannam@95
|
6 * it under the terms of the GNU General Public License as published by
|
cannam@95
|
7 * the Free Software Foundation; either version 2 of the License, or
|
cannam@95
|
8 * (at your option) any later version.
|
cannam@95
|
9 *
|
cannam@95
|
10 * This program is distributed in the hope that it will be useful,
|
cannam@95
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
cannam@95
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
cannam@95
|
13 * GNU General Public License for more details.
|
cannam@95
|
14 *
|
cannam@95
|
15 * You should have received a copy of the GNU General Public License
|
cannam@95
|
16 * along with this program; if not, write to the Free Software
|
cannam@95
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
cannam@95
|
18 *
|
cannam@95
|
19 */
|
cannam@95
|
20
|
cannam@95
|
21 /* Complex DFTs of rank == 1 when the vector length vn is >= # processes.
|
cannam@95
|
22 In this case, we don't need to use a six-step type algorithm, and can
|
cannam@95
|
23 instead transpose the DFT dimension with the vector dimension to
|
cannam@95
|
24 make the DFT local. */
|
cannam@95
|
25
|
cannam@95
|
26 #include "mpi-dft.h"
|
cannam@95
|
27 #include "mpi-transpose.h"
|
cannam@95
|
28 #include "dft.h"
|
cannam@95
|
29
|
cannam@95
|
30 typedef struct {
|
cannam@95
|
31 solver super;
|
cannam@95
|
32 int preserve_input; /* preserve input even if DESTROY_INPUT was passed */
|
cannam@95
|
33 rearrangement rearrange;
|
cannam@95
|
34 } S;
|
cannam@95
|
35
|
cannam@95
|
36 typedef struct {
|
cannam@95
|
37 plan_mpi_dft super;
|
cannam@95
|
38
|
cannam@95
|
39 plan *cldt_before, *cld, *cldt_after;
|
cannam@95
|
40 INT roff, ioff;
|
cannam@95
|
41 int preserve_input;
|
cannam@95
|
42 rearrangement rearrange;
|
cannam@95
|
43 } P;
|
cannam@95
|
44
|
cannam@95
|
45 static void apply(const plan *ego_, R *I, R *O)
|
cannam@95
|
46 {
|
cannam@95
|
47 const P *ego = (const P *) ego_;
|
cannam@95
|
48 plan_dft *cld;
|
cannam@95
|
49 plan_rdft *cldt_before, *cldt_after;
|
cannam@95
|
50 INT roff = ego->roff, ioff = ego->ioff;
|
cannam@95
|
51
|
cannam@95
|
52 /* global transpose */
|
cannam@95
|
53 cldt_before = (plan_rdft *) ego->cldt_before;
|
cannam@95
|
54 cldt_before->apply(ego->cldt_before, I, O);
|
cannam@95
|
55
|
cannam@95
|
56 if (ego->preserve_input) I = O;
|
cannam@95
|
57
|
cannam@95
|
58 /* 1d DFT(s) */
|
cannam@95
|
59 cld = (plan_dft *) ego->cld;
|
cannam@95
|
60 cld->apply(ego->cld, O+roff, O+ioff, I+roff, I+ioff);
|
cannam@95
|
61
|
cannam@95
|
62 /* global transpose */
|
cannam@95
|
63 cldt_after = (plan_rdft *) ego->cldt_after;
|
cannam@95
|
64 cldt_after->apply(ego->cldt_after, I, O);
|
cannam@95
|
65 }
|
cannam@95
|
66
|
cannam@95
|
67 static int applicable(const S *ego, const problem *p_,
|
cannam@95
|
68 const planner *plnr)
|
cannam@95
|
69 {
|
cannam@95
|
70 const problem_mpi_dft *p = (const problem_mpi_dft *) p_;
|
cannam@95
|
71 int n_pes;
|
cannam@95
|
72 MPI_Comm_size(p->comm, &n_pes);
|
cannam@95
|
73 return (1
|
cannam@95
|
74 && p->sz->rnk == 1
|
cannam@95
|
75 && !(p->flags & ~RANK1_BIGVEC_ONLY)
|
cannam@95
|
76 && (!ego->preserve_input || (!NO_DESTROY_INPUTP(plnr)
|
cannam@95
|
77 && p->I != p->O))
|
cannam@95
|
78 && (p->vn >= n_pes /* TODO: relax this, using more memory? */
|
cannam@95
|
79 || (p->flags & RANK1_BIGVEC_ONLY))
|
cannam@95
|
80
|
cannam@95
|
81 && XM(rearrange_applicable)(ego->rearrange,
|
cannam@95
|
82 p->sz->dims[0], p->vn, n_pes)
|
cannam@95
|
83
|
cannam@95
|
84 && (!NO_SLOWP(plnr) /* slow if dft-serial is applicable */
|
cannam@95
|
85 || !XM(dft_serial_applicable)(p))
|
cannam@95
|
86 );
|
cannam@95
|
87 }
|
cannam@95
|
88
|
cannam@95
|
89 static void awake(plan *ego_, enum wakefulness wakefulness)
|
cannam@95
|
90 {
|
cannam@95
|
91 P *ego = (P *) ego_;
|
cannam@95
|
92 X(plan_awake)(ego->cldt_before, wakefulness);
|
cannam@95
|
93 X(plan_awake)(ego->cld, wakefulness);
|
cannam@95
|
94 X(plan_awake)(ego->cldt_after, wakefulness);
|
cannam@95
|
95 }
|
cannam@95
|
96
|
cannam@95
|
97 static void destroy(plan *ego_)
|
cannam@95
|
98 {
|
cannam@95
|
99 P *ego = (P *) ego_;
|
cannam@95
|
100 X(plan_destroy_internal)(ego->cldt_after);
|
cannam@95
|
101 X(plan_destroy_internal)(ego->cld);
|
cannam@95
|
102 X(plan_destroy_internal)(ego->cldt_before);
|
cannam@95
|
103 }
|
cannam@95
|
104
|
cannam@95
|
105 static void print(const plan *ego_, printer *p)
|
cannam@95
|
106 {
|
cannam@95
|
107 const P *ego = (const P *) ego_;
|
cannam@95
|
108 const char descrip[][16] = { "contig", "discontig", "square-after",
|
cannam@95
|
109 "square-middle", "square-before" };
|
cannam@95
|
110 p->print(p, "(mpi-dft-rank1-bigvec/%s%s %(%p%) %(%p%) %(%p%))",
|
cannam@95
|
111 descrip[ego->rearrange], ego->preserve_input==2 ?"/p":"",
|
cannam@95
|
112 ego->cldt_before, ego->cld, ego->cldt_after);
|
cannam@95
|
113 }
|
cannam@95
|
114
|
cannam@95
|
115 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
|
cannam@95
|
116 {
|
cannam@95
|
117 const S *ego = (const S *) ego_;
|
cannam@95
|
118 const problem_mpi_dft *p;
|
cannam@95
|
119 P *pln;
|
cannam@95
|
120 plan *cld = 0, *cldt_before = 0, *cldt_after = 0;
|
cannam@95
|
121 R *ri, *ii, *ro, *io, *I, *O;
|
cannam@95
|
122 INT yblock, yb, nx, ny, vn;
|
cannam@95
|
123 int my_pe, n_pes;
|
cannam@95
|
124 static const plan_adt padt = {
|
cannam@95
|
125 XM(dft_solve), awake, print, destroy
|
cannam@95
|
126 };
|
cannam@95
|
127
|
cannam@95
|
128 UNUSED(ego);
|
cannam@95
|
129
|
cannam@95
|
130 if (!applicable(ego, p_, plnr))
|
cannam@95
|
131 return (plan *) 0;
|
cannam@95
|
132
|
cannam@95
|
133 p = (const problem_mpi_dft *) p_;
|
cannam@95
|
134
|
cannam@95
|
135 MPI_Comm_rank(p->comm, &my_pe);
|
cannam@95
|
136 MPI_Comm_size(p->comm, &n_pes);
|
cannam@95
|
137
|
cannam@95
|
138 nx = p->sz->dims[0].n;
|
cannam@95
|
139 if (!(ny = XM(rearrange_ny)(ego->rearrange, p->sz->dims[0],p->vn,n_pes)))
|
cannam@95
|
140 return (plan *) 0;
|
cannam@95
|
141 vn = p->vn / ny;
|
cannam@95
|
142 A(ny * vn == p->vn);
|
cannam@95
|
143
|
cannam@95
|
144 yblock = XM(default_block)(ny, n_pes);
|
cannam@95
|
145 cldt_before = X(mkplan_d)(plnr,
|
cannam@95
|
146 XM(mkproblem_transpose)(
|
cannam@95
|
147 nx, ny, vn*2,
|
cannam@95
|
148 I = p->I, O = p->O,
|
cannam@95
|
149 p->sz->dims[0].b[IB], yblock,
|
cannam@95
|
150 p->comm, 0));
|
cannam@95
|
151 if (XM(any_true)(!cldt_before, p->comm)) goto nada;
|
cannam@95
|
152 if (ego->preserve_input || NO_DESTROY_INPUTP(plnr)) { I = O; }
|
cannam@95
|
153
|
cannam@95
|
154 X(extract_reim)(p->sign, I, &ri, &ii);
|
cannam@95
|
155 X(extract_reim)(p->sign, O, &ro, &io);
|
cannam@95
|
156
|
cannam@95
|
157 yb = XM(block)(ny, yblock, my_pe);
|
cannam@95
|
158 cld = X(mkplan_d)(plnr,
|
cannam@95
|
159 X(mkproblem_dft_d)(X(mktensor_1d)(nx, vn*2, vn*2),
|
cannam@95
|
160 X(mktensor_2d)(yb, vn*2*nx, vn*2*nx,
|
cannam@95
|
161 vn, 2, 2),
|
cannam@95
|
162 ro, io, ri, ii));
|
cannam@95
|
163 if (XM(any_true)(!cld, p->comm)) goto nada;
|
cannam@95
|
164
|
cannam@95
|
165 cldt_after = X(mkplan_d)(plnr,
|
cannam@95
|
166 XM(mkproblem_transpose)(
|
cannam@95
|
167 ny, nx, vn*2,
|
cannam@95
|
168 I, O,
|
cannam@95
|
169 yblock, p->sz->dims[0].b[OB],
|
cannam@95
|
170 p->comm, 0));
|
cannam@95
|
171 if (XM(any_true)(!cldt_after, p->comm)) goto nada;
|
cannam@95
|
172
|
cannam@95
|
173 pln = MKPLAN_MPI_DFT(P, &padt, apply);
|
cannam@95
|
174
|
cannam@95
|
175 pln->cldt_before = cldt_before;
|
cannam@95
|
176 pln->cld = cld;
|
cannam@95
|
177 pln->cldt_after = cldt_after;
|
cannam@95
|
178 pln->preserve_input = ego->preserve_input ? 2 : NO_DESTROY_INPUTP(plnr);
|
cannam@95
|
179 pln->roff = ro - p->O;
|
cannam@95
|
180 pln->ioff = io - p->O;
|
cannam@95
|
181 pln->rearrange = ego->rearrange;
|
cannam@95
|
182
|
cannam@95
|
183 X(ops_add)(&cldt_before->ops, &cld->ops, &pln->super.super.ops);
|
cannam@95
|
184 X(ops_add2)(&cldt_after->ops, &pln->super.super.ops);
|
cannam@95
|
185
|
cannam@95
|
186 return &(pln->super.super);
|
cannam@95
|
187
|
cannam@95
|
188 nada:
|
cannam@95
|
189 X(plan_destroy_internal)(cldt_after);
|
cannam@95
|
190 X(plan_destroy_internal)(cld);
|
cannam@95
|
191 X(plan_destroy_internal)(cldt_before);
|
cannam@95
|
192 return (plan *) 0;
|
cannam@95
|
193 }
|
cannam@95
|
194
|
cannam@95
|
195 static solver *mksolver(rearrangement rearrange, int preserve_input)
|
cannam@95
|
196 {
|
cannam@95
|
197 static const solver_adt sadt = { PROBLEM_MPI_DFT, mkplan, 0 };
|
cannam@95
|
198 S *slv = MKSOLVER(S, &sadt);
|
cannam@95
|
199 slv->rearrange = rearrange;
|
cannam@95
|
200 slv->preserve_input = preserve_input;
|
cannam@95
|
201 return &(slv->super);
|
cannam@95
|
202 }
|
cannam@95
|
203
|
cannam@95
|
204 void XM(dft_rank1_bigvec_register)(planner *p)
|
cannam@95
|
205 {
|
cannam@95
|
206 rearrangement rearrange;
|
cannam@95
|
207 int preserve_input;
|
cannam@95
|
208 FORALL_REARRANGE(rearrange)
|
cannam@95
|
209 for (preserve_input = 0; preserve_input <= 1; ++preserve_input)
|
cannam@95
|
210 REGISTER_SOLVER(p, mksolver(rearrange, preserve_input));
|
cannam@95
|
211 }
|