I'm having an issue trying to parallelize a nested loop using OpenMP - it's just demo code for playing around and getting used to.
int* myresults = new int[1000]
#pragma omp parallel
{
#pragma omp for
for(int z=0; z<=mainCount;z++)
{
results[n++] = myfunc(z,0); //compute something
for(int i=0;i<=secondCount;i+=5)
{
results[n++]=myfunc(z,i);
}
}
}
My problem is the indexing of my results array. I assume since OpenMP is parallelizing the first for-loop that he is using positions of results[] twice or more because results[n++] will produce undefined behaviour (as it cannot be assured that n is incremented right), am I correct?
How can I correctly index and store my results?