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

Memory usage

Zhanghong_T_
Novice
739 Views

Hi all,

I found a strange thing when I debugging the following code:

implicit none
integer::i,j,n
real*8,allocatable::a(:)
n=100000000
allocate(a(n))

1 &
do j=1,n
a(j)=0.d0
enddo

2 &
end

I set two breakpoints at the label 1 and 2 respectively. When the program runs to the label 1, the memory usage is (observed from Windows Task Manager):

Mem Usage: 2,488k VM Size: 783,516k

However, after it runs to the label 2, the memory usage changes greatly:

Mem Usage: 785,264k VM Size: 783,516k

Could anyone explain the changes of memory usage?

Thanks,

Zhanghong Tang

0 Kudos
3 Replies
Steven_L_Intel1
Employee
739 Views
"Mem Usage" here is most likely the number of physical pages of RAM in your process working set. Until you actually touched the elements of the allocated array, they existed only as reservations in a page table and not RAM pages assigned to your process.
0 Kudos
Zhanghong_T_
Novice
739 Views

Oh, that's a new concept for me. Then how to 'measure' the memory usage of a program? Based on the allocated space or the space which is actually touched? Is there any program to 'measure' the memory usage of a subroutine?

Thanks,

Zhanghong Tang

0 Kudos
Steven_L_Intel1
Employee
739 Views
It's hard to measure the usage of a subroutine - especialy as once memory is allocated, your virtual address space size doesn't shrink. I suppose it depends on what it is you want the information for.

Windows will tell you the total virtual address space assigned to your process, the maximum available and how many physical memory pages you are using. Depending on why you care, you may want any or all of these.
0 Kudos
Reply