View previous topic :: View next topic |
Author |
Message |
mbly
Joined: 25 Jan 2013 Posts: 4
|
Posted: Mon Feb 25, 2013 10:04 pm Post subject: How to increase allocatable memory to allow for larger array |
|
|
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 |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Tue Feb 26, 2013 6:18 am Post subject: |
|
|
You should use ALLOCATE for these arrays.
Code: | ! 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 |
|
Back to top |
|
 |
mbly
Joined: 25 Jan 2013 Posts: 4
|
Posted: Tue Feb 26, 2013 7:56 pm Post subject: large arrays |
|
|
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 |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Tue Feb 26, 2013 9:17 pm Post subject: |
|
|
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 |
|
Back to top |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Wed Feb 27, 2013 11:30 pm Post subject: |
|
|
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. _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Thu Feb 28, 2013 4:12 am Post subject: |
|
|
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 |
|
Back to top |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Thu Feb 28, 2013 3:47 pm Post subject: Re: |
|
|
JohnCampbell wrote: |
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. _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
 |
|