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

Segmentation fault due to long WHERE ... ELSEWHERE ... ENDWHERE with large matrices!?

gurnemanz
Beginner
364 Views
Hi,

I experience a Segmentation fault in my code, which takes place at a long

WHERE (M1 .le. 0.0d0)
ELSEWHERE (M2 .le. 0.0d0)
ELSEWHERE
...
ENDWHERE

construct, when the matrices M1 etc are very large (of the order of 1000x1000). The Segmentation fault disappears (and the code works fine) if
- I use smaller matrices, or
- I substitute the whole structure with a corresponding double cycle over the matrix dimension, and a cascade of IF...ELSEIF...ENDIF.

What could be the reason of this Segmentation fault? Is there some "hidden" stack limit set by the compiler when unrolling the WHERE loop? I compile with parallelization on, and the stack size in the OS (CentOS 6.2 64 bits) is unlimited.

Any help is really appreciated---I don't like using the cumbersome cycle+if method, instead of the more elegant WHERE.

Regards
0 Kudos
1 Solution
Steven_L_Intel1
Employee
364 Views
If you're parallelizing, then you have the thread stack limit. You can try setting the environment variable KMP_STACKSIZE to a larger value, or build with -heap-arrays. The compiler is constructing the mask on the stack.

View solution in original post

0 Kudos
4 Replies
Steven_L_Intel1
Employee
365 Views
If you're parallelizing, then you have the thread stack limit. You can try setting the environment variable KMP_STACKSIZE to a larger value, or build with -heap-arrays. The compiler is constructing the mask on the stack.
0 Kudos
TimP
Honored Contributor III
364 Views
I don't know whether you mean -parallel, since if you used OpenMP you would require an explicit specification of which subscript is to be parallelized.
If there is just one assignment in each section, it often seems more efficient to break into multiple WHERE assignments:
WHERE (M1 <= 0.0)...
WHERE (M2 <= 0.0 .and. M1 > 0.0)...
WHERE (M2 > 0.0 .and. M1 > 0.0)....

As Steve said, the stack limit per thread could be increased by setting KMP_STACKSIZE (default 4MB for 64-bit mode).
0 Kudos
gurnemanz
Beginner
364 Views
Thank you for your prompt help, -heap-array solves the problem!
As a matter of fact, I also had an overflow in the SPREAD construct for the same reason.
Best regards.
0 Kudos
gurnemanz
Beginner
364 Views
Yes, I meant -parallel. I used the ELSEWHERE command because I have half a dozen conditions, and I wanted to be sure that the assignments were mutually exclusive, but I'll keep your suggestion in mind for the future.
Thank you for your help!
0 Kudos
Reply