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

how to set the stack size?

史_建鑫
Beginner
2,841 Views

Consider the code below

[fortran]

program Console2

    implicit none

    integer :: a(10000,10000)   # line1
    
    a=1
    print *, 'Hello World'

end program Console2

[/fortran]

My compile enviroment is VS2010+intel Parallel Studio XE 2011+Win7.

the code line1 defined a variable “a" with size 4*10000*10000=400MB, and the program pass the compile and run. I remember i got an error "stack oveflow" when i define a big array before. Why it didn't pop the error this time?

0 Kudos
5 Replies
TimP
Honored Contributor III
2,841 Views

As your results don't depend on the a array, the compile could have deleted it.

0 Kudos
Steven_L_Intel1
Employee
2,841 Views
To set the stack size, set the Linker property System > Stack Reserve. An alternative is to enable Heap Arrays (Fortran > Optimization > Heap Arrays - set to 0.)
0 Kudos
史_建鑫
Beginner
2,841 Views

Thank you for all your help.

1. TimP, if i write the array to the file, the program still goes well.

[fortran]

program Console2

    implicit none

    integer :: a(10000,10000)
    
    a=1
    Open( 12 , File = 'TestBinW.Bin', Access = 'SEQUENTIAL' , Form = 'Unformatted')
    Write( 12) a
    Close( 12 )
    print *, 'Hello World'

end program Console2

[/fortran]

2. Steve, I cannot find the help page of the "heap:reserve" and "stack:reserve", set the two properties to 0 mean default? if so, what the default size of the heap and stack.

3. I want to know the correct way to use a large array. I think i should use "new" operator, not just define it. am i right?

thank you!

0 Kudos
史_建鑫
Beginner
2,841 Views

Thank you for all your help.

1. TimP, if i write the variable to file, i can also run properly. So, I don't think the compiler delete it.

2.Steve, I find the two properties, but i cannot find the corresponding help page in the help file. i want to know the default number 0 means what.

3.what is the correct way to use a large array? should i use the "new" operator?

Thank you again.

0 Kudos
Steven_L_Intel1
Employee
2,841 Views

A 0 for Heap Arrays means to put all array temporaries on the heap. A blank value means put them on the stack.  While one can put in an integer value other than 0, that doesn't actually do anything useful so just use 0.

In Fortran, there is no "new operator". There is ALLOCATE that is used with arrays that have the ALLOCATABLE attribute. For example:

[fortran]
integer, allocatable :: a(:,:)
allocate (a(10000,10000))
...
[/fortran]

0 Kudos
Reply