我对通过调用 fftwf_plan_many_dft_r2c() 并使用 OpenMP 执行它来创建 many_plan 有点困惑。我在这里想要实现的是看看是否明确使用 OpenMP 和组织 FFTW 数据可以一起工作。(我知道我“应该”使用 fftw 的多线程版本,但我未能从中获得预期的加速)。
我的代码如下所示:
/* I ignore some helper APIs */
#define N 1024*1024 //N is the total size of 1d fft
fftwf_plan p;
float * in;
fftwf_complex *out;
omp_set_num_threads(threadNum); // Suppose threadNum is 2 here
in = fftwf_alloc_real(2*(N/2+1));
std::fill(in,in+2*(N/2+1),1.1f); // just try with a random real floating numbers
out = (fftwf_complex *)&in[0]; // for in-place transformation
/* Problems start from here */
int n[] = {N/threadNum}; // according to the manual, n is the size of each "howmany" transformation
p = fftwf_plan_many_dft_r2c(1, n, threadNum, in, NULL,1 ,1, out, NULL, 1, 1, FFTW_ESTIMATE);
#pragma omp parallel for
for (int i = 0; i < threadNum; i ++)
{
fftwf_execute(p);
// fftwf_execute_dft_r2c(p,in+i*N/threadNum,out+i*N/threadNum);
}
我得到的是这样的:
如果我使用 fftwf_execute(p),程序执行成功,但结果似乎不正确。(我将结果与不使用 many_plan 和 openmp 的版本进行比较)
如果我使用 fftwf_execute_dft_r2c(),我得到分段错误。
有人可以在这里帮助我吗?我应该如何跨多个线程分区数据?或者它首先是不正确的。
先感谢您。
飞人