Intel® MPI Library
Get help with building, analyzing, optimizing, and scaling high-performance computing (HPC) applications.

Stack Overflow because of OpenMP on Windows

Ines_F_
Beginner
4,234 Views

Hi,

I am running my code with Visual Studio Pro 2015 + parallel studio 2016 on Windows (machine : 16 GB , 64 bits). I get a problem of Stack overflow when using OpenMP associated to a call to the HDF4 function sfrdata (giving in return a large array). I got exactly the same problem on Unix and I was able to solve it thanks to the following post :

https://software.intel.com/fr-fr/forums/intel-clusters-and-hpc-technology/topic/299450

But I still don't understand how to do the same on windows ! where can I increase the STACKSIZE to avoid this problem with OpenMP. I should maybe note that the problem occurs only with the above mentioned HDF4 function, otherwise OpenMP works very well both on Windows and Unix.

Any help ? Thanks !

 

 

0 Kudos
5 Replies
DmitryVlad_P_Intel
4,234 Views

Hello, Ines,

You should set KMP_STACKSIZE or OMP_STACKSIZE environment variables or call a kmp_set_stacksize_s(size_tsize) routine to set a stacksize of for your openMP threads.
Just like mentioned in the link you’ve provided.

In addition to this you should ask Windows to reserve a memory for stack.
You can do this by passing the stacksize to linker

icl /Qopenmp /F0x10000 test.cpp

https://software.intel.com/en-us/node/582163

or

icl test.cpp /Qopenmp /link /STACK:"1000000"

Regards,
Dmitry
 

0 Kudos
SergeyKostrov
Valued Contributor II
4,234 Views
>>...set KMP_STACKSIZE or OMP_STACKSIZE environment variables... Also, These two environment variables could be set at run-time, that is when your program is working. In that case a value for the size of OpenMP stack could be dependent on how large input data is. Setting OMP_STACKSIZE indirectly ( actually a Stack Size for the application ) at a Link Time (!) is Not good because memory could be wasted when you set it to 512MB ( with /STACK option ), and an input data is only 16MB in size.
0 Kudos
SergeyKostrov
Valued Contributor II
4,234 Views
This is an example on how OMP_STACKSIZE environment variable is set at Run-Time: ... RTint iRetCode = CrtSetEnv( RTU("OMP_STACKSIZE=32K") ); if( iRetCode == 0 ) CrtPrintf( RTU("Current OMP_STACKSIZE=%s\n"), CrtGetEnv( RTU("OMP_STACKSIZE") ) ); else CrtPrintf( RTU("Error: Failed to Set Environment Variable OMP_STACKSIZE\n") ); ...
0 Kudos
TimP
Honored Contributor III
4,234 Views

Omp_stacksize or kmp_stacksize is the solution if that was what you used on Linux. If you need to increase overall program stack size as you would do with a linux shell command, this has to be built in the .exe by /link /stack setting or a compiler option which passes that setting, or it could be reset by editbin.

Default omp stack size for 64 bit is 4m so if you required an increase it might be to 9m (the most I ever needed).  As Dmitry mentioned  , that might require increasing  overall stack, which can't be done while app is running.

0 Kudos
Ines_F_
Beginner
4,234 Views

I apologize for answering that late and thank you for your comments ! it helped me a lot. thanks !

0 Kudos
Reply