I'm having issues with the size of the matrices I declare on FORTRAN. First of all, I can't declare matrices that are too large. Second, even if the matrices are not too large, the code still crushes when I pass these matrices to other functions.
I'm attaching two pieces of code. The "MAIN.f90" is the main program where objects are declared. The "Toolbox.f90" is a module that contains a function "kron_vec" which I eventually call from MAIN.
In MAIN I declared three matrices: PHIa, PHIx and PHI. PHIa is of size NS x Na, PHIx is of size NS x Nx, and PHI is of size NS x NS; where Na and Nx are integers to be declared and NS = Na*Nx. The matrices PHIa and PHIx are declared as some random numbers (lines 48 and 49), and PHI is the output of the function kron_vec(PHIa,PHIx) (line 51)
If I use Na = 200 and Nx = 50, the code copiles and can declare the matrices PHIa, PHIx, and PHI. However, when use kron_vec(PHIa,PHIx), I get the following error:
forrtl: severe (170): Program Exception - stack overflow
Image PC Routine Line Source
SIZE_TEST.exe 00CDEC57 Unknown Unknown Unknown
SIZE_TEST.exe 00D3F8F3 Unknown Unknown Unknown
SIZE_TEST.exe 00CDEE59 Unknown Unknown Unknown
SIZE_TEST.exe 00CDED1F Unknown Unknown Unknown
kernel32.dll 760C336A Unknown Unknown Unknown
ntdll.dll 775A9902 Unknown Unknown Unknown
ntdll.dll 775A98D5 Unknown Unknown Unknown
If I use Na = 300 and Nx = 100, I cannot even compile the project ...
So it seems that there is a problem itself with big matrices. I understand the case of Na = 300 and Nx = 100 implies a matrix of size 30,000 , but I think this should be manageable. At the same time, there is an issue with passing even smaller matrices to the function. I don't know why the code crush when moving these matrices to the function.
I'm using Parallel Studio XE 2011. I already added the MKL library to the Properties < Fortran < Libraries < Use Intel Math Kernel Library = Parallel (/Qmkl:parallel)
Thanks in advanced for your help!
It's not a limit on array size, but that by default the compiler uses the stack to create temporary copies of arrays when required by language semantics. The default stack size on Windows is a tiny 1MB which makes it easy to overflow. My recommended solution is to set the project property Fortran > Optimization > Heap Arrays to 0 - this will tell the compiler to use dynamic allocation for temporaries and not be subject to stack size limits. On the command line this is /heap-arrays.
Another solution is to increase the size of the stack with the property Linker > System > Stack Reserve Size. Don't make this arbitrarily large as that can create other problems. The stack size can't be set to more than 1GB.
I'm not seeing the same error you are, but I am using a much newer compiler.
Your array PHI is REAL(8) and dimensioned 30000*30000. That's 7,200,000,000 bytes, many times larger than Windows allows for a static array. Version 17.0.1 tells me:
Variable MAIN$PHI too large for NTCOFF. Bigger than 2GB. Use heap instead
If you build for x64 and make this array ALLOCATABLE, you could, theoretically, allocate an array that size, and you would absolutely need to use HeapArrays.
You may want to reconsider your algorithm.