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

Size of huge allocatable array

oleglebedev
New Contributor I
421 Views
Hello!
I would like to find out a size of memory which is assigned by a huge allocatable array. Every ellements of my array has a derived type like the following:
type :: my_type
double precision, dimension(:,:), allocatable :: z
end typemy_type
...
In the code I allocate
allocate( array(1:Nmax) )
do i = 1, Nmax
allocate( array(i)%z(1:arrayMax, 1:3) )
end do
Nmax and arrayMax are approx. equal to 17000 and 10000 respectivly. And so I warry about work station. How much Mb will I use performing this?Is there any intrinsict function estimating it?
Oleg.
0 Kudos
7 Replies
Steven_L_Intel1
Employee
421 Views
Each "z" element will have 30000 elements of 8-byte reals, or 240,000 bytes. In addition, there is the array descriptor for each z which will be something like 48 bytes. So, 17000 * 240,048 = about 4GB. You will need a 64-bit OS to allocate this much data.
0 Kudos
oleglebedev
New Contributor I
421 Views
May I attach the "z" elements from 1 up to Nmax during the calculation? resizing//increasing the allocatable array in order to save the memory.
I am performing my calculation in 64-bit OS.
0 Kudos
Steven_L_Intel1
Employee
421 Views
I am not sure I understand the question. You don't have to allocate all the z elements at once. However, there is no real support for "resizing" an allocatable array. You can do it with a three-step process:

1. Allocate a new array to the desired size
2. Copy the elements from old to new
3. Use MOVE_ALLOC to "transfer" the allocation of the new array back to the old.

Note that for a while you will have twice the memory allocated.
0 Kudos
oleglebedev
New Contributor I
421 Views
Thank you! I thought this way, too.

You note is important. Finaly, I will use more than 4 Gb (from 4 to 8 Gb after the half point of a calculation).
0 Kudos
oleglebedev
New Contributor I
421 Views
In case of using selected_real_kind will the size of element change from 8-byte?
0 Kudos
tom_p
Beginner
421 Views
That depends on the parameters you supply to selected_real_kind. If precision and exponent range are small enough for a IEEE 754 single precision real, you will only need 4 bytes per real.
0 Kudos
mriedman
Novice
421 Views
Be aware of the distinction between virtual and physical memory. When a chunk of memory is newly allocated that does not mean that it is instantlymapped to physical memory. That will only happen when you start writing toit.
So if your array is sparse, e.g. with large unused and uninitialized sections, then it will use less physical memory than you expect. With other words: It is legal to allocate more thanthe physical memory knowing that not all of it will be used. In that case you just have to avoid initializing the whole thing. In that case your workstation will freeze.
0 Kudos
Reply