Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
2424 Discussions

OMP parallel nested loop with an inner loop dependent array

lemonzhangz
Beginner
295 Views
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 = phinew;
}
cosft1(temp - 1, I);
for(i = 0; i <= I; i++){
phinew = 2.0 / (I + 0.0) * temp; // don't forget this coefficient 2/I for the inverse transform
}
}
}

0 Kudos
5 Replies
RafSchietekat
Black Belt
295 Views
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).
TimP
Black Belt
295 Views
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.
lemonzhangz
Beginner
295 Views
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?
jimdempseyatthecove
Black Belt
295 Views
Add i to your private or use for(int i=...

j is implicitly private.

Jim Dempsey
Vladimir_P_Intel2
295 Views
Add i to your private or use for(int i=...

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

--Vladimir

Reply