Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.3/mpi/dft-serial.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 /* "MPI" DFTs where all of the data is on one processor...just | |
22 call through to serial API. */ | |
23 | |
24 #include "mpi-dft.h" | |
25 #include "dft.h" | |
26 | |
27 typedef struct { | |
28 plan_mpi_dft super; | |
29 plan *cld; | |
30 INT roff, ioff; | |
31 } P; | |
32 | |
33 static void apply(const plan *ego_, R *I, R *O) | |
34 { | |
35 const P *ego = (const P *) ego_; | |
36 plan_dft *cld; | |
37 INT roff = ego->roff, ioff = ego->ioff; | |
38 cld = (plan_dft *) ego->cld; | |
39 cld->apply(ego->cld, I+roff, I+ioff, O+roff, O+ioff); | |
40 } | |
41 | |
42 static void awake(plan *ego_, enum wakefulness wakefulness) | |
43 { | |
44 P *ego = (P *) ego_; | |
45 X(plan_awake)(ego->cld, wakefulness); | |
46 } | |
47 | |
48 static void destroy(plan *ego_) | |
49 { | |
50 P *ego = (P *) ego_; | |
51 X(plan_destroy_internal)(ego->cld); | |
52 } | |
53 | |
54 static void print(const plan *ego_, printer *p) | |
55 { | |
56 const P *ego = (const P *) ego_; | |
57 p->print(p, "(mpi-dft-serial %(%p%))", ego->cld); | |
58 } | |
59 | |
60 int XM(dft_serial_applicable)(const problem_mpi_dft *p) | |
61 { | |
62 return (1 | |
63 && p->flags == 0 /* TRANSPOSED/SCRAMBLED_IN/OUT not supported */ | |
64 && ((XM(is_local)(p->sz, IB) && XM(is_local)(p->sz, OB)) | |
65 || p->vn == 0)); | |
66 } | |
67 | |
68 static plan *mkplan(const solver *ego, const problem *p_, planner *plnr) | |
69 { | |
70 const problem_mpi_dft *p = (const problem_mpi_dft *) p_; | |
71 P *pln; | |
72 plan *cld; | |
73 int my_pe; | |
74 R *ri, *ii, *ro, *io; | |
75 static const plan_adt padt = { | |
76 XM(dft_solve), awake, print, destroy | |
77 }; | |
78 | |
79 UNUSED(ego); | |
80 | |
81 /* check whether applicable: */ | |
82 if (!XM(dft_serial_applicable)(p)) | |
83 return (plan *) 0; | |
84 | |
85 X(extract_reim)(p->sign, p->I, &ri, &ii); | |
86 X(extract_reim)(p->sign, p->O, &ro, &io); | |
87 | |
88 MPI_Comm_rank(p->comm, &my_pe); | |
89 if (my_pe == 0 && p->vn > 0) { | |
90 int i, rnk = p->sz->rnk; | |
91 tensor *sz = X(mktensor)(p->sz->rnk); | |
92 sz->dims[rnk - 1].is = sz->dims[rnk - 1].os = 2 * p->vn; | |
93 sz->dims[rnk - 1].n = p->sz->dims[rnk - 1].n; | |
94 for (i = rnk - 1; i > 0; --i) { | |
95 sz->dims[i - 1].is = sz->dims[i - 1].os = | |
96 sz->dims[i].is * sz->dims[i].n; | |
97 sz->dims[i - 1].n = p->sz->dims[i - 1].n; | |
98 } | |
99 | |
100 cld = X(mkplan_d)(plnr, | |
101 X(mkproblem_dft_d)(sz, | |
102 X(mktensor_1d)(p->vn, 2, 2), | |
103 ri, ii, ro, io)); | |
104 } | |
105 else { /* idle process: make nop plan */ | |
106 cld = X(mkplan_d)(plnr, | |
107 X(mkproblem_dft_d)(X(mktensor_0d)(), | |
108 X(mktensor_1d)(0,0,0), | |
109 ri, ii, ro, io)); | |
110 } | |
111 if (XM(any_true)(!cld, p->comm)) return (plan *) 0; | |
112 | |
113 pln = MKPLAN_MPI_DFT(P, &padt, apply); | |
114 pln->cld = cld; | |
115 pln->roff = ro - p->O; | |
116 pln->ioff = io - p->O; | |
117 X(ops_cpy)(&cld->ops, &pln->super.super.ops); | |
118 return &(pln->super.super); | |
119 } | |
120 | |
121 static solver *mksolver(void) | |
122 { | |
123 static const solver_adt sadt = { PROBLEM_MPI_DFT, mkplan, 0 }; | |
124 return MKSOLVER(solver, &sadt); | |
125 } | |
126 | |
127 void XM(dft_serial_register)(planner *p) | |
128 { | |
129 REGISTER_SOLVER(p, mksolver()); | |
130 } |