2

I am currently bumping into stack overflow issues while trying to use large high-dimensional arrays in an Abaqus user material (UMAT) subroutine written in Modern Fortran. To indicate the magnitude, there are about 15 4-D and 5-D double-precision arrays and derived types with sizes like (100,12,52,10), (6,7,100,100,6) among many other double precision and integer variables local to the sub-program units (smaller subroutines contained in modules). I am testing it on a single element model resulting in 32 calls to the UMAT subroutine, which is clearly not that intensive. Below is the error message from the Abaqus/Standard solver.

*** Error: Runtime stack limit has been exceeded.           
    This may be caused by user subroutines with large data structures allocated on   
    the stack or recursion.  For suggestions on how to resolve this problem,  please 
    refer to the chapter "Ensuring thread safety" in the ABAQUS documentation.     
*** ERROR CATEGORY:  ELEMENT LOOP

I learnt that automatic arrays could be the issue (Stack overflow in Fortran 90, Anything helpful about Fortran stack overflow?) and looked at the memory management solutions to use heap instead of stack memory. So far I have tried dynamic allocation and de-allocation using Fortran allocatable arrays and Abaqus-specific thread-safe allocatable arrays (https://abaqus-docs.mit.edu/2017/English/SIMACAESUBRefMap/simasub-c-localarrays.htm). Solver executes successfully when running with smaller (both dynamic/static) arrays e.g. (20,12,52,3),(6,7,20,20,6) but none of them solved the issue when trying those large arrays.

I don't have much background in memory and process management and have tried all options that I could find on the internet. I am unable to provide the code blocks as it is a large one. Hope the provided info would suffice to get a reasonable picture. What would be the stack size for the above array sizes? Could it be possible that the other double precision variables or the intermediate calculations performed with the arrays are still too many to exceed the stack limit within 32 calls to the subroutine? What else could be the reason for the stack memory bottleneck? Any suggestions to resolve this would be helpful.

Ian Bush
  • 6,996
  • 1
  • 21
  • 27
SnowySun
  • 33
  • 4
  • What OS and compiler are you using? Have you tried increasing the stack size? – M. S. B. Aug 31 '21 at 17:56
  • 5
    Use [the `heap-arrays` option](https://software.intel.com/content/www/us/en/develop/documentation/fortran-compiler-oneapi-dev-guide-and-reference/top/compiler-reference/compiler-options/compiler-option-details/advanced-optimization-options/heap-arrays.html) of the Intel Fortran compiler to put all automatic arrays on heap instead of stack. – Scientist Aug 31 '21 at 17:58
  • 1
    Follow the advice by King. To get anything more specific, you should show the code that causes the problem. – Vladimir F Героям слава Aug 31 '21 at 21:40
  • Wow, that's a fast response. @M.S.B. Windows 10 with Intel Parallel Studio XE 16. I am providing the Fortran subroutine to Abaqus which will run it by calling the compiler and hence can't provide the heap-arrays flag for the compiler directly using command line. Also, I would prefer to avoid tweaking anything outside of the code itself, which is why I didn't pursue heap-arrays option or increasing stack size before and went with dynamic allocation. – SnowySun Sep 01 '21 at 02:02
  • @King Is there any compiler directive or other ways to instruct the compiler via Visual Studio GUI to use heap? – SnowySun Sep 01 '21 at 02:05
  • @SnowySun Open in VisualStudio -> Project Tab -> properties -> Configuration Properties -> Fortran -> Command Line -> add `/heap-arrays` to "Additional Options" box. Done. On Windows, you can also use compiler option `/F` to tell the **linker** to increase the size of the run-time stack to allow for large objects on the stack (you have to add this to the list of linker options). But it appears that your main program is not in Fortran. So, this option may not help. – Scientist Sep 01 '21 at 02:14
  • Thats why I said **show us the code**! You could go from automatic arrays to allocatable arrays. Those are always on the heap. Automatic arrays are often like VLAs in C, they often go to the stack. You said you tried that already - to diagnose anything more we need **the code**. – Vladimir F Героям слава Sep 01 '21 at 06:52

0 Answers0