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

Relation between thread and program stack space

David_DiLaura1
New Contributor I
493 Views

Steve, Colleagues,

What is the relationship between the Linker parameter "Stack Reserve Size" as set in Project Properties dropdown, and the value set with kmp_set_stacksize_s()?

It is my understanding that kmp_set_stacksize_s() allocates stack space for each thread. Is this in addition to that allocated for the "program" -- that is the master thread (number zero)? Or "within it"?  I have a very large section of code within a parallel do, and for most projects I can run 4 threads with 32,000,000 used in kmp_set_stacksize_s(). The loop involves reduction of three large arrays. In these cases the linker parameter "Stack Reserve Size" can be set to 400,000,000

I have a larger project that requires 64,000,000 in kmp_set_stacksize_s(), and runs IFF  I run only one thread; that is, use call OMP_SET_NUM_THREADS(1).  [I'm running a series of experiments to see what these parameter settings should be, in general]   If I run with 2 or more threads, I get a stack overflow error at the place in the code where the threads are being established. Altering linker parameter "Stack Reserve Size" doesn't affect this failure.

It is my assumption that the space required for private and reduced variables in the threaded region scales roughly linearly with thread count. No? The shared variables would NOT require more space with more threads -- aside, perhaps, from some minor overhead.

David

0 Kudos
1 Reply
jimdempseyatthecove
Honored Contributor III
493 Views

(someone may correct me if I am wrong)

The linker stack size, if set, and if kmp_set_stacksize_s(() not used, and environment variables relating to OMP/KMP stack size are not used, then the linker stack size will affect the main thread and and any subsequently created threads.

If kmp_set_stacksize_s() is used, then any subsequently created OpenMP threads will be created with the specified stack size (assuming sufficient memory is available). This function does not allocate or reallocate the stack, it specifies the parameter to be used on beginthreadex (or whatever is used internally). (similar thing with environment variable).

Each thread has its own stack that is established at thread creation time.

Jim Dempsey

0 Kudos
Reply