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 revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
dev:codingconventions [2018/12/19 12:19] – [Use existing infrastructure] tmuellerdev:codingconventions [2020/05/05 07:51] oschuett
Line 3: Line 3:
 ===== Stick to the standard ===== ===== Stick to the standard =====
  
-  * Code enabled by default should be standard Fortran 2008 [-std=f2008]+  * Code enabled by default should be standard Fortran 2008 [-std=f2008] and C99 [-std=c99]
   * OpenMP code should follow version 3.X of the standard   * OpenMP code should follow version 3.X of the standard
   * MPI should should follow version 3 of the standard   * MPI should should follow version 3 of the standard
Line 22: Line 22:
 ===== Don't use poorly designed language features ===== ===== Don't use poorly designed language features =====
   * Do not use the ''GOTO''-statement. See also [[http://xkcd.com/292/]] and [[doi>10.1145/362929.362947]]   * Do not use the ''GOTO''-statement. See also [[http://xkcd.com/292/]] and [[doi>10.1145/362929.362947]]
-  * Do not use left-hand-side (lhs) reallocations of allocatables [-Wrealloc-lhs-all]. [[http://www.tddft.org/pipermail/octopus-devel/2012-February/005510.html | Why? ]] +  * Do not use left-hand-side (lhs) reallocations of allocatables [-Wrealloc-lhs]. [[https://github.com/cp2k/cp2k/issues/726 | Why? ]] 
   * Do not use ''FORALL'' constructs. [[https://gcc.gnu.org/ml/fortran/2012-04/msg00025.html | Why? ]]   * Do not use ''FORALL'' constructs. [[https://gcc.gnu.org/ml/fortran/2012-04/msg00025.html | Why? ]]
   * Do not use ''OMP THREADPRIVATE'' variables.   * Do not use ''OMP THREADPRIVATE'' variables.
Line 40: Line 40:
 ===== 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. Example: +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'' instead of ''%%SQRT(x(1)**2 + x(2)**2 + x(3)**2)%%''+
  
 +  * ''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)%%''
  
  
dev/codingconventions.txt · Last modified: 2020/08/21 10:15 by 127.0.0.1