Force all local variables to be allocated on the memory stack.
SPARC: 77/90 x86:77
Allocate all the local variables and arrays in a routine onto the memory stack, unless otherwise specified. This option makes them automatic, rather than static, and provides more freedom to the optimizer for parallelizing a CALL in a loop.
Use of -stackvar is recommended with any of the parallelization options.
Variables and arrays are local, unless they are:
Arguments in a SUBROUTINE or FUNCTION statement (already on stack)
Global items in a COMMON or SAVE, or STATIC statement
Items initialized in a type statement or DATA statement, such as: REAL X/8.0/ or DATA X/8.0/
Initializing a local variable in a DATA statement after an executable reference to that variable is flagged as an error when -stackvar is used:
demo% cat stak.f real x x = 1. t = 0. print*, t data x/3.0/ print *,x+t end demo% f77 -o stak -stackvar stak.f stak.f: MAIN: "stak.f", line 5: Error: attempt to initialize an automatic variable: x
Putting large arrays onto the stack with -stackvar can overflow the stack causing segmentation faults. Increasing the stack size may be required.
There are two stacks:
The whole program has a main stack.
Each thread of a multi-threaded program has a thread stack.
The default stack size is about 8 Megabytes for the main stack and 256 KBytes for each thread stack. The limit command (with no parameters) shows the current main stack size. If you get a segmentation fault using -stackvar, you might try doubling the main stack size at least once.
Example: Show the current main stack size:
demo% limit cputime unlimited filesize unlimited datasize 523256 kbytes stacksize 8192 kbytes <--- coredumpsize unlimited descriptors 64 memorysize unlimited demo%
Example: Set the main stack size to 64 Megabytes:
demo% limit stacksize 65536
Example: Set each thread stack size to 8 Megabytes:
demo% setenv STACKSIZE 8192
For further information of the use of -stackvar with parallelization, see the Parallelization chapter in the Fortran Programming Guide. See csh(1) for details on the limit command.