USE
-statement should have an ONLY:
-clause, which lists the imported symbols [-Wuse-without-only].OMP PARALLEL
-region should declare default(none)
.SAVE
attribute.IMPLICIT NONE
[-fimplicit-none].FORALL
constructs. Why? OMP THREADPRIVATE
variables.STAT
from a DEALLOCATE
, the Fortran runtime takes care.RANDOM_NUMBER()
, it's not consistent across different compilers.There are two measure of defense against spaghetti code:
PRIVATE
and only few public symbols.Always prefer built-in (intrinsic) functions instead of hand-coded routines since they usually include extra numerical checks to avoid intermediate under- or overflow while still performing optimally. Examples:
NORM2(x)
instead of SQRT(x(1)**2 + x(2)**2 + x(3)**2)
DOT_PRODUCT(x, x)
instead of x(1)**2 + x(2)**2 + x(3)**2
DOT_PRODUCT(x, y)
instead of x(1)*y(1) + x(2)*y(2) + x(3)*y(3)
For many common operations there exist wrappers in CP2K to prevent usage errors and to allow for central redirections, i.e. avoid to use direct calls to external libraries in CP2K
cp_files.F
instead of calling OPEN
and CLOSE
directly.fm
-package instead of calling BLAS or Scalapack directly.message_passing.F
instead of calling MPI directly.fft_lib.F
instead of calling FFT (any library) directly.machine.F
to access architecture depended things like e.g. the working directory.UNIT=*
in WRITE
or PRINT
statements. Instead request a unit from the logger: iw=cp_logger_get_default_unit_nr()
and write only if you actually received a unit: IF(iw>0) WRITE (UNIT=iw, ,,,)
.STOP
statement.IF(debug_this_module)
-block, with a parameter set to .FALSE.
. This way the code will stay up-to-date and easily callable..F
file should contain either a PROGRAM
or a single MODULE
, whose name matches the filename.INSTALL
-file and added to the cp2k_flags function (cp2k_info.F).make -j pretty
.FUNCTION
and SUBROUTINE
should be preceded by a valid doxygen block.\brief
, \param
(for each parameter), \retval
(for functions)\note
, \par
, \date
, \author
make doxify
to format your doxygen comments, or generate templates where none exist