2
* Copyright (c) 2003, 2006 Matteo Frigo
3
* Copyright (c) 2003, 2006 Massachusetts Institute of Technology
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36
static void *spawn_apply(spawn_data *d)
38
PD *ego = (PD *) d->data;
40
plan_hc2hc *cldw = (plan_hc2hc *) (ego->cldws[d->thr_num]);
41
cldw->apply((plan *) cldw, ego->IO);
45
static void apply_dit(const plan *ego_, R *I, R *O)
47
const P *ego = (const P *) ego_;
50
cld = (plan_rdft *) ego->cld;
51
cld->apply((plan *) cld, I, O);
59
X(spawn_loop)(ego->nthr, ego->nthr, spawn_apply, (void*)&d);
63
static void apply_dif(const plan *ego_, R *I, R *O)
65
const P *ego = (const P *) ego_;
74
X(spawn_loop)(ego->nthr, ego->nthr, spawn_apply, (void*)&d);
77
cld = (plan_rdft *) ego->cld;
78
cld->apply((plan *) cld, I, O);
81
static void awake(plan *ego_, enum wakefulness wakefulness)
85
X(plan_awake)(ego->cld, wakefulness);
86
for (i = 0; i < ego->nthr; ++i)
87
X(plan_awake)(ego->cldws[i], wakefulness);
90
static void destroy(plan *ego_)
94
X(plan_destroy_internal)(ego->cld);
95
for (i = 0; i < ego->nthr; ++i)
96
X(plan_destroy_internal)(ego->cldws[i]);
100
static void print(const plan *ego_, printer *p)
102
const P *ego = (const P *) ego_;
104
p->print(p, "(rdft-thr-ct-%s-x%d/%D",
105
ego->super.apply == apply_dit ? "dit" : "dif",
107
for (i = 0; i < ego->nthr; ++i)
108
if (i == 0 || (ego->cldws[i] != ego->cldws[i-1] &&
109
(i <= 1 || ego->cldws[i] != ego->cldws[i-2])))
110
p->print(p, "%(%p%)", ego->cldws[i]);
111
p->print(p, "%(%p%))", ego->cld);
114
static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
116
const hc2hc_solver *ego = (const hc2hc_solver *) ego_;
117
const problem_rdft *p;
119
plan *cld = 0, **cldws = 0;
120
INT n, r, m, vl, ivs, ovs, mcount;
121
int i, nthr, plnr_nthr_save;
126
static const plan_adt padt = {
127
X(rdft_solve), awake, print, destroy
130
if (plnr->nthr <= 1 || !X(hc2hc_applicable)(ego, p_, plnr))
133
p = (const problem_rdft *) p_;
136
r = X(choose_radix)(ego->r, n);
138
mcount = (m + 2) / 2;
140
X(tensor_tornk1)(p->vecsz, &vl, &ivs, &ovs);
142
block_size = (mcount + plnr->nthr - 1) / plnr->nthr;
143
nthr = (int)((mcount + block_size - 1) / block_size);
144
plnr_nthr_save = plnr->nthr;
145
plnr->nthr = (plnr->nthr + nthr - 1) / nthr;
147
cldws = (plan **) MALLOC(sizeof(plan *) * nthr, PLANS);
148
for (i = 0; i < nthr; ++i) cldws[i] = (plan *) 0;
150
switch (p->kind[0]) {
152
for (i = 0; i < nthr; ++i) {
153
cldws[i] = ego->mkcldw(ego,
154
R2HC, r, m, d[0].os, vl, ovs,
157
(mcount - i*block_size) : block_size,
159
if (!cldws[i]) goto nada;
162
t1 = X(mktensor_1d)(r, d[0].is, m * d[0].os);
163
t2 = X(tensor_append)(t1, p->vecsz);
164
X(tensor_destroy)(t1);
166
plnr->nthr = plnr_nthr_save;
168
cld = X(mkplan_d)(plnr,
170
X(mktensor_1d)(m, r * d[0].is, d[0].os),
171
t2, p->I, p->O, p->kind)
175
pln = MKPLAN_RDFT(P, &padt, apply_dit);
179
for (i = 0; i < nthr; ++i) {
180
cldws[i] = ego->mkcldw(ego,
181
HC2R, r, m, d[0].is, vl, ivs,
184
(mcount - i*block_size) : block_size,
186
if (!cldws[i]) goto nada;
189
t1 = X(mktensor_1d)(r, m * d[0].is, d[0].os);
190
t2 = X(tensor_append)(t1, p->vecsz);
191
X(tensor_destroy)(t1);
193
plnr->nthr = plnr_nthr_save;
195
cld = X(mkplan_d)(plnr,
197
X(mktensor_1d)(m, d[0].is, r * d[0].os),
198
t2, p->I, p->O, p->kind)
202
pln = MKPLAN_RDFT(P, &padt, apply_dif);
214
X(ops_zero)(&pln->super.super.ops);
215
for (i = 0; i < nthr; ++i)
216
X(ops_add2)(&cldws[i]->ops, &pln->super.super.ops);
217
X(ops_add2)(&cld->ops, &pln->super.super.ops);
218
return &(pln->super.super);
222
for (i = 0; i < nthr; ++i)
223
X(plan_destroy_internal)(cldws[i]);
226
X(plan_destroy_internal)(cld);
230
hc2hc_solver *X(mksolver_hc2hc_threads)(size_t size, INT r, hc2hc_mkinferior mkcldw)
232
static const solver_adt sadt = { PROBLEM_RDFT, mkplan };
233
hc2hc_solver *slv = (hc2hc_solver *)X(mksolver)(size, &sadt);
235
slv->mkcldw = mkcldw;