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

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

gurnemanz
初學者
1,238 檢視
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 積分
1 解決方案
Steven_L_Intel1
1,238 檢視
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.

在原始文章中檢視解決方案

4 回應
Steven_L_Intel1
1,239 檢視
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.
TimP
榮譽貢獻者 III
1,238 檢視
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).
gurnemanz
初學者
1,238 檢視
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.
gurnemanz
初學者
1,238 檢視
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!
回覆