shared arrays in OpenMP
<p>I'm trying to parallelize a piece of C++ code with OpenMp but I'm facing some problems.
In fact, my parallelized code is not faster than the serial one.
I think I have understood the cause of this, but I'm not able to solve it.</p>

<p>The structure of my code is like this:</p>

<pre><code>int vec1 [M];
int vec2 [N];

...initialization of vec1 and vec2...

for (int it=0; it &lt; tot_iterations; it++) {

if ( (it+1)%2 != 0 ) {

   #pragma omp parallel for

   for (int j=0 ; j &lt; N ; j++) {

  ....code involving a call to a function to which I'm passing as a parameter vec1.....

if (something) { vec2[j]=vec2[j]-1;}

}
}
else {
   # pragma omp parallel for

   for (int i=0 ; i &lt; M ; i++) {

  ....code involving a call to a function to which I'm passing as a parameter vec2.....

 if (something) { vec1[i]=vec1[i]-1;}

 }
 }

 }
</code></pre>

<p>I thought that maybe my parallelized code is slower because multiple threads want to access to the same shared array and one has to wait until another has finished, but I'm not sure how things really go. But I can't make vec1 and vec2 private since the updates wouldn't be seen in the other iterations...
How can I improve it??</p>