1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/*
* Copyright (c) 1997-1999, 2003 Massachusetts Institute of Technology
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <stdlib.h>
#include "fftw_threads-int.h"
#include "fftw_threads.h"
typedef struct {
fftwnd_plan plan;
int cur_dim;
int distance;
fftw_complex *in, *out;
int istride, ostride;
fftw_complex *work;
} fftwnd_aux_many_data;
static void *fftwnd_aux_many_thread(fftw_loop_data *loop_data)
{
int min = loop_data->min, max = loop_data->max;
fftwnd_aux_many_data *d = (fftwnd_aux_many_data *) loop_data->data;
int distance = d->distance, cur_dim = d->cur_dim;
fftwnd_plan plan = d->plan;
fftw_complex *in = d->in, *out = d->out;
int istride = d->istride, ostride = d->ostride;
fftw_complex *work = d->work + loop_data->thread_num * plan->nwork;
for (; min < max; ++min)
fftwnd_aux(plan,cur_dim,
in + min*istride*distance,istride,
out + min*ostride*distance,ostride,
work);
return 0;
}
static void fftwnd_aux_many_threads(int nthreads, int n, int n_after,
fftwnd_plan plan, int cur_dim,
fftw_complex *in, int istride,
fftw_complex *out, int ostride)
{
fftw_complex *tmp;
fftwnd_aux_many_data d;
if (nthreads > n)
nthreads = n;
tmp = (fftw_complex *) fftw_malloc(nthreads * plan->nwork
* sizeof(fftw_complex));
d.plan = plan;
d.cur_dim = cur_dim;
d.distance = n_after;
d.in = in;
d.out = out;
d.istride = istride;
d.ostride = ostride;
d.work = tmp;
fftw_thread_spawn_loop(n, nthreads, fftwnd_aux_many_thread, &d);
fftw_free(tmp);
}
static void fftwnd_threads_aux(int nthreads, fftwnd_plan p, int cur_dim,
fftw_complex *in, int istride,
fftw_complex *out, int ostride)
{
int n_after = p->n_after[cur_dim], n = p->n[cur_dim];
if (cur_dim == p->rank - 2) {
/* just do the last dimension directly: */
if (p->is_in_place)
fftw_threads(nthreads, p->plans[p->rank - 1], n,
in, istride, n_after * istride,
(fftw_complex*)NULL, 0, 0);
else
fftw_threads(nthreads, p->plans[p->rank - 1], n,
in, istride, n_after * istride,
out, ostride, n_after * ostride);
}
else { /* we have at least two dimensions to go */
/* process the subsequent dimensions recursively, in hyperslabs,
to get maximum locality: */
fftwnd_aux_many_threads(nthreads, n, n_after,
p, cur_dim + 1,
in, istride, out, ostride);
}
/* do the current dimension (in-place): */
fftw_threads(nthreads, p->plans[cur_dim], n_after,
out, n_after * ostride, ostride,
(fftw_complex*)NULL, 0, 0);
}
void fftwnd_threads(int nthreads, fftwnd_plan p, int howmany,
fftw_complex *in, int istride, int idist,
fftw_complex *out, int ostride, int odist)
{
switch (p->rank) {
case 0:
break;
case 1:
if (p->is_in_place) /* fft is in-place */
fftw_threads(nthreads, p->plans[0], howmany,
in, istride, idist,
(fftw_complex*) NULL, 0, 0);
else
fftw_threads(nthreads, p->plans[0], howmany,
in, istride, idist,
out, ostride, odist);
break;
default: /* rank >= 2 */
{
int i;
if (p->is_in_place) {
out = in;
ostride = istride;
odist = idist;
}
if (nthreads <= 1)
fftwnd(p, howmany, in, istride, idist, out, ostride, odist);
else
for (i = 0; i < howmany; ++i)
fftwnd_threads_aux(nthreads, p, 0,
in + i*idist, istride,
out + i*odist, ostride);
}
}
}
void fftwnd_threads_one(int nthreads, fftwnd_plan p,
fftw_complex *in, fftw_complex *out)
{
fftwnd_threads(nthreads, p, 1, in, 1, 0, out, 1, 0);
}
|