Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29425 Discussions

stack overflow when trying to uase openmp directive

Ralph_Nelson
Novice
1,289 Views
Been running with single thread and tried to use a single openmp instruction.

do 95 k = 1, ivfcount
j = ivflist(k)
!$omp parallel DO private(i,j)
do 90 i = 1, nfmaxp2
if (i.le.ncn(j)+2) w(j) = w(j) + (a(i,j) * p(cn(i,j)))
90 continue
!$omp end parallel DO
95 continue

Get the error "forrt1: severe (170): Program Exception - stack overflow" A web search shows this isn't uncommon but trying several fixes that were suggested, haven't fixed the problem.

Running Intel Fortran 11.1 in Visual Studion 2008 on Win7 64-bit.

Thanks for any suggestions.
0 Kudos
5 Replies
TimP
Honored Contributor III
1,289 Views
In effect, you have a reduction operator here. With the syntax you quote, you have a race condition, with multiple threads updating w(j) at the maximum possible rate. It doesn't look like you should be trying OpenMP in the inner reduction loop. Supposing that you wrote
!$omp parallel do private(j,tmp)
do k=1,ivfcount
j = ivflist(k)
tmp = dot_product(a(1:min(nfpmax2,ncn(j)+2),j),p(1:min(nfpmax2,ncn(j)+2),j))
!$omp ordered
w(j)= tmp
!$omp end ordered
enddo

You would not need the ordered if you could assure that ivlist doesn't contain repeated values, if in fact that's what is meant in this code.
0 Kudos
Ralph_Nelson
Novice
1,289 Views
Thanks Tim.

Yes, ivflist has no repeated values, just a list of loop values that statisfy a condition.

ivfcount = 0
do 7 j = 1, nelem
if (ivflag(j).ne.1) then
ivfcount = ivfcount +1
ivflist(ivfcount) = j
endif
7 continue

Implementing your suggestion still results in the same failure.
0 Kudos
TimP
Honored Contributor III
1,289 Views
As your search no doubt told you, the most common solutions for stack overflow when introducing OpenMP are attention both to global stack (Microsoft linker properties) and thread stack (KMP_STACKSIZE).
0 Kudos
Ralph_Nelson
Novice
1,289 Views
Tim,

Dumb question(s). I assume I can set the global stack using
Configuation Properties -> Linker -> System -> Stack Reserve Size

Is the thread stack variable set as a comand line addition to Fortran?
0 Kudos
Steven_L_Intel1
Employee
1,289 Views
You have to define an environment variable, KMP_STACKSIZE, before running the program. It isn't a compile or link option.
0 Kudos
Reply