我對通過調用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