Skip to content

Best practices

Mauricio Esguerra edited this page May 14, 2015 · 3 revisions

Best practices

The program should work as double precision (or custom precision). There is no place to give a choice to the compiler. When you write code you must know what precision it should be, that is why we need to use the following rules:

  • no default declarations of real. Use parameter for:

    • single precision real(kind=singleprecision)
    • double/custom precision real(kind=prec)
  • function real should contain precision

    • single precision real(variable/formula, kind=singleprecision)
    • double/custom precision real(variable/formula, kind=prec)
  • numerical values should contain information about precision

    • single precision e.g. 1.0_singleprecision 0.0_singleprecision 1.e-12_singleprecision
    • double/custom precision e.g. 1.0_prec 0.0_prec 1.e-12_prec
  • if you need use different precision than used in program add it in size.f90 file and use it as previous examples

  • math functions sin(), cos(), asin() etc. are in default precision. Use compiler flags for single or double precision as default

    • gfortran -fdefault-real-8
  • ifort -r8
  • pgf90 -r8
  • in md.f90 are defined one and zero use them in that file:
    • real(kind=prec) :: one = 1.0_prec
    • real(kind=prec) :: zero = 0.0_prec

Every time you don't use best practices you are changing the resulting values for default precision. We do not want this.

Clone this wiki locally