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