【问题标题】:Large VIRT memory in FortranFortran 中的大型 VIRT 内存
【发布时间】:2017-06-30 18:07:50
【问题描述】:
我有一个大型 Fortran/MPI 代码,运行时使用大量 VIRT 内存 (~20G),尽管实际使用的内存 (500 mb) 非常少。
如何分析代码以了解哪个部分产生了如此巨大的 VIRT 内存?
在这个阶段,我什至很乐意使用蛮力方法。
我尝试的是在代码中放入 sleep 语句,并通过“top”记录内存使用情况,以尝试通过二等分来确定大分配的位置。
但是,这不起作用,因为 sleep 调用会将内存使用量设为 0。有没有办法在保持当前内存使用量的同时冻结代码?
PS:我尝试过 VALGRIND,但代码太大,VALGRIND 从未完成。是否有“易于”使用的 VALGRIND 替代品?
谢谢,
山姆
【问题讨论】:
标签:
memory
memory-leaks
fortran
virtual-memory
【解决方案1】:
对此的解决方案是从 Fortran 90 中的 Track memory usage 中修改(以获取 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