title: parallel summation of arrays with openmp in C++
body: <p>I have a for-loop in C++ that takes a lot of computation time and that I would like to parallelize by using OpenMP (I have 16 cores available). Other, more simple for-loops and FFTs of my code are already parallelized with OpenMP and work fine. I have tried some options but the results were nothing (orders of magnitude difference) like the one computed serially.</p>
  
  <p>My corresponding part of my code looks essentially like the following:</p>
  
  <pre><code>for (i1=1;i1&lt;N;i1++){
      function(Nx, Ny, i1, k, vector_1, vector_2);
      for (i=0;i&lt;(Nx*Ny);i++){
          vector_3[i] = I*kx[i/Ny]*vector_2[i];
      }
      for (i=0;i&lt;(Nx*Ny);i++){
          sum[i1-1] -= vector_2[i];
      }
  
      fftw_execute(p_c2r_4);
      #pragma omp parallel for default(shared)
      for (i=0;i&lt;(Nx*Ny);i++){
          vector_4[i] = vector_4[i]/norm;
      }
  
      for (i2=1;i2&lt;N;i2++){
      function(Nx, Ny, i2, k, vector_1, vector_2);
          for (i=0;i&lt;(Nx*Ny);i++){
              Trans[(i1-1)*N + (i2-1)] -= creal( vector_2[i]*vector_4[i] );
          }
      }
  }
  </code></pre>
  
  <p>One of the for-loops is already parallelized, so my goal is to parallelize the others. For the sums I have seen others using <code>reduction(+:sum)</code> but in my case <code>sum</code> is an array and I get an error when compiling.</p>
  
  <p>Can someone give me a hint because this is a big bottleneck in my code?</p>