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

Memory / Size used by program

klaus_knebel
Beginner
905 Views
Is there a possibility to find out how much memory the fortran program uses whne the program is running.
I do not mean the size of the (.exe) program
I mean the size of memony used when the program is running

Klaus
0 Kudos
5 Replies
mecej4
Honored Contributor III
905 Views
A basic measure is the image size, and that can be obtained at the command line:

C:\ > dumpbin /headers .exe

You can watch the time-dependent memory consumption by locating your application processes in the Task Manager. There are other tools for "process monitoring".

As a program allocates variables on the heap, loads DLLs, and chains calls on the stack, naturally memory consumption is dynamic.
0 Kudos
klaus_knebel
Beginner
905 Views
Ok thanks
I was hoping, that there is a possibility within the program
Some kind of a compiler option or fortran call or.....

thanks
Klaus
0 Kudos
Les_Neilson
Valued Contributor II
905 Views

You could try looking at GlobalMemoryStatusEX
for example something like :

[bash]module memory_System
   implicit none
   private

   ! Parameters

   ! Used to return data in Mb (ie divide by (1024 * 1024))
   real*8, parameter :: m_dbDivide = 1024 * 1024;

   ! Variables

   integer*4, public :: m_dwMemLength 
   integer*4, public :: m_dwMemLoad 
   real*8,    public :: m_dbMemTotalPhys 
   real*8,    public :: m_dbMemAvailPhys 
   real*8,    public :: m_dbMemTotalPageFile 
   real*8,    public :: m_dbMemAvailPageFile 
   real*8,    public :: m_dbMemTotalVirtual 
   real*8,    public :: m_dbMemAvailVirtual 

   ! Subroutines

   public:: GetMemoryStats

   contains

!------------------------------------------------------------------
! Subroutines

   subroutine GetMemoryStats()
   use kernel32
   IMPLICIT NONE

   type(T_MEMORYSTATUSEX) lpMstMemStat

   lpMstMemStat.dwLength = sizeof(lpMstMemStat)

   if (GlobalMemoryStatusEx(lpMstMemStat)==0) then
      !error
      m_dwMemLength        =  0
      m_dwMemLoad          =  0
      m_dbMemTotalPhys     = 0.0
      m_dbMemAvailPhys     = 0.0
      m_dbMemTotalPageFile = 0.0
      m_dbMemAvailPageFile = 0.0
      m_dbMemTotalVirtual  = 0.0
      m_dbMemAvailVirtual  = 0.0
   else
      m_dwMemLength        = lpMstMemStat.dwLength
      m_dwMemLoad          = lpMstMemStat.dwMemoryLoad
      m_dbMemTotalPhys     = fnUlltoR8(lpMstMemStat.ullTotalPhys)     / m_dbDivide
      m_dbMemAvailPhys     = fnUlltoR8(lpMstMemStat.ullAvailPhys)     / m_dbDivide
      m_dbMemTotalPageFile = fnUlltoR8(lpMstMemStat.ullTotalPageFile) / m_dbDivide
      m_dbMemAvailPageFile = fnUlltoR8(lpMstMemStat.ullAvailPageFile) / m_dbDivide
      m_dbMemTotalVirtual  = fnUlltoR8(lpMstMemStat.ullTotalVirtual)  / m_dbDivide
      m_dbMemAvailVirtual  = fnUlltoR8(lpMstMemStat.ullAvailVirtual)  / m_dbDivide
   end if


   return

   end subroutine GetMemoryStats

real*8 function fnUlltoR8(nIn) use ifwinty implicit none type(T_LARGE_INTEGERX), intent(in) :: nIn integer*8 nI8 integer*4 nBits integer*8 nLow, nHigh !----------------------------------------------------------------------| nbits = 0 !do low if (nIn.LowPart < 0) then nBits = bit_size(nIn.LowPart) nLow = (int8(nIn.LowPart) + 2_8**nBits) else nLow = nIn.LowPart endif !do high if (nIn.HighPart < 0) then nBits = bit_size(nIn.HighPart) nHigh = (int8(nIn.HighPart) + 2_8**nBits) else nHigh = nIn.HighPart endif !combine the data nHigh=ISHFT(nHigh,32_8) nI8=nHigh+nLow fnUlltoR8=nI8 end function fnUlltoR8 [/bash]

end module memory_System

Hope this helps

forgot the function to return the number
Les
0 Kudos
Les_Neilson
Valued Contributor II
905 Views
Sorry I'm not sure how the
 and 
stuff got there. I was trying to add in a function I had missed out in my cut and paste. Just ignore those lines.

Les
0 Kudos
jimdempseyatthecove
Honored Contributor III
905 Views
There are multiple issues at play here (to find out how much memory the fortran program uses whne the program is running).

There is the issue of the memory requirements for the code plus static data, plus stack data, plus allocated memory.

Then there is the issue of memory footprint which includes the above plus voids (previously allocated but now returned memory).

The memory foot print is effectively the Virtual Memory requirements of the application. (think of this as "squatting" memory).

The former requirement (sans voids) would be your "working" memory.

Les's suggestion as well as using other heap walk (diagnostic debug routines) can be used to determine heap size and allocations.

It is not unusual for some applications to experience Virtual Memory creap while having a relatively steady working memory requirement (consistantly fragmenting the heap).

Jim Dempsey

0 Kudos
Reply