FFTW plans using OpenMP

I have the following function using the FFTW3 plan and I am trying to parallelize it with openMP. I am following with the FFTW doucmentation, however I don't think I am getting it right. How how you go about this and explain why?

My function:
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

// Make a c2r fft function for ease of use and to not lose data. Use this to take inverse FFTs.

// Something about it internally causes the Fourier space variable to be overwritten. 
// This is not something that is fine for us because we will need to take many inverse FFTs but still need the old values.
// So, this function put the variable into a dummy variable. Then, it takes the inverse FFT of that dummy variable so no data are lost.

void c2rfft(double cArr[][ncomp], double rArr[]){   
    // Make a dummy variable so we don't overwrite data
    fftw_complex *dummy;
    dummy = (fftw_complex*) fftw_malloc(nx*nyk* sizeof(fftw_complex)); 
    // Set this dummy variable equal to the complex array
        for (int i = 0; i < nx; i++){
            for(int j = 0; j < nyk; j++){
                for(int k = 0; k < ncomp; k++){
                    dummy[j + nyk*i][k] = cArr[j + nyk*i][k];
                }
            }
        }       
    // Make a FFT plan
    fftw_plan c2r;
    // Define the FFT plan
    c2r = fftw_plan_dft_c2r_2d(nx, ny, &dummy[0], &rArr[0], FFTW_ESTIMATE); //dummy[0] is real part of dummy
    // Run FFT
    fftw_execute(c2r);
    
    fftw_destroy_plan(c2r);
    
    fftw_cleanup();
    

    scalArr2DMult(rArr, 1.0 / (nx*ny), rArr); //renormalize 
    
    fftw_free(dummy);

}


All I am including so far is the fftw3.h files, do I need to use something else? like fftw_threads.h ??
Last edited on
So, I have been reading some examples online. There aren't many for FFTW and openmp unfortunately. For now I have a question what is the difference between these two codes and why the second one gives me an error?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

void r2cfft(double rArr[], double cArr[][ncomp]){
    // before creating a plan you want to parrallelize, call this function: void fftw_plan_with_nthreads(int nthreads);
  

    fftw_plan r2c; 

    #pragma omp critical (FFTW)  // FFTW? make_plan?
        
     // Define the FFT plan
       r2c = fftw_plan_dft_r2c_2d(nx, ny, &rArr[0], &cArr[0], FFTW_ESTIMATE);
     
      // Run FFT
     fftw_execute(r2c);

     //#pragma omp critical (FFTW) 
     fftw_destroy_plan(r2c);
    
    
    

     fftw_cleanup();
}


Why I get the error: declaration is incompatible with "<error-type> r2cfft" at line 1

This declaration has no storage class or type specifier at line 8

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void r2cfft(double rArr[], double cArr[][ncomp]){ // error line 1

    fftw_plan r2c; 

    #pragma omp critical (FFTW) {
        // Define the FFT plan
       r2c = fftw_plan_dft_r2c_2d(nx, ny, &rArr[0], &cArr[0], FFTW_ESTIMATE);


    } 
        
      // Run FFT
     fftw_execute(r2c); // error line 8

    #pragma omp critical (FFTW) {
        fftw_destroy_plan(r2c);

    } // error: expected a declaration
     
    
     fftw_cleanup();
}


This basically breaks my entire FFTW functions and routines I am using.

My apologies, I realize these are pretty basic questions, but I am truly struggling to understand the documentation of fftw with multithreading and I can't seem to even set up a test code. I was following with this simple example:
https://stackoverflow.com/questions/66591719/using-fftw-in-oop-with-multithreading
Topic archived. No new replies allowed.