Initializing Uninitialized Variables

We’ve recently gotten a code that failed during runtime because an uninitialized variable had a nonzero value. Does pgf90 have an option to automatically set uinitialized variables to zero, or to flag all occurences of uninitialized variables? I’ve been through the man page a few times and don’t seem to see that particular feature.

Hi Peter,

Ah yes, UMRs (uninitialized memory reads) the most evil of all bugs. There are a couple of things you can do. Add “-Msave” to the compilation line. This has the effect of setting the SAVE attribute to all local varaibles, which in turn initializes variables to zero. You can also set the environment variable “PGHPF_ZMEM” to “YES” which has the effect intializing all allocated memory to zero.

However, both of these are very heavy handed and can diminish performance. Ideally, you’d like to find and fix these bugs. For that, I’d recommend the open source utility Valgrind which is able to detect these types of errors. It’s not perfect and it has a harder time with Fortran code than it does C. However, I do use it myself and it has helped me quite a bit when chasing down UMR bugs.

Good luck,


Is there a way (a flag maybe) that aborts the compile if it encounters an uninitialized variable??


Unfortunately no.



Is there a flag similar to -Msave for a C compile??


Sorry, no.