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?
// 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 ??
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?