developers:coding_rules
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
developers:coding_rules [2021/08/31 20:28] – [4. Constructs for flow control] Xavier Gonze | developers:coding_rules [2021/08/31 20:32] – [12. Other topics] Xavier Gonze | ||
---|---|---|---|
Line 422: | Line 422: | ||
5.b. Literal labels or comment lines must be used for each construct that is longer than one page of a screen (about 20 lines), both at the beginning and at the end of the construct. (enforced) | 5.b. Literal labels or comment lines must be used for each construct that is longer than one page of a screen (about 20 lines), both at the beginning and at the end of the construct. (enforced) | ||
- | ====== | + | ====== |
- | 5.a. Distinguish explicitly a vector operation from its scalar counterpart, | + | 6.a. Distinguish explicitly a vector operation from its scalar counterpart, |
suppose | suppose | ||
Line 440: | Line 440: | ||
However, this rule can lead to problems with the stack size, see rules 5c-e. (enforced) (JB:I think the stack size has really increased and for a small routine that need temporary array of small size this is better that spending time for allocation/ | However, this rule can lead to problems with the stack size, see rules 5c-e. (enforced) (JB:I think the stack size has really increased and for a small routine that need temporary array of small size this is better that spending time for allocation/ | ||
- | 5.b. In order to improve the readability of the code, use vector operations instead of explicit DO-loop constructs. Use also the intrinsic subroutines '' | + | 6.b. In order to improve the readability of the code, use vector operations instead of explicit DO-loop constructs. Use also the intrinsic subroutines '' |
functions like '' | functions like '' | ||
Use directly the array name: you do not need to distinguish this operation from an hypothetical scalar counterpart. | Use directly the array name: you do not need to distinguish this operation from an hypothetical scalar counterpart. | ||
Line 447: | Line 447: | ||
do not lead to as good a readability (see later). (partially enforced) | do not lead to as good a readability (see later). (partially enforced) | ||
- | 5.c DO NOT pass as an argument of a subroutine, a segment of an array. For example : | + | 6.c DO NOT pass as an argument of a subroutine, a segment of an array. For example : |
call routine(aa(1: | call routine(aa(1: | ||
Line 465: | Line 465: | ||
(enforced, with the restrictions mentioned) | (enforced, with the restrictions mentioned) | ||
- | 5.d Avoid the following construct, except when the segment size is sufficiently small: | + | 6.d Avoid the following construct, except when the segment size is sufficiently small: |
aa(:, | aa(:, | ||
(JB: Is there really a problem there ? I think I do that and I don't have trouble) | (JB: Is there really a problem there ? I think I do that and I don't have trouble) | ||
- | (JB:NB: all the implicit loop are good for new cpus since then can vectorize the intrusction. So loops should really be though carefully) | + | (JB:NB: all the implicit loop are good for new cpus since then can vectorize the instruction. So loops should really be though carefully) |
On the DEC machines, the compiler thinks it must first store the segment aa(:,jj) in the stack, then copy the stack in aa(:,ii). | On the DEC machines, the compiler thinks it must first store the segment aa(:,jj) in the stack, then copy the stack in aa(:,ii). | ||
This not only doubles the time for copying, but can lead to stack size problems. | This not only doubles the time for copying, but can lead to stack size problems. | ||
Line 478: | Line 478: | ||
(enforced) | (enforced) | ||
- | 5.e Avoid the use of large segments in read or write operations (**MG: not easy to accomplish, especially for binary IO**) | + | 6.e Avoid the use of large segments in read or write operations (**MG: not easy to accomplish, especially for binary IO**) |
read(6, | read(6, | ||
Line 497: | Line 497: | ||
(enforced) | (enforced) | ||
- | 5.f For allocation and deallocation of arrays use the macros ABI_ALLOCATE(array, | + | 6.f For allocation and deallocation of arrays use the macros ABI_ALLOCATE(array, |
- | ====== | + | ====== |
* Run innermost loop fastest in looping. This is simply less CPU time consuming in Fortran.(JB: | * Run innermost loop fastest in looping. This is simply less CPU time consuming in Fortran.(JB: | ||
Line 507: | Line 507: | ||
* ***MG_TOO_COMPLICATED_USEFASTLIBS_INSTEAD*** On many machines cache memory conflicts, which slow down performance, | * ***MG_TOO_COMPLICATED_USEFASTLIBS_INSTEAD*** On many machines cache memory conflicts, which slow down performance, | ||
- | ====== | + | ====== |
MG: This part must be rewritten. We should stop the code via macros such as MSG_ERROR | MG: This part must be rewritten. We should stop the code via macros such as MSG_ERROR | ||
Line 578: | Line 578: | ||
(enforced) | (enforced) | ||
- | ====== | + | ====== |
* Use | * Use | ||
Line 614: | Line 614: | ||
! although grammatically incorrect. (usually enforced) | ! although grammatically incorrect. (usually enforced) | ||
- | ====== | + | ====== |
BLAS and LAPACK subroutines are public domain subroutines, | BLAS and LAPACK subroutines are public domain subroutines, | ||
Line 672: | Line 672: | ||
(at present, no other BLAS routines than those called by LAPACK are used in ABINIT, so these rules are indications for the future) | (at present, no other BLAS routines than those called by LAPACK are used in ABINIT, so these rules are indications for the future) | ||
- | ====== Modules ====== | + | ====== |
MG: This section should be rewritten from scratch! | MG: This section should be rewritten from scratch! | ||
Line 695: | Line 695: | ||
Be cautious when you introduce such a feature, and mention it to the ABINIT coordinator. | Be cautious when you introduce such a feature, and mention it to the ABINIT coordinator. | ||
- | ====== Derived datatypes ====== | + | ====== |
- | Derived datatypes should be declared in the adequate module (MG: And this rule is not followed in many places, e.g dataset_type, | + | 12.a. Derived datatypes should be declared in the adequate module (MG: And this rule is not followed in many places, e.g dataset_type, |
These are powerful F90 constructs, but the information about them is not local to the subroutine | These are powerful F90 constructs, but the information about them is not local to the subroutine | ||
where they are used, so they should be introduced in a controlled way, in order for the programmers to become sufficiently easily familiarized with them: the introduction of a new derived datatype must be made in agreement with the coordinator of ABINIT. | where they are used, so they should be introduced in a controlled way, in order for the programmers to become sufficiently easily familiarized with them: the introduction of a new derived datatype must be made in agreement with the coordinator of ABINIT. | ||
The introduction of appropriate derived datatypes in ABINIT is one of the central issues of v3.2 and later versions. | The introduction of appropriate derived datatypes in ABINIT is one of the central issues of v3.2 and later versions. | ||
- | 11.b. Suffix a type identifier with ' | + | 12.b. Suffix a type identifier with ' |
TYPE ipe_type | TYPE ipe_type | ||
Line 713: | Line 713: | ||
| | ||
- | 11.c. Pros and cons. | + | 12.c. Pros and cons. |
Grouping connected variables into structured types is interesting for readability (it avoids too long | Grouping connected variables into structured types is interesting for readability (it avoids too long | ||
Line 723: | Line 723: | ||
However, source code itself may become less readable. Also, remember that the use of structured types is never more efficient for CPU: complex declarations should be avoided. | However, source code itself may become less readable. Also, remember that the use of structured types is never more efficient for CPU: complex declarations should be avoided. | ||
- | ====== | + | ====== |
For the time being, pointers are only allowed when an array has to be allocated in a subprogram, and | For the time being, pointers are only allowed when an array has to be allocated in a subprogram, and |
developers/coding_rules.txt · Last modified: 2021/08/31 20:35 by Xavier Gonze