User Tools

Site Tools


dev:codingconventions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
dev:codingconventions [2018/12/19 11:37]
tmueller raise Fortran standard to 2008 since we are already using features from there
dev:codingconventions [2018/12/21 08:41] (current)
tmueller [Use existing infrastructure]
Line 3: Line 3:
 ===== Stick to the standard ===== ===== Stick to the standard =====
  
-  * Code enabled by default should be standard ​Fortran2008 ​[-std=f2008] +  * Code enabled by default should be standard ​Fortran 2008 [-std=f2008] 
-  * OpenMP code should follow ​the version 3.X of the standard +  * OpenMP code should follow version 3.X of the standard 
-  * MPI should should follow ​the version 3 of the standard +  * MPI should should follow version 3 of the standard 
-  * Extended functionality should match [[wp>​POSIX]] ​[[wp>​Linux_Standard_Base|LSB]].+  * Extended functionality should match [[wp>​POSIX]] ​and [[wp>​Linux_Standard_Base|LSB]].
  
 ===== Write explicit code ===== ===== Write explicit code =====
Line 39: Line 39:
  
 ===== Use existing infrastructure ===== ===== Use existing infrastructure =====
 +
 +Always prefer [[https://​gcc.gnu.org/​onlinedocs/​gcc-8.2.0/​gfortran/​Intrinsic-Procedures.html|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 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
 +
   * Use the routines from ''​cp_files.F''​ instead of calling ''​OPEN''​ and ''​CLOSE''​ directly.   * Use the routines from ''​cp_files.F''​ instead of calling ''​OPEN''​ and ''​CLOSE''​ directly.
   * Use the routines from the full-matrix ''​fm''​-package instead of calling BLAS or Scalapack directly.   * Use the routines from the full-matrix ''​fm''​-package instead of calling BLAS or Scalapack directly.
dev/codingconventions.1545219425.txt.gz · Last modified: 2018/12/19 11:37 by tmueller