My workflow involves importing Fortran subroutines into R to work with very large vectors and matrices. My gfortran compiling options are as follows: gfortran -fimplicit-none -ffree-line-length-0 -fdefault-integer-8 -fdefault-real-8 -fpic -shared fortran_file.f95 -o fortran_file.so
I find these options very convenient to use. I would like to ask whether these options can bring unexpected errors. I am not concerned about portability since I only distribute the so files and other R users just call them from R.
For āreleaseā use, I usually only use -Ofast -mach=native
If anyone have better flags for āreleaseā mode, please advise too.
For ādebugā use, possibly could just use whatever flags you want.
I usally use intel fortran first, then use gfortran to compile and to fix some possible issues which intel fortran is happy but gfortran is unhappy about.
-Ofast turns on -ffinite-math-only among (many) others. -ffinite-math-only orders the compiler to assume that all the numbers involved in the calculations are finite ā no Inf, no NaN. This is fine if you have only a few lines of code, and they deal with only numerically easy (well-conditioned) problems. Otherwise, Inf and NaN will likely pop out at places that we may not be able to imagine until we see them.
If -Ofast is intended, then it may be a good idea to put at least -fnofinite-math-only afterwards.
I understand that Fortran highly values backward compatibility. How about gfortran? Is it possible that some of these gfortran options be deprecated in the future?
I also avoid the gfortran option -freal-M-real-N (where M = 4 or 8, N = 4, 8, 10 or 16, but N /= M) because it doesnāt do everything I wanted it to. Selected_real_kind ignored these options and so did literal constants with _kind, e.g. 1.0_4, when I last tried them a few years ago. I donāt know whether more recent gfortran versions have fixed those problems.