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

OMP parallel nested loop with an inner loop dependent array

lemonzhangz
Beginner
893 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
Valued Contributor III
893 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).
0 Kudos
TimP
Honored Contributor III
893 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.
0 Kudos
lemonzhangz
Beginner
893 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?
0 Kudos
jimdempseyatthecove
Honored Contributor III
893 Views
Add i to your private or use for(int i=...

j is implicitly private.

Jim Dempsey
0 Kudos
Vladimir_P_1234567890
893 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

0 Kudos
Reply