To find leaks and uninitialized values, I normally use Valgrind. But right now Valgrind does not work on on MacOS Big Sur or newer. My solution has been to boot up a Ubuntu VirtualBox occasionally, then build my code on there, then run with valgrind. This is annoying, and slow, and takes up too much ram on my little laptop.
I’m in search of either
Lightweight fast virtual linux terminal, that takes little ram, which I can build and run my code on with valgrind
Memory error detector that can work on MacOS that is as good as Valgrind.
The -ffpe-trap=invalid,zero,overflow throws an exception if a nan is ever read from a variable (or perhaps only when it is assigned somewhere, which is almost the same thing), and -finit-real=snan initializes all real variables to nan. So this achieves the same thing, and with -fbacktrace you get a stacktrace to see where it happened.
Unfortunately it doesn’t work for integers, but there at least I initialize them to -finit-integer=-99999999, so the -fcheck=all triggers if they are used as array indices. And if they are used in some computation, I will usually get an obviously wrong answer, so it’s easier to spot.
@nicholaswogan , a lesson some teams have learned is to use Linux and/or Windows to debug memory errors in code and then instantiate the macOS version based on portable code. This is only going by the situations in the commercial space such as with Intel oneAPI where their tool Intel Inspector for memory leaks is available on Linux and Windows but not for macOS (likely the ValGrind issue lurking behind the scenes).
If you’re feeling brave, you can consider alphaDr Memory.
Re: uninitialized variables, you can also try with Intel oneAPI the run-time option -check uninit for uninitialized variables e.g.,
print *, x
end
C:\Temp>ifort /standard-semantics /check:uninit a.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.3.0 Build 20210609_000000
Copyright (C) 1985-2021 Intel Corporation. All rights reserved.
Microsoft (R) Incremental Linker Version 14.29.30038.1
Copyright (C) Microsoft Corporation. All rights reserved.
-out:a.exe
-subsystem:console
a.obj
C:\Temp>a.exe
forrtl: severe (194): Run-Time Check Failure. The variable '_UNNAMED_MAIN$$$X' is being used in 'C:\Temp\a.f90(1,4)' without being defined
Image PC Routine Line Source
a.exe 00007FF7DD9D5609 Unknown Unknown Unknown
a.exe 00007FF7DD9D104C Unknown Unknown Unknown
a.exe 00007FF7DDA20D7E Unknown Unknown Unknown
a.exe 00007FF7DDA21100 Unknown Unknown Unknown
KERNEL32.DLL 00007FFB1BBE7034 Unknown Unknown Unknown
ntdll.dll 00007FFB1D7C2651 Unknown Unknown Unknown