Skip to content
Snippets Groups Projects
Commit 426fb9cc authored by sparonuz's avatar sparonuz
Browse files

Added key_single to coding rules

parent a3db1f32
No related branches found
No related tags found
1 merge request!7Added key_single to coding rules
Pipeline #1394 passed with stage
in 6 minutes and 3 seconds
......@@ -612,6 +612,46 @@ definitions" to obtain the required numerical precision and range as well as the
REAL(wp), DIMENSION(jpi,jpj,jpk) :: zpc ! power consumption
\end{forlines}
\subsubsection{The \key{single}}
In the \path{./src/OCE/par_kind.F90} module the working precision
for \forcode{REAL} variables is declared as follows:
\begin{forlines}
# if defined key_single
INTEGER, PUBLIC, PARAMETER :: wp = sp !: working precision
# else
INTEGER, PUBLIC, PARAMETER :: wp = dp !: working precision
# endif
\end{forlines}
The default is \forcode{dp}, so that all the real variables declared \forcode{wp} are assigned to be double precision.
The \key{single} is available to switch the precision of the \forcode{wp} parameter
to single precision. This does not mean that the code will be fully single precision,
which can lead to instabilities in the model. In facts, the declaration of a set of variables
has been hardcoded to \forcode{dp} and the key \key{single} enables to run in mixed-precision.
Variables that need to stay double precision, no matter the value of the working precision are declared as:
\begin{forlines}
REAL(dp), DIMENSION(jpi,jpj,jpk) :: arr_name
\end{forlines}
This set of variables has been highlighted using the methodology described in Tinto et al. 2019. and this mixed-precision
version of \NEMO is tested for the official configuration \forcode{ORCA2} compiled without the \forcode{ICE} module.
Apart from changing the value of the \forcode{wp} parameter another macro will be activated by the usage of the \key{single}. Inside the
\path{./src/OCE/single_precision_substitute.h90} two macros are defined:
\begin{forlines}
#if defined key_single
# define CASTSP(x) REAL(x,sp)
# define CASTDP(x) REAL(x,dp)
#else
# define CASTSP(x) x
# define CASTDP(x) x
#endif
\end{forlines}
When the \key{single} is used at compilation time all the variable
to which this macro is applied will be put inside a cast, to double or single precision depending on the macro used.
This is done to ensure coherence at compilation time between variables and dummy arguments in some function and subroutine calls.
When the \key{single} is omitted the cast is no longer needed and the macro evaluates to the variable itself.
\subsection{Structures}
The \forcode{TYPE} structure allowing to declare some variables is more often used in \NEMO,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment