代码之家  ›  专栏  ›  技术社区  ›  sponce

Fortran中的大VIRT内存

  •  0
  • sponce  · 技术社区  · 7 年前

    我有一个很大的Fortran/MPI代码,在运行时会使用大量的VIRT内存(约20G),尽管实际使用的内存(500 mb)相当有限。

    但是,这不起作用,因为睡眠调用将内存使用率设置为0。有没有办法在保持当前内存使用率的同时冻结代码?

    PS:我试过VALGRIND,但是代码太大了,Valgrinde从来没有完成过。VALGRIND是否有一种“易于”使用的替代品?

    山姆

    1 回复  |  直到 7 年前
        1
  •  1
  •   sponce    7 年前

    解决这个问题的一个方法是在Fortran 90中修改(以获取VIRT内存)子例程的轨迹内存使用情况

    subroutine system_mem_usage(valueRSS)
    use ifport !if on intel compiler
    implicit none
    integer, intent(out) :: valueRSS
    
    character(len=200):: filename=' '
    character(len=80) :: line
    character(len=8)  :: pid_char=' '
    integer :: pid
    logical :: ifxst
    
    valueRSS=-1    ! return negative number if not found
    
    !--- get process ID
    
    pid=getpid()
    write(pid_char,'(I8)') pid
    filename='/proc/'//trim(adjustl(pid_char))//'/status'
    
    !--- read system file
    
    inquire (file=filename,exist=ifxst)
    if (.not.ifxst) then
      write (*,*) 'system file does not exist'
      return
    endif
    
    open(unit=100, file=filename, action='read')
    do
      read (100,'(a)',end=120) line
      if (line(1:7).eq.'VmSize:') then
         read (line(8:),*) valueRSS
         exit
      endif
    enddo
    120 continue
    close(100)
    
    return
    end subroutine system_mem_usage