OMP parallel nested loop with an inner loop dependent array

OMP parallel nested loop with an inner loop dependent array

Portrait de lemonzhangz

Hi,

I have a question on the omp parallelization in the nested loop. I want to parallelize the outer loop by omp while in the inner loop a loop-dependent array "temp" is used. Without the omp inplementation, this serial of codes work well. But when I set "temp" to be private, and run it, it complains "Segmentation fault!". I guess there must be a mismatch in the dimension of "temp" and "phinew" due to the parallelization. But I don't know how to fix it. Obviously, "temp" cannot be shared by all the threads. Can anyone tell me why and show me a solution?

FYI, the original code is listed here:

#pragma omp parallel shared(phinew, chunk) private(temp)
{
#pragma omp for schedule(static, chunk)
for(j = 0; j <= J; j++){
for(i = 0; i <= I; i++){
temp[i] = phinew[i][j];
}
cosft1(temp - 1, I);
for(i = 0; i <= I; i++){
phinew[i][j] = 2.0 / (I + 0.0) * temp[i]; // don't forget this coefficient 2/I for the inverse transform
}
}
}

6 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.
Portrait de Raf Schietekat

This is really a forum about a more powerful alternative for OpenMP (with which I am not so familiar), and you have probably left out some essential details in the code, but here is my best guess.

(2012-06-22 Added after #5) Of course... OpenMP is not my thing (and I therefore didn't dare assume it could be so elemental).

Portrait de Tim Prince

As Raf said, the TBB forum is not the best place to get advice about OpenMP, which even uses a separate threading library, with no mutual awareness between that and the TBB library.
When you make an array private, that implies the run-time calls to allocate a copy of the array for each thread, evidently increasing consumption of stack space. You would likely require an explicit boost in thread stack limit or general stack limit, or both.
In C or C++, if the array is private, it may be good simply to define it with local scope.

Portrait de lemonzhangz

I tried to make the private variable "temp" locally allocated inside each omp parallel block. But it still does not work and the same complaint comes out as before. In openmp, when I make a variable to be private, does it mean that the different threads replicate it for their own use? If "temp" is a pointer, each thread just produce its own replication of pointer "temp" in the parallel block?

Portrait de jimdempseyatthecove

Add i to your private or use for(int i=...

j is implicitly private.

Jim Dempsey

www.quickthreadprogramming.com
Portrait de Vladimir Polin (Intel)
Quoting jimdempseyatthecove Add i to your private or use for(int i=...

It looks that some oftemp[i] values contain a garbage due to this. printf() is the best method to debug this in this case:)

--Vladimir

Connectez-vous pour laisser un commentaire.