Silverfrost Forums

Welcome to our forums

How to increase allocatable memory to allow for larger array

25 Feb 2013 9:04 #11613

MikeHi Is there any way to increase the allocatable memory, heap beyond 100 mb to allow for larger arrays? Currently , I can only do 2 arrays of size: (500000,200). Any suggestions? If so, can you walk a newbie through it. If not, any recommendations? thanks

26 Feb 2013 5:18 #11616

You should use ALLOCATE for these arrays.

! declare as
integer*4, allocatable, dimension(:,:) :: new_array
integer*4 al_stat
...
!  allocate the array
      allocate ( new_array(500000,200), stat=al_stat)
      if (al_stat /= 0) then
        write (*,*) 'error allocating new_array, stat =',al_stat
        stop
      end
....
! you can now use the array
    new_array = 0

You should read up on the use of ALLOCATE.

John

26 Feb 2013 6:56 #11624

Thanks for the reply.

Isn't ALLOCATE used mainly to help in the definition of a dynamic array?

Won't I still be limited by the 100mb heap or stack?

thanks Mike

26 Feb 2013 8:17 #11628

Allocate uses the malloc memory routines and not the heap or stack. Local variables and automatic arrays use the stack. After many years of programming, i still do not know what the 'heap' is or how big it needs to be. With FTN95 on a 64-bit OS, you can allocate an array up to nearly 2gb in size. Give it a try and you will find the flexibility very effective, especially if you declare these arrays in a module, so that they are globally available.

John

27 Feb 2013 10:30 #11636

The 'heap' is where malloc (in C) and allocate (in Fortran) allocates memory.

Strictly speaking the heap doesn't have to be used in Fortran for this, but it usually is.

I don't think you can change the maximum size of the 'normal' heap with Silverfrost's FTN95. You can set the maximum size of the 'check heap' used in check mode using an environment variable FTN95CHECKHEAP.

There's some information in the documentation.

28 Feb 2013 3:12 #11637

David,

I am able to allocate arrays anywhere in memory, from about 4mb to 4gb, where the space is available. I don't think this 'heap' really exists as a location in memory. When using ALLOCATE, there must be some memory management table to indicate what is being used. Perhaps the memory table is in the 'Heap'. Help on 'Storage management routines' does describe a 100mb area above the stack, so perhaps this is just the top of the stack. I have had more experience with the 'stack', which is used for local and automatic arrays. This experience has taught me not to use it, except for variables or very small arrays. I place all large (not small) arrays in COMMON, modules or as allocatable arrays, with my preference now being for allocatable arrays in modules.

John

28 Feb 2013 2:47 #11640

Quoted from JohnCampbell

Perhaps the memory table is in the 'Heap'.

Yes. The 'heap' is an area above the stack. Have a look at the figure on this page.

http://www.maxi-pedia.com/what+is+heap+and+stack

There are tools you can use to 'see' the data on the heap if you need to do this, e.g.

http://www.nirsoft.net/utils/heap_memory_view.html

With the heap you can create and remove data structures anywhere within it. Contrast this with the stack where only the top item can be manipulated.

Please login to reply.