Memory 按GNU时间(1)测量的Fortran程序意外高峰值内存消耗
我试图测量我正在进行的一个(MPI)Fortran项目的内存消耗。 我使用Memory 按GNU时间(1)测量的Fortran程序意外高峰值内存消耗,memory,memory-management,time,fortran,gnu,Memory,Memory Management,Time,Fortran,Gnu,我试图测量我正在进行的一个(MPI)Fortran项目的内存消耗。 我使用/usr/bin/time-v测量GNU时间(1)的内存消耗,它给出了最大驻留集大小(以KB为单位)。 因为我看到一些较旧版本的time在内存测量方面有问题,我想确保它工作正常,所以我编写了以下小程序来测试它: program timingcheck implicit none integer :: i, s, Mb,arrlen integer,dimension(:), allocatable :: me
/usr/bin/time-v
测量GNU时间(1)的内存消耗,它给出了最大驻留集大小(以KB为单位)。
因为我看到一些较旧版本的time
在内存测量方面有问题,我想确保它工作正常,所以我编写了以下小程序来测试它:
program timingcheck
implicit none
integer :: i, s, Mb,arrlen
integer,dimension(:), allocatable :: memarr
i = 1
s = sizeof(i) !number of bytes integer i occupies
Mb = 1024*1024
!Allocate array of size 100 Mb
arrlen = 100 * Mb / s
allocate(memarr(1:arrlen))
memarr = 1
call sleep(3)
deallocate(memarr)
end program timingcheck
到目前为止,一切顺利。我用gfortran编译程序,没有任何特殊标志。通过运行/usr/bin/time-v./timingcheck.out
我得到:
Command being timed: "./timingcheck.out"
User time (seconds): 0.02
System time (seconds): 0.00
Percent of CPU this job got: 1%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:03.03
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 104144
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 655
Voluntary context switches: 2
Involuntary context switches: 3
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
所以/usr/bin/time
给了我最大的内存消耗量为104144 kb,也就是101.7 Mb
问题是:1.7 Mb的额外内存使用从何而来?我看到了多种可能性:
- 我在程序中犯了一个我不知道的错误
- Fortran存储数组的方式需要一些额外的内存,我不知道
- 这是因为
的内存测量不精确/usr/bin/time
ldd计时签出
给出:
linux-vdso.so.1 => (0x00007ffde1b53000)
libgfortran.so.3 => /usr/lib/x86_64-linux-gnu/libgfortran.so.3 (0x00007f421485d000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4214494000)
libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007f4214254000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4213f4b000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f4213d35000)
/lib64/ld-linux-x86-64.so.2 (0x000055c3d15ec000)
编辑2:我已经对不同的阵列大小进行了测量。结果如下:
Intended array size: Measured Peak Memory Usage:
10 Mb 12.07 Mb
50 Mb 51.98 Mb
100 Mb 101.83 Mb
200 Mb 201.87 Mb
500 Mb 502.03 Mb
有趣的是,每次我运行测量时,峰值内存消耗似乎都会有一点变化。这背后的原因可能是什么 说真的,您是否担心1.7MB?这没什么,它可以用于编译器簿记所需的许多内部变量中的任何一个。加上启动代码。
ldd timingcheck.out
报告是什么?@VladimirF:我并不真的关心,不。对于一个做得相对较少的程序来说,这似乎有点高,我无法解释。更好地理解事物是如何运作的很少有坏处:)更好地理解事物是如何运作的很少有坏处。因此,找出同一个程序的内存消耗,比如说,一个10MB数组,一个50MB数组,…这看起来好像你正在使用内存分配给\u大数组+一些大约固定的\u开销,这在我看来是完全正常的。如果您研究操作系统的内存分配策略和方法,您可能会发现它是如何做到这一点的,以及为什么在不同的运行中可能会有一些不同。