Fortran 中的大型 VIRT 内存
Large VIRT memory in Fortran
我有一个很大的 Fortran/MPI 代码,当 运行 使用大量 VIRT 内存(~20G)时,尽管实际使用的内存(500 mb)相当适中。
我如何分析代码以了解哪个部分产生了这么大的 VIRT 内存?
在这个阶段,我什至乐于使用蛮力方法。
我尝试的是在代码中放置睡眠语句并通过 "top" 记录内存使用情况,以尝试通过二分法查明大分配的位置。
但是,这不起作用,因为睡眠调用将内存使用量设置为 0。有没有办法在保持当前内存使用量的同时冻结代码?
PS:我已经尝试过 VALGRIND,但是代码太大,VALGRIND 从未完成。是否有 "easy" 的 VALGRIND 替代品可供使用?
谢谢,
山姆
此问题的解决方案是修改(以获取 VIRT 内存)子例程,该子例程来自 Fortran 90 中的跟踪内存使用情况
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
我有一个很大的 Fortran/MPI 代码,当 运行 使用大量 VIRT 内存(~20G)时,尽管实际使用的内存(500 mb)相当适中。
我如何分析代码以了解哪个部分产生了这么大的 VIRT 内存?
在这个阶段,我什至乐于使用蛮力方法。 我尝试的是在代码中放置睡眠语句并通过 "top" 记录内存使用情况,以尝试通过二分法查明大分配的位置。 但是,这不起作用,因为睡眠调用将内存使用量设置为 0。有没有办法在保持当前内存使用量的同时冻结代码?
PS:我已经尝试过 VALGRIND,但是代码太大,VALGRIND 从未完成。是否有 "easy" 的 VALGRIND 替代品可供使用?
谢谢,
山姆
此问题的解决方案是修改(以获取 VIRT 内存)子例程,该子例程来自 Fortran 90 中的跟踪内存使用情况
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