title: FFTW plan creation using OpenMP
body: <p>I am trying to perform several FFT's in parallel. I am using FFTW and OpenMP. Each FFT is different, so I'm not relying on FFTW's build-in multithreading (which I know uses OpenMP). </p>
  
  <pre><code>int m;
  
  // assume:
  // int numberOfColumns = 100;
  // int numberOfRows = 100;
  
  #pragma omp parallel for default(none) private(m) shared(numberOfColumns, numberOfRows)//  num_threads(4)
      for(m = 0; m &lt; 36; m++){
  
          // create pointers
          double          *inputTest;
          fftw_complex    *outputTest;
          fftw_plan       testPlan;
  
          // preallocate vectors for FFTW
           outputTest = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*numberOfRows*numberOfColumns);
           inputTest  = (double *)fftw_malloc(sizeof(double)*numberOfRows*numberOfColumns);
  
           // confirm that preallocation worked
           if (inputTest == NULL || outputTest == NULL){
               logger_.log_error("\t\t FFTW memory not allocated on m = %i", m);
           }
  
           // EDIT: insert data into inputTest
           inputTest = someDataSpecificToThisIteration(m); // same size for all m
  
          // create FFTW plan
          #pragma omp critical (make_plan)
          {
              testPlan = fftw_plan_dft_r2c_2d(numberOfRows, numberOfColumns, inputTest, outputTest, FFTW_ESTIMATE);
          }
  
           // confirm that plan was created correctly
           if (testPlan == NULL){
               logger_.log_error("\t\t failed to create plan on m = %i", m);
           }
  
          // execute plan
           fftw_execute(testPlan);
  
          // clean up
           fftw_free(inputTest);
           fftw_free(outputTest);
           fftw_destroy_plan(testPlan);
  
      }// end parallelized for loop
  </code></pre>
  
  <p>This all works fine. However, if I remove the critical construct from around the plan creation (fftw_plan_dft_r2c_2d) my code will fail. Can someone explain why? fftw_plan_dft_r2c_2d isn't really an "orphan", right? Is it because two threads might both try to hit the <em>numberOfRows</em> or <em>numberOfColumns</em> memory location at the same time?</p>