我对通过调用fftwf_plan_many_dft_r2c()创建many_plan以及使用OpenMP执行它有点困惑。我试图在这里实现的目的是看看是否明确使用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(),我得到了段错误。
有人可以帮我吗?我应该如何在多个线程间分割数据?或者首先它不正确。
预先感谢您。
flyree