I am trying to run several FFTs in parallel. I use FFTW and OpenMP. Each FFT is different, so I don't rely on FFTW multithreading, which, as I know, uses OpenMP.
int m;
#pragma omp parallel for default(none) private(m) shared(numberOfColumns, numberOfRows)
for(m = 0; m < 36; m++){
double *inputTest;
fftw_complex *outputTest;
fftw_plan testPlan;
outputTest = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*numberOfRows*numberOfColumns);
inputTest = (double *)fftw_malloc(sizeof(double)*numberOfRows*numberOfColumns);
if (inputTest == NULL || outputTest == NULL){
logger_.log_error("\t\t FFTW memory not allocated on m = %i", m);
}
inputTest = someDataSpecificToThisIteration(m);
#pragma omp critical (make_plan)
{
testPlan = fftw_plan_dft_r2c_2d(numberOfRows, numberOfColumns, inputTest, outputTest, FFTW_ESTIMATE);
}
if (testPlan == NULL){
logger_.log_error("\t\t failed to create plan on m = %i", m);
}
fftw_execute(testPlan);
fftw_free(inputTest);
fftw_free(outputTest);
fftw_destroy_plan(testPlan);
}
It all works great. However, if I remove the critical construct around creating the plan (fftw_plan_dft_r2c_2d), my code will fail. Can someone explain why? fftw_plan_dft_r2c_2d is not really an orphan, is it? Is this due to the fact that two threads can simultaneously try to delete memory cells numberOfRows or numberOfColumns at the same time?
tir38 source
share