With the caveat that short test programs (see below) are notoriously easy to read
too much into, it empirically looks likely that using gfortran on Linux
using KIND=1 will not degrade performance for logical operations.
Since you indicated you are using Linux, a cheap way to get your
memory high water mark from Fortran in a batch mode is to read it from
/proc/self/status if you want to report it from your program.
I generally use a call to the C routine getrusage instead, but that
requires using the ISO_C_BINDING and a procedure longer than the
example code!
There are all kinds of goodies in /proc; so you might want to look at
the link referenced in the mstat() procedure below when you have some spare time
, which I added just
as an example.
I still feel top(1) is easy to use and lets you watch things dynamically, but if
you just want a high water mark and are only using Linux, just look
for the line with HWM in it in /proc/self/status from your program
.
I’m basing that KIND=1 does not change things from gfortran much on a simple program so again, as mentioned
by several posters earlier try it with your own program. Note that
KIND=4 appears to be faster with optimized ifort, for example.
#!/bin/bash
(
exec 2>&1
set -x
ulimit -a
grep -i total /proc/meminfo
time fpm run --profile debug --compiler gfortran --flag -DLKIND=1
time fpm run --profile debug --compiler ifort --flag -DLKIND=1
time fpm run --profile debug --compiler nvfortran --flag -DLKIND=1
time fpm run --profile debug --compiler gfortran --flag -DLKIND=4
time fpm run --profile debug --compiler ifort --flag -DLKIND=4
time fpm run --profile debug --compiler nvfortran --flag -DLKIND=4
time fpm run --profile release --compiler gfortran --flag -DLKIND=1
time fpm run --profile release --compiler ifort --flag -DLKIND=1
time fpm run --profile release --compiler nvfortran --flag -DLKIND=1
time fpm run --profile release --compiler gfortran --flag -DLKIND=4
time fpm run --profile release --compiler ifort --flag -DLKIND=4
time fpm run --profile release --compiler nvfortran --flag -DLKIND=4
)|tee $0.log
exit
Summary of timings
DEBUG MODE
COMPILER KIND REAL_TIME
gfortran KIND=1 0m 8.047s
ifort KIND=1 0m 21.896s
nvfortran KIND=1 0m 18.945s
gfortran KIND=4 0m 8.686s
ifort KIND=4 0m 21.561s
nvfortran KIND=4 0m 19.711s
OPTIMIZED
COMPILER KIND REAL_TIME
gfortran KIND=1 0m 5.194s
ifort KIND=1 0m 4.687s
nvfortran KIND=1 0m 14.377s
gfortran KIND=4 0m 5.974s
ifort KIND=4 0m 3.416s
nvfortran KIND=4 0m 14.964s
Again, do not read too much into these numbers except that using KIND=1 with gfortran did not drastically slow things down (I have seen using a non-standard LOGICAL kind slow things down by a factor of 3, but it depends on the chip, the compiler, the compiler flags, …).
trivial test program
Look at the mstat() routine for a Linux-only easy way to get HWM from Fortran, otherwise not really anything to see here …
program testit
implicit none
logical(kind=LKIND),allocatable :: vals(:)
integer :: i, icount
real :: r
if(allocated(vals))deallocate(vals)
allocate(vals(450000000))
! do some things with a big logical array, doing odd things to
! reduce chance the compiler does not optimize everything away
do i=1,size(vals)
call random_number(r)
vals(i)=merge(.true.,.false.,r>0.5)
enddo
icount=0
do i=1,size(vals)
if(vals(i))icount=icount+1
enddo
write(*,*)icount,size(vals),storage_size(vals),storage_size(.true.)
call mstat()
contains
subroutine mstat()
! /proc rocks!
! reference: https://www.kernel.org/doc/html/latest/filesystems/proc.html
! assume on Linux and show /proc/self/status memory, especially High Water Mark
! also see system_getrusage()
integer :: lun, iostat
character(len=80) :: line
open(newunit=lun,file='/proc/self/status')
do
read(lun,'(a)',iostat=iostat)line
if(iostat.ne.0)exit
if(line(1:2).eq.'Vm')write(*,'(a)')trim(line)
enddo
! open(newunit=lun,file='/proc/self/limits')
end subroutine mstat
end program testit
urbanjs@venus:~/githhub/fun/lsize/
Regarding the bug stuff, if you do not expect your memory usage to increase while running, and the code seems to crash with the same wallclock time you do want to check on it periodically and see if the resident memory usage is increasing inexplicably over time. If it is, and should not be you might want to look at valgrind for a tool for finding memory leaks; although aside from eating up your memory that does not mean results are being affected if there is one.
Although I saw something really similar a long time ago where a code always crashed on Friday night, and was restarted just about every Monday morning (that ended up being because when everyone left on Friday they turned off the air conditioning and the node overheated). When someone asked me to look at it an I told them it was overheating and what the cause was they admitted that had been happening for two years; and that when they had paid for someone to come in and watch what was happening it never happened, so they were really frustrated (the guy coming in was turning on the air conditioner)! So I am not excluding overheating by any means, but typically that happens in far less than a week and (usually) is not so repeatable.