1

I am a little confused about creating many_plan by calling fftwf_plan_many_dft_r2c() and executing it with OpenMP. What I am trying to achieve here is to see if explicitly using OpenMP and organizing FFTW data could work together. ( I know I "should" use multithreaded version of fftw but I failed to get a expected speedup from it ).

My code looks like this:

/* 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);
}

What I got is like this:

If I use fftwf_execute(p), the program executes successfully, but the result seems not correct. ( I compare the result with the version of not using many_plan and openmp )

If I use fftwf_execute_dft_r2c(), I got segmentation fault.

Can somebody help me here? How should I partition the data across multiple threads? Or it is not correct in the first place.

Thank you in advance.

flyree

4

1 に答える 1

1
  • outにメモリを適切に割り当てていますか? これを行います:
out = (fftwf_complex *)&in[0];  // for in-place transformation

これと同じことを行います:

out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*numberOfOutputColumns);
  • 使用方法を特に openMP に指示せずに、並列ブロック内の 'p' にアクセスしようとしています。そのはず:

pragma omp parallel for shared(p)

  • 作業を n スレッドに分割する場合は、omp に n スレッドを使用するように明示的に指示する必要があると思います。

pragma omp parallel for shared(p) num_threads(n)

  • このコードはマルチスレッドなしで機能しますか? for ループと openMP 呼び出しを削除し、fftwf_execute(p) を 1 回だけ実行すると機能しますか?

  • FFTW の多数の計画についてはよくわかりませんが、p は単一の計画ではなく、実際には多数の計画のようです。では、p を「実行」すると、すべての計画を一度に実行することになりますよね? p を繰り返し実行する必要はありません。

OpenMP + FFTW についてはまだ学習中なので、間違っている可能性があります。プラグマの前に # を置くと、StackOverflow は気に入らないのですが、# が必要です。

于 2013-02-21T20:36:15.917 に答える