\hypertarget{namespacemom__coms}{}\doxysection{mom\+\_\+coms Module Reference}
\label{namespacemom__coms}\index{mom\_coms@{mom\_coms}}


\doxysubsection{Detailed Description}
Interfaces to non-\/domain-\/oriented communication subroutines, including the M\+O\+M6 reproducing sums facility. \doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
interface \mbox{\hyperlink{interfacemom__coms_1_1assignment_07_0a_08}{assignment(=)}}
\begin{DoxyCompactList}\small\item\em Copy the value of one extended-\/fixed-\/point number into another. \end{DoxyCompactList}\item 
interface \mbox{\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\+\_\+sum\+\_\+across\+\_\+pes}}
\begin{DoxyCompactList}\small\item\em Sum a value or 1-\/d array of values across processors, returning the sums in place. \end{DoxyCompactList}\item 
type \mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}
\begin{DoxyCompactList}\small\item\em The Extended Fixed Point (E\+FP) type provides a public interface for doing sums and taking differences with this type. \end{DoxyCompactList}\item 
interface \mbox{\hyperlink{interfacemom__coms_1_1operator_07_09_08}{operator(+)}}
\begin{DoxyCompactList}\small\item\em Add two extended-\/fixed-\/point numbers. \end{DoxyCompactList}\item 
interface \mbox{\hyperlink{interfacemom__coms_1_1operator_07-_08}{operator(-\/)}}
\begin{DoxyCompactList}\small\item\em Subtract one extended-\/fixed-\/point number from another. \end{DoxyCompactList}\item 
interface \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\+\_\+sum}}
\begin{DoxyCompactList}\small\item\em Find an accurate and order-\/invariant sum of a distributed 2d or 3d field. \end{DoxyCompactList}\item 
interface \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum__efp}{reproducing\+\_\+sum\+\_\+efp}}
\begin{DoxyCompactList}\small\item\em Find an accurate and order-\/invariant sum of a distributed 2d field, returning the result in the form of an extended fixed point value that can be converted back with E\+F\+P\+\_\+to\+\_\+real. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}) function \mbox{\hyperlink{namespacemom__coms_a81eab26b0e062043ae4b13949d90a5dc}{reproducing\+\_\+efp\+\_\+sum\+\_\+2d}} (array, isr, ier, jsr, jer, overflow\+\_\+check, err, only\+\_\+on\+\_\+\+PE)
\begin{DoxyCompactList}\small\item\em This subroutine uses a conversion to an integer representation of real numbers to give an order-\/invariant sum of distributed 2-\/D arrays that reproduces across domain decomposition, with the result returned as an extended fixed point type that can be converted back to a real number using E\+F\+P\+\_\+to\+\_\+real. This technique is described in Hallberg \& Adcroft, 2014, Parallel Computing, doi\+:10.\+1016/j.parco.\+2014.\+04.\+007. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__coms_a82b35df61c7d0aba1712fc3ce7b47685}{reproducing\+\_\+sum\+\_\+2d}} (array, isr, ier, jsr, jer, E\+F\+P\+\_\+sum, reproducing, overflow\+\_\+check, err, only\+\_\+on\+\_\+\+PE)
\begin{DoxyCompactList}\small\item\em This subroutine uses a conversion to an integer representation of real numbers to give an order-\/invariant sum of distributed 2-\/D arrays that reproduces across domain decomposition. This technique is described in Hallberg \& Adcroft, 2014, Parallel Computing, doi\+:10.\+1016/j.parco.\+2014.\+04.\+007. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__coms_aa98bb5adb44798d397f668edf62832e8}{reproducing\+\_\+sum\+\_\+3d}} (array, isr, ier, jsr, jer, sums, E\+F\+P\+\_\+sum, E\+F\+P\+\_\+lay\+\_\+sums, err, only\+\_\+on\+\_\+\+PE)
\begin{DoxyCompactList}\small\item\em This subroutine uses a conversion to an integer representation of real numbers to give an order-\/invariant sum of distributed 3-\/D arrays that reproduces across domain decomposition. This technique is described in Hallberg \& Adcroft, 2014, Parallel Computing, doi\+:10.\+1016/j.parco.\+2014.\+04.\+007. \end{DoxyCompactList}\item 
integer(kind=8) function, dimension(\mbox{\hyperlink{namespacemom__coms_ac1760c24e671a314322e4b1b33e0db39}{ni}}) \mbox{\hyperlink{namespacemom__coms_a0cc261620495abf3313937726883b95e}{real\+\_\+to\+\_\+ints}} (r, prec\+\_\+error, overflow)
\begin{DoxyCompactList}\small\item\em Convert a real number into the array of integers constitute its extended-\/fixed-\/point representation. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__coms_a24ac5b7cc37b1498f23b61eea03fb8c3}{ints\+\_\+to\+\_\+real}} (ints)
\begin{DoxyCompactList}\small\item\em Convert the array of integers that constitute an extended-\/fixed-\/point representation into a real number. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__coms_a8228dee8e8e72652d5a58f483f0dc661}{increment\+\_\+ints}} (int\+\_\+sum, int2, prec\+\_\+error)
\begin{DoxyCompactList}\small\item\em Increment an array of integers that constitutes an extended-\/fixed-\/point representation with a another E\+FP number. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__coms_aebe91f9c9bd6de5e9523c1f663e8a04d}{increment\+\_\+ints\+\_\+faster}} (int\+\_\+sum, r, max\+\_\+mag\+\_\+term)
\begin{DoxyCompactList}\small\item\em Increment an E\+FP number with a real number without doing any carrying of of overflows and using only minimal error checking. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__coms_a3fe107391eb9d2c199eb09e451f4dbb2}{carry\+\_\+overflow}} (int\+\_\+sum, prec\+\_\+error)
\begin{DoxyCompactList}\small\item\em This subroutine handles carrying of the overflow. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__coms_ab8feff19e782af36bb7ccccd5ba9eddc}{regularize\+\_\+ints}} (int\+\_\+sum)
\begin{DoxyCompactList}\small\item\em This subroutine carries the overflow, and then makes sure that all integers are of the same sign as the overall value. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__coms_addf8caf9a58bed7059b5bb6660d73c4e}\label{namespacemom__coms_addf8caf9a58bed7059b5bb6660d73c4e}} 
logical function, public \mbox{\hyperlink{namespacemom__coms_addf8caf9a58bed7059b5bb6660d73c4e}{query\+\_\+efp\+\_\+overflow\+\_\+error}} ()
\begin{DoxyCompactList}\small\item\em Returns the status of the module\textquotesingle{}s error flag. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__coms_a9a44466e43db89b2525996feedd11b7a}\label{namespacemom__coms_a9a44466e43db89b2525996feedd11b7a}} 
subroutine, public \mbox{\hyperlink{namespacemom__coms_a9a44466e43db89b2525996feedd11b7a}{reset\+\_\+efp\+\_\+overflow\+\_\+error}} ()
\begin{DoxyCompactList}\small\item\em Reset the module\textquotesingle{}s error flag to false. \end{DoxyCompactList}\item 
type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}) function, public \mbox{\hyperlink{namespacemom__coms_abfb8af92b0a6ee8b7f5d8391f6893977}{efp\+\_\+plus}} (E\+F\+P1, E\+F\+P2)
\begin{DoxyCompactList}\small\item\em Add two extended-\/fixed-\/point numbers. \end{DoxyCompactList}\item 
type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}) function, public \mbox{\hyperlink{namespacemom__coms_ac9cda4ec7606fa2e47d79d759d9e6694}{efp\+\_\+minus}} (E\+F\+P1, E\+F\+P2)
\begin{DoxyCompactList}\small\item\em Subract one extended-\/fixed-\/point number from another. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__coms_a63ee6c200b7e9e34624430be6347fbec}{efp\+\_\+assign}} (E\+F\+P1, E\+F\+P2)
\begin{DoxyCompactList}\small\item\em Copy one extended-\/fixed-\/point number into another. \end{DoxyCompactList}\item 
real function, public \mbox{\hyperlink{namespacemom__coms_a4aaf51b372bcaf7b46939145577eff92}{efp\+\_\+to\+\_\+real}} (E\+F\+P1)
\begin{DoxyCompactList}\small\item\em Return the real number that an extended-\/fixed-\/point number corresponds with. \end{DoxyCompactList}\item 
real function, public \mbox{\hyperlink{namespacemom__coms_a8f23ba3eaaf03101afa61c339fac805b}{efp\+\_\+real\+\_\+diff}} (E\+F\+P1, E\+F\+P2)
\begin{DoxyCompactList}\small\item\em Take the difference between two extended-\/fixed-\/point numbers (E\+F\+P1 -\/ E\+F\+P2) and return the result as a real number. \end{DoxyCompactList}\item 
type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}) function, public \mbox{\hyperlink{namespacemom__coms_ac8f1b5be23b128cd8bb956ebda917edb}{real\+\_\+to\+\_\+efp}} (val, overflow)
\begin{DoxyCompactList}\small\item\em Return the extended-\/fixed-\/point number that a real number corresponds with. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__coms_a6cbcab29d87b134dcd5c4bdb922b4344}{efp\+\_\+list\+\_\+sum\+\_\+across\+\_\+pes}} (E\+F\+Ps, nval, errors)
\begin{DoxyCompactList}\small\item\em This subroutine does a sum across P\+Es of a list of E\+FP variables, returning the sums in place, with all overflows carried. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__coms_aa6ad80e8330fc146562404a4e756916b}{efp\+\_\+val\+\_\+sum\+\_\+across\+\_\+pes}} (E\+FP, error)
\begin{DoxyCompactList}\small\item\em This subroutine does a sum across P\+Es of an E\+FP variable, returning the sums in place, with all overflows carried. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__coms_a6a5fa5714820df840a829d6d1b432a75}\label{namespacemom__coms_a6a5fa5714820df840a829d6d1b432a75}} 
subroutine, public \mbox{\hyperlink{namespacemom__coms_a6a5fa5714820df840a829d6d1b432a75}{mom\+\_\+infra\+\_\+end}}
\begin{DoxyCompactList}\small\item\em This subroutine carries out all of the calls required to close out the infrastructure cleanly. This should only be called in ocean-\/only runs, as the coupler takes care of this in coupled runs. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__coms_a53dec744e5fb972fe74863d02a5b3f7f}\label{namespacemom__coms_a53dec744e5fb972fe74863d02a5b3f7f}} 
integer(kind=8), parameter \mbox{\hyperlink{namespacemom__coms_a53dec744e5fb972fe74863d02a5b3f7f}{prec}} =2\+\_\+8$\ast$$\ast$46
\begin{DoxyCompactList}\small\item\em The precision of each integer. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__coms_a885379ffe89eb60f2b0071abb9e8c638}\label{namespacemom__coms_a885379ffe89eb60f2b0071abb9e8c638}} 
real, parameter \mbox{\hyperlink{namespacemom__coms_a885379ffe89eb60f2b0071abb9e8c638}{r\+\_\+prec}} =2.\+0$\ast$$\ast$46
\begin{DoxyCompactList}\small\item\em A real version of prec. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__coms_af2d95ca11334965b9f5ecf2593692cd7}\label{namespacemom__coms_af2d95ca11334965b9f5ecf2593692cd7}} 
real, parameter \mbox{\hyperlink{namespacemom__coms_af2d95ca11334965b9f5ecf2593692cd7}{i\+\_\+prec}} =1.\+0/(2.\+0$\ast$$\ast$46)
\begin{DoxyCompactList}\small\item\em The inverse of prec. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__coms_a2aeaf40b69c9d498459bc534a38451d8}\label{namespacemom__coms_a2aeaf40b69c9d498459bc534a38451d8}} 
integer, parameter \mbox{\hyperlink{namespacemom__coms_a2aeaf40b69c9d498459bc534a38451d8}{max\+\_\+count\+\_\+prec}} =2$\ast$$\ast$(63-\/46)-\/1
\begin{DoxyCompactList}\small\item\em The number of values that can be added together with the current value of prec before there will be roundoff problems. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__coms_ac1760c24e671a314322e4b1b33e0db39}\label{namespacemom__coms_ac1760c24e671a314322e4b1b33e0db39}} 
integer, parameter \mbox{\hyperlink{namespacemom__coms_ac1760c24e671a314322e4b1b33e0db39}{ni}} =6
\begin{DoxyCompactList}\small\item\em The number of long integers to use to represent a real number. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__coms_ad18445cd567da1ccb36b4080c93b4d61}\label{namespacemom__coms_ad18445cd567da1ccb36b4080c93b4d61}} 
real, dimension(\mbox{\hyperlink{namespacemom__coms_ac1760c24e671a314322e4b1b33e0db39}{ni}}), parameter \mbox{\hyperlink{namespacemom__coms_ad18445cd567da1ccb36b4080c93b4d61}{pr}} = (/ \mbox{\hyperlink{namespacemom__coms_a885379ffe89eb60f2b0071abb9e8c638}{r\+\_\+prec}}$\ast$$\ast$2, \mbox{\hyperlink{namespacemom__coms_a885379ffe89eb60f2b0071abb9e8c638}{r\+\_\+prec}}, 1.\+0, 1.\+0/\mbox{\hyperlink{namespacemom__coms_a885379ffe89eb60f2b0071abb9e8c638}{r\+\_\+prec}}, 1.\+0/\mbox{\hyperlink{namespacemom__coms_a885379ffe89eb60f2b0071abb9e8c638}{r\+\_\+prec}}$\ast$$\ast$2, 1.\+0/\mbox{\hyperlink{namespacemom__coms_a885379ffe89eb60f2b0071abb9e8c638}{r\+\_\+prec}}$\ast$$\ast$3 /)
\begin{DoxyCompactList}\small\item\em An array of the real precision of each of the integers. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__coms_ab2035af144ae0d121f4259db705c4185}\label{namespacemom__coms_ab2035af144ae0d121f4259db705c4185}} 
real, dimension(\mbox{\hyperlink{namespacemom__coms_ac1760c24e671a314322e4b1b33e0db39}{ni}}), parameter \mbox{\hyperlink{namespacemom__coms_ab2035af144ae0d121f4259db705c4185}{i\+\_\+pr}} = (/ 1.\+0/\mbox{\hyperlink{namespacemom__coms_a885379ffe89eb60f2b0071abb9e8c638}{r\+\_\+prec}}$\ast$$\ast$2, 1.\+0/\mbox{\hyperlink{namespacemom__coms_a885379ffe89eb60f2b0071abb9e8c638}{r\+\_\+prec}}, 1.\+0, \mbox{\hyperlink{namespacemom__coms_a885379ffe89eb60f2b0071abb9e8c638}{r\+\_\+prec}}, \mbox{\hyperlink{namespacemom__coms_a885379ffe89eb60f2b0071abb9e8c638}{r\+\_\+prec}}$\ast$$\ast$2, \mbox{\hyperlink{namespacemom__coms_a885379ffe89eb60f2b0071abb9e8c638}{r\+\_\+prec}}$\ast$$\ast$3 /)
\begin{DoxyCompactList}\small\item\em An array of the inverse of the real precision of each of the integers. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__coms_a863bd692f968d62288323e0badf23933}\label{namespacemom__coms_a863bd692f968d62288323e0badf23933}} 
real, parameter \mbox{\hyperlink{namespacemom__coms_a863bd692f968d62288323e0badf23933}{max\+\_\+efp\+\_\+float}} = \mbox{\hyperlink{namespacemom__coms_ad18445cd567da1ccb36b4080c93b4d61}{pr}}(1) $\ast$ (2.$\ast$$\ast$63 -\/ 1.)
\begin{DoxyCompactList}\small\item\em The largest float with an E\+FP representation. N\+O\+TE\+: Only the first bin can exceed precision, but is bounded by the largest signed integer. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__coms_a7af397491bbb8f8e6e9a268492bebc33}\label{namespacemom__coms_a7af397491bbb8f8e6e9a268492bebc33}} 
logical \mbox{\hyperlink{namespacemom__coms_a7af397491bbb8f8e6e9a268492bebc33}{overflow\+\_\+error}} = .false.
\begin{DoxyCompactList}\small\item\em This becomes true if an overflow is encountered. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__coms_adfb52edef53a82f62d4c9a0786ce6bdf}\label{namespacemom__coms_adfb52edef53a82f62d4c9a0786ce6bdf}} 
logical \mbox{\hyperlink{namespacemom__coms_adfb52edef53a82f62d4c9a0786ce6bdf}{nan\+\_\+error}} = .false.
\begin{DoxyCompactList}\small\item\em This becomes true if a NaN is encountered. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__coms_ad6c2231f3de989b71d4455ca97b24d8a}\label{namespacemom__coms_ad6c2231f3de989b71d4455ca97b24d8a}} 
logical \mbox{\hyperlink{namespacemom__coms_ad6c2231f3de989b71d4455ca97b24d8a}{debug}} = .false.
\begin{DoxyCompactList}\small\item\em Making this true enables debugging output. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__coms_a3fe107391eb9d2c199eb09e451f4dbb2}\label{namespacemom__coms_a3fe107391eb9d2c199eb09e451f4dbb2}} 
\index{mom\_coms@{mom\_coms}!carry\_overflow@{carry\_overflow}}
\index{carry\_overflow@{carry\_overflow}!mom\_coms@{mom\_coms}}
\doxysubsubsection{\texorpdfstring{carry\_overflow()}{carry\_overflow()}}
{\footnotesize\ttfamily subroutine mom\+\_\+coms\+::carry\+\_\+overflow (\begin{DoxyParamCaption}\item[{integer(kind=8), dimension(\mbox{\hyperlink{namespacemom__coms_ac1760c24e671a314322e4b1b33e0db39}{ni}}), intent(inout)}]{int\+\_\+sum,  }\item[{integer(kind=8), intent(in)}]{prec\+\_\+error }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine handles carrying of the overflow. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em int\+\_\+sum} & The array of E\+FP integers being modified by carries, but without changing value. \\
\hline
\mbox{\texttt{ in}}  & {\em prec\+\_\+error} & The P\+E-\/count dependent precision of the integers that is safe from overflows during global sums. This will be larger than the compile-\/time precision parameter, and is used to detect overflows. \\
\hline
\end{DoxyParams}


Definition at line 629 of file M\+O\+M\+\_\+coms.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{629   \textcolor{keywordtype}{integer(kind=8)}, \textcolor{keywordtype}{dimension(ni)}, \textcolor{keywordtype}{intent(inout)} :: int\_sum\textcolor{comment}{  !< The array of EFP integers being}}
\DoxyCodeLine{630 \textcolor{comment}{                                              !! modified by carries, but without changing value.}}
\DoxyCodeLine{631   \textcolor{keywordtype}{integer(kind=8)},                \textcolor{keywordtype}{intent(in)}    :: prec\_error\textcolor{comment}{  !< The PE-\/count dependent precision of the}}
\DoxyCodeLine{632 \textcolor{comment}{                                              !! integers that is safe from overflows during global}}
\DoxyCodeLine{633 \textcolor{comment}{                                              !! sums.  This will be larger than the compile-\/time}}
\DoxyCodeLine{634 \textcolor{comment}{                                              !! precision parameter, and is used to detect overflows.}}
\DoxyCodeLine{635 }
\DoxyCodeLine{636   \textcolor{comment}{! This subroutine handles carrying of the overflow.}}
\DoxyCodeLine{637   \textcolor{keywordtype}{integer} :: i, num\_carry}
\DoxyCodeLine{638 }
\DoxyCodeLine{639   \textcolor{keywordflow}{do} i=ni,2,-\/1 ; \textcolor{keywordflow}{if} (abs(int\_sum(i)) >= prec) \textcolor{keywordflow}{then}}
\DoxyCodeLine{640     num\_carry = int(int\_sum(i) * i\_prec)}
\DoxyCodeLine{641     int\_sum(i) = int\_sum(i) -\/ num\_carry*prec}
\DoxyCodeLine{642     int\_sum(i-\/1) = int\_sum(i-\/1) + num\_carry}
\DoxyCodeLine{643 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{644   \textcolor{keywordflow}{if} (abs(int\_sum(1)) > prec\_error) \textcolor{keywordflow}{then}}
\DoxyCodeLine{645     overflow\_error = .true.}
\DoxyCodeLine{646 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{647 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__coms_a63ee6c200b7e9e34624430be6347fbec}\label{namespacemom__coms_a63ee6c200b7e9e34624430be6347fbec}} 
\index{mom\_coms@{mom\_coms}!efp\_assign@{efp\_assign}}
\index{efp\_assign@{efp\_assign}!mom\_coms@{mom\_coms}}
\doxysubsubsection{\texorpdfstring{efp\_assign()}{efp\_assign()}}
{\footnotesize\ttfamily subroutine mom\+\_\+coms\+::efp\+\_\+assign (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}), intent(out)}]{E\+F\+P1,  }\item[{type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}), intent(in)}]{E\+F\+P2 }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Copy one extended-\/fixed-\/point number into another. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em efp1} & The recipient extended fixed point number \\
\hline
\mbox{\texttt{ in}}  & {\em efp2} & The source extended fixed point number \\
\hline
\end{DoxyParams}


Definition at line 729 of file M\+O\+M\+\_\+coms.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{729   \textcolor{keywordtype}{type}(EFP\_type), \textcolor{keywordtype}{intent(out)} :: EFP1\textcolor{comment}{ !< The recipient extended fixed point number}}
\DoxyCodeLine{730   \textcolor{keywordtype}{type}(EFP\_type), \textcolor{keywordtype}{intent(in)}  :: EFP2\textcolor{comment}{ !< The source extended fixed point number}}
\DoxyCodeLine{731   \textcolor{keywordtype}{integer} i}
\DoxyCodeLine{732   \textcolor{comment}{! This subroutine assigns all components of the extended fixed point type}}
\DoxyCodeLine{733   \textcolor{comment}{! variable on the RHS (EFP2) to the components of the variable on the LHS}}
\DoxyCodeLine{734   \textcolor{comment}{! (EFP1).}}
\DoxyCodeLine{735 }
\DoxyCodeLine{736   \textcolor{keywordflow}{do} i=1,ni ; efp1\%v(i) = efp2\%v(i) ;\textcolor{keywordflow}{ enddo}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__coms_a6cbcab29d87b134dcd5c4bdb922b4344}\label{namespacemom__coms_a6cbcab29d87b134dcd5c4bdb922b4344}} 
\index{mom\_coms@{mom\_coms}!efp\_list\_sum\_across\_pes@{efp\_list\_sum\_across\_pes}}
\index{efp\_list\_sum\_across\_pes@{efp\_list\_sum\_across\_pes}!mom\_coms@{mom\_coms}}
\doxysubsubsection{\texorpdfstring{efp\_list\_sum\_across\_pes()}{efp\_list\_sum\_across\_pes()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+coms\+::efp\+\_\+list\+\_\+sum\+\_\+across\+\_\+pes (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}), dimension(\+:), intent(inout)}]{E\+F\+Ps,  }\item[{integer, intent(in)}]{nval,  }\item[{logical, dimension(\+:), intent(out), optional}]{errors }\end{DoxyParamCaption})}



This subroutine does a sum across P\+Es of a list of E\+FP variables, returning the sums in place, with all overflows carried. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em efps} & The list of extended fixed point numbers \\
\hline
\mbox{\texttt{ in}}  & {\em nval} & The number of values being summed. \\
\hline
\mbox{\texttt{ out}}  & {\em errors} & A list of error flags for each sum \\
\hline
\end{DoxyParams}


Definition at line 789 of file M\+O\+M\+\_\+coms.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{789   \textcolor{keywordtype}{type}(EFP\_type), \textcolor{keywordtype}{dimension(:)}, \&}
\DoxyCodeLine{790               \textcolor{keywordtype}{intent(inout)} :: EFPs\textcolor{comment}{   !< The list of extended fixed point numbers}}
\DoxyCodeLine{791 \textcolor{comment}{                                      !! being summed across PEs.}}
\DoxyCodeLine{792   \textcolor{keywordtype}{integer},    \textcolor{keywordtype}{intent(in)}    :: nval\textcolor{comment}{   !< The number of values being summed.}}
\DoxyCodeLine{793   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(:)}, \&}
\DoxyCodeLine{794            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: errors\textcolor{comment}{ !< A list of error flags for each sum}}
\DoxyCodeLine{795 }
\DoxyCodeLine{796   \textcolor{comment}{!   This subroutine does a sum across PEs of a list of EFP variables,}}
\DoxyCodeLine{797   \textcolor{comment}{! returning the sums in place, with all overflows carried.}}
\DoxyCodeLine{798 }
\DoxyCodeLine{799   \textcolor{keywordtype}{integer(kind=8)}, \textcolor{keywordtype}{dimension(ni,nval)} :: ints}
\DoxyCodeLine{800   \textcolor{keywordtype}{integer(kind=8)} :: prec\_error}
\DoxyCodeLine{801   \textcolor{keywordtype}{logical} :: error\_found}
\DoxyCodeLine{802   \textcolor{keywordtype}{character(len=256)} :: mesg}
\DoxyCodeLine{803   \textcolor{keywordtype}{integer} :: i, n}
\DoxyCodeLine{804 }
\DoxyCodeLine{805   \textcolor{keywordflow}{if} (num\_pes() > max\_count\_prec) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{806     \textcolor{stringliteral}{"reproducing\_sum: Too many processors are being used for the value of "}//\&}
\DoxyCodeLine{807     \textcolor{stringliteral}{"prec.  Reduce prec to (2\string^63-\/1)/num\_PEs."})}
\DoxyCodeLine{808 }
\DoxyCodeLine{809   prec\_error = (2\_8**62 + (2\_8**62 -\/ 1)) / num\_pes()}
\DoxyCodeLine{810   \textcolor{comment}{! overflow\_error is an overflow error flag for the whole module.}}
\DoxyCodeLine{811   overflow\_error = .false. ; error\_found = .false.}
\DoxyCodeLine{812 }
\DoxyCodeLine{813   \textcolor{keywordflow}{do} i=1,nval ; \textcolor{keywordflow}{do} n=1,ni ; ints(n,i) = efps(i)\%v(n) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{814 }
\DoxyCodeLine{815   \textcolor{keyword}{call }sum\_across\_pes(ints(:,:), ni*nval)}
\DoxyCodeLine{816 }
\DoxyCodeLine{817   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(errors)) errors(:) = .false.}
\DoxyCodeLine{818   \textcolor{keywordflow}{do} i=1,nval}
\DoxyCodeLine{819     overflow\_error = .false.}
\DoxyCodeLine{820     \textcolor{keyword}{call }carry\_overflow(ints(:,i), prec\_error)}
\DoxyCodeLine{821     \textcolor{keywordflow}{do} n=1,ni ; efps(i)\%v(n) = ints(n,i) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{822     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(errors)) errors(i) = overflow\_error}
\DoxyCodeLine{823     \textcolor{keywordflow}{if} (overflow\_error) \textcolor{keywordflow}{then}}
\DoxyCodeLine{824       \textcolor{keyword}{write} (mesg,\textcolor{stringliteral}{'("EFP\_list\_sum\_across\_PEs error at ",i6," val was ",ES12.6, ", prec\_error = ",ES12.6)'}) \&}
\DoxyCodeLine{825              i, efp\_to\_real(efps(i)), real(prec\_error)}
\DoxyCodeLine{826       \textcolor{keyword}{call }mom\_error(warning, mesg)}
\DoxyCodeLine{827 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{828     error\_found = error\_found .or. overflow\_error}
\DoxyCodeLine{829 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{830   \textcolor{keywordflow}{if} (error\_found .and. .not.(\textcolor{keyword}{present}(errors))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{831     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Overflow in EFP\_list\_sum\_across\_PEs."})}
\DoxyCodeLine{832 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{833 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__coms_ac9cda4ec7606fa2e47d79d759d9e6694}\label{namespacemom__coms_ac9cda4ec7606fa2e47d79d759d9e6694}} 
\index{mom\_coms@{mom\_coms}!efp\_minus@{efp\_minus}}
\index{efp\_minus@{efp\_minus}!mom\_coms@{mom\_coms}}
\doxysubsubsection{\texorpdfstring{efp\_minus()}{efp\_minus()}}
{\footnotesize\ttfamily type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}) function, public mom\+\_\+coms\+::efp\+\_\+minus (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}), intent(in)}]{E\+F\+P1,  }\item[{type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}), intent(in)}]{E\+F\+P2 }\end{DoxyParamCaption})}



Subract one extended-\/fixed-\/point number from another. 

\begin{DoxyReturn}{Returns}
The result in extended fixed point format 
\end{DoxyReturn}

\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em efp1} & The first extended fixed point number \\
\hline
\mbox{\texttt{ in}}  & {\em efp2} & The extended fixed point number being subtracted from the first extended fixed point number \\
\hline
\end{DoxyParams}


Definition at line 716 of file M\+O\+M\+\_\+coms.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{716   \textcolor{keywordtype}{type}(EFP\_type)             :: EFP\_minus\textcolor{comment}{ !< The result in extended fixed point format}}
\DoxyCodeLine{717   \textcolor{keywordtype}{type}(EFP\_type), \textcolor{keywordtype}{intent(in)} :: EFP1\textcolor{comment}{ !< The first extended fixed point number}}
\DoxyCodeLine{718   \textcolor{keywordtype}{type}(EFP\_type), \textcolor{keywordtype}{intent(in)} :: EFP2\textcolor{comment}{ !< The extended fixed point number being}}
\DoxyCodeLine{719 \textcolor{comment}{                        !! subtracted from the first extended fixed point number}}
\DoxyCodeLine{720   \textcolor{keywordtype}{integer} :: i}
\DoxyCodeLine{721 }
\DoxyCodeLine{722   \textcolor{keywordflow}{do} i=1,ni ; efp\_minus\%v(i) = -\/1*efp2\%v(i) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{723 }
\DoxyCodeLine{724   \textcolor{keyword}{call }increment\_ints(efp\_minus\%v(:), efp1\%v(:))}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__coms_abfb8af92b0a6ee8b7f5d8391f6893977}\label{namespacemom__coms_abfb8af92b0a6ee8b7f5d8391f6893977}} 
\index{mom\_coms@{mom\_coms}!efp\_plus@{efp\_plus}}
\index{efp\_plus@{efp\_plus}!mom\_coms@{mom\_coms}}
\doxysubsubsection{\texorpdfstring{efp\_plus()}{efp\_plus()}}
{\footnotesize\ttfamily type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}) function, public mom\+\_\+coms\+::efp\+\_\+plus (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}), intent(in)}]{E\+F\+P1,  }\item[{type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}), intent(in)}]{E\+F\+P2 }\end{DoxyParamCaption})}



Add two extended-\/fixed-\/point numbers. 

\begin{DoxyReturn}{Returns}
The result in extended fixed point format 
\end{DoxyReturn}

\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em efp1} & The first extended fixed point number \\
\hline
\mbox{\texttt{ in}}  & {\em efp2} & The second extended fixed point number \\
\hline
\end{DoxyParams}


Definition at line 705 of file M\+O\+M\+\_\+coms.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{705   \textcolor{keywordtype}{type}(EFP\_type)             :: EFP\_plus\textcolor{comment}{ !< The result in extended fixed point format}}
\DoxyCodeLine{706   \textcolor{keywordtype}{type}(EFP\_type), \textcolor{keywordtype}{intent(in)} :: EFP1\textcolor{comment}{ !< The first extended fixed point number}}
\DoxyCodeLine{707   \textcolor{keywordtype}{type}(EFP\_type), \textcolor{keywordtype}{intent(in)} :: EFP2\textcolor{comment}{ !< The second extended fixed point number}}
\DoxyCodeLine{708 }
\DoxyCodeLine{709   efp\_plus = efp1}
\DoxyCodeLine{710 }
\DoxyCodeLine{711   \textcolor{keyword}{call }increment\_ints(efp\_plus\%v(:), efp2\%v(:))}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__coms_a8f23ba3eaaf03101afa61c339fac805b}\label{namespacemom__coms_a8f23ba3eaaf03101afa61c339fac805b}} 
\index{mom\_coms@{mom\_coms}!efp\_real\_diff@{efp\_real\_diff}}
\index{efp\_real\_diff@{efp\_real\_diff}!mom\_coms@{mom\_coms}}
\doxysubsubsection{\texorpdfstring{efp\_real\_diff()}{efp\_real\_diff()}}
{\footnotesize\ttfamily real function, public mom\+\_\+coms\+::efp\+\_\+real\+\_\+diff (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}), intent(in)}]{E\+F\+P1,  }\item[{type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}), intent(in)}]{E\+F\+P2 }\end{DoxyParamCaption})}



Take the difference between two extended-\/fixed-\/point numbers (E\+F\+P1 -\/ E\+F\+P2) and return the result as a real number. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em efp1} & The first extended fixed point number \\
\hline
\mbox{\texttt{ in}}  & {\em efp2} & The extended fixed point number being subtracted from the first extended fixed point number \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The real result 
\end{DoxyReturn}


Definition at line 751 of file M\+O\+M\+\_\+coms.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{751   \textcolor{keywordtype}{type}(EFP\_type), \textcolor{keywordtype}{intent(in)} :: EFP1\textcolor{comment}{  !< The first extended fixed point number}}
\DoxyCodeLine{752   \textcolor{keywordtype}{type}(EFP\_type), \textcolor{keywordtype}{intent(in)} :: EFP2\textcolor{comment}{  !< The extended fixed point number being}}
\DoxyCodeLine{753 \textcolor{comment}{                        !! subtracted from the first extended fixed point number}}
\DoxyCodeLine{754 \textcolor{keywordtype}{  real} :: EFP\_real\_diff\textcolor{comment}{ !< The real result}}
\DoxyCodeLine{755 }
\DoxyCodeLine{756   \textcolor{keywordtype}{type}(EFP\_type)             :: EFP\_diff}
\DoxyCodeLine{757 }
\DoxyCodeLine{758   efp\_diff = efp1 -\/ efp2}
\DoxyCodeLine{759   efp\_real\_diff = efp\_to\_real(efp\_diff)}
\DoxyCodeLine{760 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__coms_a4aaf51b372bcaf7b46939145577eff92}\label{namespacemom__coms_a4aaf51b372bcaf7b46939145577eff92}} 
\index{mom\_coms@{mom\_coms}!efp\_to\_real@{efp\_to\_real}}
\index{efp\_to\_real@{efp\_to\_real}!mom\_coms@{mom\_coms}}
\doxysubsubsection{\texorpdfstring{efp\_to\_real()}{efp\_to\_real()}}
{\footnotesize\ttfamily real function, public mom\+\_\+coms\+::efp\+\_\+to\+\_\+real (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}), intent(inout)}]{E\+F\+P1 }\end{DoxyParamCaption})}



Return the real number that an extended-\/fixed-\/point number corresponds with. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em efp1} & The extended fixed point number being converted \\
\hline
\end{DoxyParams}


Definition at line 741 of file M\+O\+M\+\_\+coms.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{741   \textcolor{keywordtype}{type}(EFP\_type), \textcolor{keywordtype}{intent(inout)} :: EFP1\textcolor{comment}{ !< The extended fixed point number being converted}}
\DoxyCodeLine{742 \textcolor{keywordtype}{  real} :: EFP\_to\_real}
\DoxyCodeLine{743 }
\DoxyCodeLine{744   \textcolor{keyword}{call }regularize\_ints(efp1\%v)}
\DoxyCodeLine{745   efp\_to\_real = ints\_to\_real(efp1\%v)}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__coms_aa6ad80e8330fc146562404a4e756916b}\label{namespacemom__coms_aa6ad80e8330fc146562404a4e756916b}} 
\index{mom\_coms@{mom\_coms}!efp\_val\_sum\_across\_pes@{efp\_val\_sum\_across\_pes}}
\index{efp\_val\_sum\_across\_pes@{efp\_val\_sum\_across\_pes}!mom\_coms@{mom\_coms}}
\doxysubsubsection{\texorpdfstring{efp\_val\_sum\_across\_pes()}{efp\_val\_sum\_across\_pes()}}
{\footnotesize\ttfamily subroutine mom\+\_\+coms\+::efp\+\_\+val\+\_\+sum\+\_\+across\+\_\+pes (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}), intent(inout)}]{E\+FP,  }\item[{logical, intent(out), optional}]{error }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine does a sum across P\+Es of an E\+FP variable, returning the sums in place, with all overflows carried. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em efp} & The extended fixed point numbers being summed across P\+Es. \\
\hline
\mbox{\texttt{ out}}  & {\em error} & An error flag for this sum \\
\hline
\end{DoxyParams}


Definition at line 839 of file M\+O\+M\+\_\+coms.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{839   \textcolor{keywordtype}{type}(EFP\_type),  \textcolor{keywordtype}{intent(inout)} :: EFP\textcolor{comment}{   !< The extended fixed point numbers}}
\DoxyCodeLine{840 \textcolor{comment}{                                          !! being summed across PEs.}}
\DoxyCodeLine{841   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: error\textcolor{comment}{ !< An error flag for this sum}}
\DoxyCodeLine{842 }
\DoxyCodeLine{843   \textcolor{comment}{!   This subroutine does a sum across PEs of a list of EFP variables,}}
\DoxyCodeLine{844   \textcolor{comment}{! returning the sums in place, with all overflows carried.}}
\DoxyCodeLine{845 }
\DoxyCodeLine{846   \textcolor{keywordtype}{integer(kind=8)}, \textcolor{keywordtype}{dimension(ni)} :: ints}
\DoxyCodeLine{847   \textcolor{keywordtype}{integer(kind=8)} :: prec\_error}
\DoxyCodeLine{848   \textcolor{keywordtype}{logical} :: error\_found}
\DoxyCodeLine{849   \textcolor{keywordtype}{character(len=256)} :: mesg}
\DoxyCodeLine{850   \textcolor{keywordtype}{integer} :: n}
\DoxyCodeLine{851 }
\DoxyCodeLine{852   \textcolor{keywordflow}{if} (num\_pes() > max\_count\_prec) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{853     \textcolor{stringliteral}{"reproducing\_sum: Too many processors are being used for the value of "}//\&}
\DoxyCodeLine{854     \textcolor{stringliteral}{"prec.  Reduce prec to (2\string^63-\/1)/num\_PEs."})}
\DoxyCodeLine{855 }
\DoxyCodeLine{856   prec\_error = (2\_8**62 + (2\_8**62 -\/ 1)) / num\_pes()}
\DoxyCodeLine{857   \textcolor{comment}{! overflow\_error is an overflow error flag for the whole module.}}
\DoxyCodeLine{858   overflow\_error = .false. ; error\_found = .false.}
\DoxyCodeLine{859 }
\DoxyCodeLine{860   \textcolor{keywordflow}{do} n=1,ni ; ints(n) = efp\%v(n) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{861 }
\DoxyCodeLine{862   \textcolor{keyword}{call }sum\_across\_pes(ints(:), ni)}
\DoxyCodeLine{863 }
\DoxyCodeLine{864   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(error)) error = .false.}
\DoxyCodeLine{865 }
\DoxyCodeLine{866   overflow\_error = .false.}
\DoxyCodeLine{867   \textcolor{keyword}{call }carry\_overflow(ints(:), prec\_error)}
\DoxyCodeLine{868   \textcolor{keywordflow}{do} n=1,ni ; efp\%v(n) = ints(n) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{869   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(error)) error = overflow\_error}
\DoxyCodeLine{870   \textcolor{keywordflow}{if} (overflow\_error) \textcolor{keywordflow}{then}}
\DoxyCodeLine{871     \textcolor{keyword}{write} (mesg,\textcolor{stringliteral}{'("EFP\_val\_sum\_across\_PEs error val was ",ES12.6, ", prec\_error = ",ES12.6)'}) \&}
\DoxyCodeLine{872            efp\_to\_real(efp), real(prec\_error)}
\DoxyCodeLine{873     \textcolor{keyword}{call }mom\_error(warning, mesg)}
\DoxyCodeLine{874 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{875   error\_found = error\_found .or. overflow\_error}
\DoxyCodeLine{876 }
\DoxyCodeLine{877   \textcolor{keywordflow}{if} (error\_found .and. .not.(\textcolor{keyword}{present}(error))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{878     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Overflow in EFP\_val\_sum\_across\_PEs."})}
\DoxyCodeLine{879 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{880 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__coms_a8228dee8e8e72652d5a58f483f0dc661}\label{namespacemom__coms_a8228dee8e8e72652d5a58f483f0dc661}} 
\index{mom\_coms@{mom\_coms}!increment\_ints@{increment\_ints}}
\index{increment\_ints@{increment\_ints}!mom\_coms@{mom\_coms}}
\doxysubsubsection{\texorpdfstring{increment\_ints()}{increment\_ints()}}
{\footnotesize\ttfamily subroutine mom\+\_\+coms\+::increment\+\_\+ints (\begin{DoxyParamCaption}\item[{integer(kind=8), dimension(\mbox{\hyperlink{namespacemom__coms_ac1760c24e671a314322e4b1b33e0db39}{ni}}), intent(inout)}]{int\+\_\+sum,  }\item[{integer(kind=8), dimension(\mbox{\hyperlink{namespacemom__coms_ac1760c24e671a314322e4b1b33e0db39}{ni}}), intent(in)}]{int2,  }\item[{integer(kind=8), intent(in), optional}]{prec\+\_\+error }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Increment an array of integers that constitutes an extended-\/fixed-\/point representation with a another E\+FP number. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em int\+\_\+sum} & The array of E\+FP integers being incremented \\
\hline
\mbox{\texttt{ in}}  & {\em int2} & The array of E\+FP integers being added \\
\hline
\mbox{\texttt{ in}}  & {\em prec\+\_\+error} & The P\+E-\/count dependent precision of the integers that is safe from overflows during global sums. This will be larger than the compile-\/time precision parameter, and is used to detect overflows. \\
\hline
\end{DoxyParams}


Definition at line 563 of file M\+O\+M\+\_\+coms.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{563   \textcolor{keywordtype}{integer(kind=8)}, \textcolor{keywordtype}{dimension(ni)}, \textcolor{keywordtype}{intent(inout)} :: int\_sum\textcolor{comment}{ !< The array of EFP integers being incremented}}
\DoxyCodeLine{564   \textcolor{keywordtype}{integer(kind=8)}, \textcolor{keywordtype}{dimension(ni)}, \textcolor{keywordtype}{intent(in)}    :: int2\textcolor{comment}{    !< The array of EFP integers being added}}
\DoxyCodeLine{565   \textcolor{keywordtype}{integer(kind=8)}, \textcolor{keywordtype}{optional},      \textcolor{keywordtype}{intent(in)}    :: prec\_error\textcolor{comment}{ !< The PE-\/count dependent precision of the}}
\DoxyCodeLine{566 \textcolor{comment}{                                              !! integers that is safe from overflows during global}}
\DoxyCodeLine{567 \textcolor{comment}{                                              !! sums.  This will be larger than the compile-\/time}}
\DoxyCodeLine{568 \textcolor{comment}{                                              !! precision parameter, and is used to detect overflows.}}
\DoxyCodeLine{569 }
\DoxyCodeLine{570   \textcolor{comment}{! This subroutine increments a number with another, both using the integer}}
\DoxyCodeLine{571   \textcolor{comment}{! representation in real\_to\_ints.}}
\DoxyCodeLine{572   \textcolor{keywordtype}{integer} :: i}
\DoxyCodeLine{573 }
\DoxyCodeLine{574   \textcolor{keywordflow}{do} i=ni,2,-\/1}
\DoxyCodeLine{575     int\_sum(i) = int\_sum(i) + int2(i)}
\DoxyCodeLine{576     \textcolor{comment}{! Carry the local overflow.}}
\DoxyCodeLine{577     \textcolor{keywordflow}{if} (int\_sum(i) > prec) \textcolor{keywordflow}{then}}
\DoxyCodeLine{578       int\_sum(i) = int\_sum(i) -\/ prec}
\DoxyCodeLine{579       int\_sum(i-\/1) = int\_sum(i-\/1) + 1}
\DoxyCodeLine{580     \textcolor{keywordflow}{elseif} (int\_sum(i) < -\/prec) \textcolor{keywordflow}{then}}
\DoxyCodeLine{581       int\_sum(i) = int\_sum(i) + prec}
\DoxyCodeLine{582       int\_sum(i-\/1) = int\_sum(i-\/1) -\/ 1}
\DoxyCodeLine{583 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{584 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{585   int\_sum(1) = int\_sum(1) + int2(1)}
\DoxyCodeLine{586   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(prec\_error)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{587     \textcolor{keywordflow}{if} (abs(int\_sum(1)) > prec\_error) overflow\_error = .true.}
\DoxyCodeLine{588   \textcolor{keywordflow}{else}}
\DoxyCodeLine{589     \textcolor{keywordflow}{if} (abs(int\_sum(1)) > prec) overflow\_error = .true.}
\DoxyCodeLine{590 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{591 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__coms_aebe91f9c9bd6de5e9523c1f663e8a04d}\label{namespacemom__coms_aebe91f9c9bd6de5e9523c1f663e8a04d}} 
\index{mom\_coms@{mom\_coms}!increment\_ints\_faster@{increment\_ints\_faster}}
\index{increment\_ints\_faster@{increment\_ints\_faster}!mom\_coms@{mom\_coms}}
\doxysubsubsection{\texorpdfstring{increment\_ints\_faster()}{increment\_ints\_faster()}}
{\footnotesize\ttfamily subroutine mom\+\_\+coms\+::increment\+\_\+ints\+\_\+faster (\begin{DoxyParamCaption}\item[{integer(kind=8), dimension(\mbox{\hyperlink{namespacemom__coms_ac1760c24e671a314322e4b1b33e0db39}{ni}}), intent(inout)}]{int\+\_\+sum,  }\item[{real, intent(in)}]{r,  }\item[{real, intent(inout)}]{max\+\_\+mag\+\_\+term }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Increment an E\+FP number with a real number without doing any carrying of of overflows and using only minimal error checking. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em int\+\_\+sum} & The array of E\+FP integers being incremented \\
\hline
\mbox{\texttt{ in}}  & {\em r} & The real number being added. \\
\hline
\mbox{\texttt{ in,out}}  & {\em max\+\_\+mag\+\_\+term} & A running maximum magnitude of the r\textquotesingle{}s. \\
\hline
\end{DoxyParams}


Definition at line 597 of file M\+O\+M\+\_\+coms.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{597   \textcolor{keywordtype}{integer(kind=8)}, \textcolor{keywordtype}{dimension(ni)}, \textcolor{keywordtype}{intent(inout)} :: int\_sum\textcolor{comment}{  !< The array of EFP integers being incremented}}
\DoxyCodeLine{598 \textcolor{keywordtype}{  real},                           \textcolor{keywordtype}{intent(in)}    :: r\textcolor{comment}{        !< The real number being added.}}
\DoxyCodeLine{599 \textcolor{keywordtype}{  real},                           \textcolor{keywordtype}{intent(inout)} :: max\_mag\_term\textcolor{comment}{ !< A running maximum magnitude of the r's.}}
\DoxyCodeLine{600 }
\DoxyCodeLine{601   \textcolor{comment}{! This subroutine increments a number with another, both using the integer}}
\DoxyCodeLine{602   \textcolor{comment}{! representation in real\_to\_ints, but without doing any carrying of overflow.}}
\DoxyCodeLine{603   \textcolor{comment}{! The entire operation is embedded in a single call for greater speed.}}
\DoxyCodeLine{604 \textcolor{keywordtype}{  real} :: rs}
\DoxyCodeLine{605   \textcolor{keywordtype}{integer(kind=8)} :: ival}
\DoxyCodeLine{606   \textcolor{keywordtype}{integer} :: sgn, i}
\DoxyCodeLine{607 }
\DoxyCodeLine{608   \textcolor{keywordflow}{if} ((r >= 1e30) .eqv. (r < 1e30)) \textcolor{keywordflow}{then} ; nan\_error = .true. ; \textcolor{keywordflow}{return} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{609   sgn = 1 ; \textcolor{keywordflow}{if} (r<0.0) sgn = -\/1}
\DoxyCodeLine{610   rs = abs(r)}
\DoxyCodeLine{611   \textcolor{keywordflow}{if} (rs > abs(max\_mag\_term)) max\_mag\_term = r}
\DoxyCodeLine{612 }
\DoxyCodeLine{613   \textcolor{comment}{! Abort if the number has no EFP representation}}
\DoxyCodeLine{614   \textcolor{keywordflow}{if} (rs > max\_efp\_float) \textcolor{keywordflow}{then}}
\DoxyCodeLine{615     overflow\_error = .true.}
\DoxyCodeLine{616     \textcolor{keywordflow}{return}}
\DoxyCodeLine{617 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{618 }
\DoxyCodeLine{619   \textcolor{keywordflow}{do} i=1,ni}
\DoxyCodeLine{620     ival = int(rs*i\_pr(i), 8)}
\DoxyCodeLine{621     rs = rs -\/ ival*pr(i)}
\DoxyCodeLine{622     int\_sum(i) = int\_sum(i) + sgn*ival}
\DoxyCodeLine{623 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{624 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__coms_a24ac5b7cc37b1498f23b61eea03fb8c3}\label{namespacemom__coms_a24ac5b7cc37b1498f23b61eea03fb8c3}} 
\index{mom\_coms@{mom\_coms}!ints\_to\_real@{ints\_to\_real}}
\index{ints\_to\_real@{ints\_to\_real}!mom\_coms@{mom\_coms}}
\doxysubsubsection{\texorpdfstring{ints\_to\_real()}{ints\_to\_real()}}
{\footnotesize\ttfamily real function mom\+\_\+coms\+::ints\+\_\+to\+\_\+real (\begin{DoxyParamCaption}\item[{integer(kind=8), dimension(\mbox{\hyperlink{namespacemom__coms_ac1760c24e671a314322e4b1b33e0db39}{ni}}), intent(in)}]{ints }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Convert the array of integers that constitute an extended-\/fixed-\/point representation into a real number. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em ints} & The array of E\+FP integers \\
\hline
\end{DoxyParams}


Definition at line 550 of file M\+O\+M\+\_\+coms.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{550   \textcolor{keywordtype}{integer(kind=8)}, \textcolor{keywordtype}{dimension(ni)}, \textcolor{keywordtype}{intent(in)} :: ints\textcolor{comment}{ !< The array of EFP integers}}
\DoxyCodeLine{551 \textcolor{keywordtype}{  real} :: r}
\DoxyCodeLine{552   \textcolor{comment}{! This subroutine reverses the conversion in real\_to\_ints.}}
\DoxyCodeLine{553 }
\DoxyCodeLine{554   \textcolor{keywordtype}{integer} :: i}
\DoxyCodeLine{555 }
\DoxyCodeLine{556   r = 0.0}
\DoxyCodeLine{557   \textcolor{keywordflow}{do} i=1,ni ; r = r + pr(i)*ints(i) ;\textcolor{keywordflow}{ enddo}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__coms_ac8f1b5be23b128cd8bb956ebda917edb}\label{namespacemom__coms_ac8f1b5be23b128cd8bb956ebda917edb}} 
\index{mom\_coms@{mom\_coms}!real\_to\_efp@{real\_to\_efp}}
\index{real\_to\_efp@{real\_to\_efp}!mom\_coms@{mom\_coms}}
\doxysubsubsection{\texorpdfstring{real\_to\_efp()}{real\_to\_efp()}}
{\footnotesize\ttfamily type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}) function, public mom\+\_\+coms\+::real\+\_\+to\+\_\+efp (\begin{DoxyParamCaption}\item[{real, intent(in)}]{val,  }\item[{logical, intent(inout), optional}]{overflow }\end{DoxyParamCaption})}



Return the extended-\/fixed-\/point number that a real number corresponds with. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em val} & The real number being converted \\
\hline
\mbox{\texttt{ in,out}}  & {\em overflow} & Returns true if the conversion is being done on a value that is too large to be represented \\
\hline
\end{DoxyParams}


Definition at line 765 of file M\+O\+M\+\_\+coms.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{765 \textcolor{keywordtype}{  real},              \textcolor{keywordtype}{intent(in)}    :: val\textcolor{comment}{ !< The real number being converted}}
\DoxyCodeLine{766   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: overflow\textcolor{comment}{ !< Returns true if the conversion is being}}
\DoxyCodeLine{767 \textcolor{comment}{                                          !! done on a value that is too large to be represented}}
\DoxyCodeLine{768   \textcolor{keywordtype}{type}(EFP\_type) :: real\_to\_EFP}
\DoxyCodeLine{769 }
\DoxyCodeLine{770   \textcolor{keywordtype}{logical} :: over}
\DoxyCodeLine{771   \textcolor{keywordtype}{character(len=80)} :: mesg}
\DoxyCodeLine{772 }
\DoxyCodeLine{773   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(overflow)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{774     real\_to\_efp\%v(:) = real\_to\_ints(val, overflow=overflow)}
\DoxyCodeLine{775   \textcolor{keywordflow}{else}}
\DoxyCodeLine{776     over = .false.}
\DoxyCodeLine{777     real\_to\_efp\%v(:) = real\_to\_ints(val, overflow=over)}
\DoxyCodeLine{778     \textcolor{keywordflow}{if} (over) \textcolor{keywordflow}{then}}
\DoxyCodeLine{779       \textcolor{keyword}{write}(mesg, \textcolor{stringliteral}{'(ES13.5)'}) val}
\DoxyCodeLine{780       \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"Overflow in real\_to\_EFP conversion of "}//trim(mesg))}
\DoxyCodeLine{781 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{782 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{783 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__coms_a0cc261620495abf3313937726883b95e}\label{namespacemom__coms_a0cc261620495abf3313937726883b95e}} 
\index{mom\_coms@{mom\_coms}!real\_to\_ints@{real\_to\_ints}}
\index{real\_to\_ints@{real\_to\_ints}!mom\_coms@{mom\_coms}}
\doxysubsubsection{\texorpdfstring{real\_to\_ints()}{real\_to\_ints()}}
{\footnotesize\ttfamily integer(kind=8) function, dimension(\mbox{\hyperlink{namespacemom__coms_ac1760c24e671a314322e4b1b33e0db39}{ni}}) mom\+\_\+coms\+::real\+\_\+to\+\_\+ints (\begin{DoxyParamCaption}\item[{real, intent(in)}]{r,  }\item[{integer(kind=8), intent(in), optional}]{prec\+\_\+error,  }\item[{logical, intent(inout), optional}]{overflow }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Convert a real number into the array of integers constitute its extended-\/fixed-\/point representation. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em r} & The real number being converted \\
\hline
\mbox{\texttt{ in}}  & {\em prec\+\_\+error} & The P\+E-\/count dependent precision of the integers that is safe from overflows during global sums. This will be larger than the compile-\/time precision parameter, and is used to detect overflows. \\
\hline
\mbox{\texttt{ in,out}}  & {\em overflow} & Returns true if the conversion is being done on a value that is too large to be represented \\
\hline
\end{DoxyParams}


Definition at line 508 of file M\+O\+M\+\_\+coms.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{508 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in)} :: r\textcolor{comment}{  !< The real number being converted}}
\DoxyCodeLine{509   \textcolor{keywordtype}{integer(kind=8)}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: prec\_error\textcolor{comment}{  !< The PE-\/count dependent precision of the}}
\DoxyCodeLine{510 \textcolor{comment}{                                              !! integers that is safe from overflows during global}}
\DoxyCodeLine{511 \textcolor{comment}{                                              !! sums.  This will be larger than the compile-\/time}}
\DoxyCodeLine{512 \textcolor{comment}{                                              !! precision parameter, and is used to detect overflows.}}
\DoxyCodeLine{513   \textcolor{keywordtype}{logical},         \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: overflow\textcolor{comment}{ !< Returns true if the conversion is being}}
\DoxyCodeLine{514 \textcolor{comment}{                                              !! done on a value that is too large to be represented}}
\DoxyCodeLine{515   \textcolor{keywordtype}{integer(kind=8)}, \textcolor{keywordtype}{dimension(ni)}  :: ints}
\DoxyCodeLine{516   \textcolor{comment}{!   This subroutine converts a real number to an equivalent representation}}
\DoxyCodeLine{517   \textcolor{comment}{! using several long integers.}}
\DoxyCodeLine{518 }
\DoxyCodeLine{519 \textcolor{keywordtype}{  real} :: rs}
\DoxyCodeLine{520   \textcolor{keywordtype}{character(len=80)} :: mesg}
\DoxyCodeLine{521   \textcolor{keywordtype}{integer(kind=8)} :: ival, prec\_err}
\DoxyCodeLine{522   \textcolor{keywordtype}{integer} :: sgn, i}
\DoxyCodeLine{523 }
\DoxyCodeLine{524   prec\_err = prec ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(prec\_error)) prec\_err = prec\_error}
\DoxyCodeLine{525   ints(:) = 0\_8}
\DoxyCodeLine{526   \textcolor{keywordflow}{if} ((r >= 1e30) .eqv. (r < 1e30)) \textcolor{keywordflow}{then} ; nan\_error = .true. ; \textcolor{keywordflow}{return} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{527 }
\DoxyCodeLine{528   sgn = 1 ; \textcolor{keywordflow}{if} (r<0.0) sgn = -\/1}
\DoxyCodeLine{529   rs = abs(r)}
\DoxyCodeLine{530 }
\DoxyCodeLine{531   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(overflow)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{532     \textcolor{keywordflow}{if} (.not.(rs < prec\_err*pr(1))) overflow = .true.}
\DoxyCodeLine{533     \textcolor{keywordflow}{if} ((r >= 1e30) .eqv. (r < 1e30)) overflow = .true.}
\DoxyCodeLine{534   \textcolor{keywordflow}{elseif} (.not.(rs < prec\_err*pr(1))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{535     \textcolor{keyword}{write}(mesg, \textcolor{stringliteral}{'(ES13.5)'}) r}
\DoxyCodeLine{536     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"Overflow in real\_to\_ints conversion of "}//trim(mesg))}
\DoxyCodeLine{537 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{538 }
\DoxyCodeLine{539   \textcolor{keywordflow}{do} i=1,ni}
\DoxyCodeLine{540     ival = int(rs*i\_pr(i), 8)}
\DoxyCodeLine{541     rs = rs -\/ ival*pr(i)}
\DoxyCodeLine{542     ints(i) = sgn*ival}
\DoxyCodeLine{543 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{544 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__coms_ab8feff19e782af36bb7ccccd5ba9eddc}\label{namespacemom__coms_ab8feff19e782af36bb7ccccd5ba9eddc}} 
\index{mom\_coms@{mom\_coms}!regularize\_ints@{regularize\_ints}}
\index{regularize\_ints@{regularize\_ints}!mom\_coms@{mom\_coms}}
\doxysubsubsection{\texorpdfstring{regularize\_ints()}{regularize\_ints()}}
{\footnotesize\ttfamily subroutine mom\+\_\+coms\+::regularize\+\_\+ints (\begin{DoxyParamCaption}\item[{integer(kind=8), dimension(\mbox{\hyperlink{namespacemom__coms_ac1760c24e671a314322e4b1b33e0db39}{ni}}), intent(inout)}]{int\+\_\+sum }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine carries the overflow, and then makes sure that all integers are of the same sign as the overall value. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em int\+\_\+sum} & The array of integers being modified to take a \\
\hline
\end{DoxyParams}


Definition at line 653 of file M\+O\+M\+\_\+coms.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{653   \textcolor{keywordtype}{integer(kind=8)}, \textcolor{keywordtype}{dimension(ni)}, \&}
\DoxyCodeLine{654     \textcolor{keywordtype}{intent(inout)} :: int\_sum\textcolor{comment}{ !< The array of integers being modified to take a}}
\DoxyCodeLine{655 \textcolor{comment}{                             !! regular form with all integers of the same sign,}}
\DoxyCodeLine{656 \textcolor{comment}{                             !! but without changing value.}}
\DoxyCodeLine{657 }
\DoxyCodeLine{658   \textcolor{comment}{! This subroutine carries the overflow, and then makes sure that}}
\DoxyCodeLine{659   \textcolor{comment}{! all integers are of the same sign as the overall value.}}
\DoxyCodeLine{660   \textcolor{keywordtype}{logical} :: positive}
\DoxyCodeLine{661   \textcolor{keywordtype}{integer} :: i, num\_carry}
\DoxyCodeLine{662 }
\DoxyCodeLine{663   \textcolor{keywordflow}{do} i=ni,2,-\/1 ; \textcolor{keywordflow}{if} (abs(int\_sum(i)) >= prec) \textcolor{keywordflow}{then}}
\DoxyCodeLine{664     num\_carry = int(int\_sum(i) * i\_prec)}
\DoxyCodeLine{665     int\_sum(i) = int\_sum(i) -\/ num\_carry*prec}
\DoxyCodeLine{666     int\_sum(i-\/1) = int\_sum(i-\/1) + num\_carry}
\DoxyCodeLine{667 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{668 }
\DoxyCodeLine{669   \textcolor{comment}{! Determine the sign of the final number.}}
\DoxyCodeLine{670   positive = .true.}
\DoxyCodeLine{671   \textcolor{keywordflow}{do} i=1,ni}
\DoxyCodeLine{672     \textcolor{keywordflow}{if} (abs(int\_sum(i)) > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{673       \textcolor{keywordflow}{if} (int\_sum(i) < 0) positive = .false.}
\DoxyCodeLine{674       \textcolor{keywordflow}{exit}}
\DoxyCodeLine{675 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{676 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{677 }
\DoxyCodeLine{678   \textcolor{keywordflow}{if} (positive) \textcolor{keywordflow}{then}}
\DoxyCodeLine{679     \textcolor{keywordflow}{do} i=ni,2,-\/1 ; \textcolor{keywordflow}{if} (int\_sum(i) < 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{680       int\_sum(i) = int\_sum(i) + prec}
\DoxyCodeLine{681       int\_sum(i-\/1) = int\_sum(i-\/1) -\/ 1}
\DoxyCodeLine{682 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{683   \textcolor{keywordflow}{else}}
\DoxyCodeLine{684     \textcolor{keywordflow}{do} i=ni,2,-\/1 ; \textcolor{keywordflow}{if} (int\_sum(i) > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{685       int\_sum(i) = int\_sum(i) -\/ prec}
\DoxyCodeLine{686       int\_sum(i-\/1) = int\_sum(i-\/1) + 1}
\DoxyCodeLine{687 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{688 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{689 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__coms_a81eab26b0e062043ae4b13949d90a5dc}\label{namespacemom__coms_a81eab26b0e062043ae4b13949d90a5dc}} 
\index{mom\_coms@{mom\_coms}!reproducing\_efp\_sum\_2d@{reproducing\_efp\_sum\_2d}}
\index{reproducing\_efp\_sum\_2d@{reproducing\_efp\_sum\_2d}!mom\_coms@{mom\_coms}}
\doxysubsubsection{\texorpdfstring{reproducing\_efp\_sum\_2d()}{reproducing\_efp\_sum\_2d()}}
{\footnotesize\ttfamily type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}) function mom\+\_\+coms\+::reproducing\+\_\+efp\+\_\+sum\+\_\+2d (\begin{DoxyParamCaption}\item[{real, dimension(\+:,\+:), intent(in)}]{array,  }\item[{integer, intent(in), optional}]{isr,  }\item[{integer, intent(in), optional}]{ier,  }\item[{integer, intent(in), optional}]{jsr,  }\item[{integer, intent(in), optional}]{jer,  }\item[{logical, intent(in), optional}]{overflow\+\_\+check,  }\item[{integer, intent(out), optional}]{err,  }\item[{logical, intent(in), optional}]{only\+\_\+on\+\_\+\+PE }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine uses a conversion to an integer representation of real numbers to give an order-\/invariant sum of distributed 2-\/D arrays that reproduces across domain decomposition, with the result returned as an extended fixed point type that can be converted back to a real number using E\+F\+P\+\_\+to\+\_\+real. This technique is described in Hallberg \& Adcroft, 2014, Parallel Computing, doi\+:10.\+1016/j.parco.\+2014.\+04.\+007. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em array} & The array to be summed \\
\hline
\mbox{\texttt{ in}}  & {\em isr} & The starting i-\/index of the sum, noting that the array indices starts at 1 \\
\hline
\mbox{\texttt{ in}}  & {\em ier} & The ending i-\/index of the sum, noting that the array indices starts at 1 \\
\hline
\mbox{\texttt{ in}}  & {\em jsr} & The starting j-\/index of the sum, noting that the array indices starts at 1 \\
\hline
\mbox{\texttt{ in}}  & {\em jer} & The ending j-\/index of the sum, noting that the array indices starts at 1 \\
\hline
\mbox{\texttt{ in}}  & {\em overflow\+\_\+check} & If present and false, disable checking for overflows in incremental results. This can speed up calculations if the number of values being summed is small enough \\
\hline
\mbox{\texttt{ out}}  & {\em err} & If present, return an error code instead of triggering any fatal errors directly from this routine. \\
\hline
\mbox{\texttt{ in}}  & {\em only\+\_\+on\+\_\+pe} & If present and true, do not do the sum across processors, only reporting the local sum \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The result in extended fixed point format 
\end{DoxyReturn}


Definition at line 93 of file M\+O\+M\+\_\+coms.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{93 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},     \textcolor{keywordtype}{intent(in)}  :: array\textcolor{comment}{   !< The array to be summed}}
\DoxyCodeLine{94   \textcolor{keywordtype}{integer},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: isr\textcolor{comment}{     !< The starting i-\/index of the sum, noting}}
\DoxyCodeLine{95 \textcolor{comment}{                                                   !! that the array indices starts at 1}}
\DoxyCodeLine{96   \textcolor{keywordtype}{integer},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: ier\textcolor{comment}{     !< The ending i-\/index of the sum, noting}}
\DoxyCodeLine{97 \textcolor{comment}{                                                   !! that the array indices starts at 1}}
\DoxyCodeLine{98   \textcolor{keywordtype}{integer},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: jsr\textcolor{comment}{     !< The starting j-\/index of the sum, noting}}
\DoxyCodeLine{99 \textcolor{comment}{                                                   !! that the array indices starts at 1}}
\DoxyCodeLine{100   \textcolor{keywordtype}{integer},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: jer\textcolor{comment}{     !< The ending j-\/index of the sum, noting}}
\DoxyCodeLine{101 \textcolor{comment}{                                                   !! that the array indices starts at 1}}
\DoxyCodeLine{102   \textcolor{keywordtype}{logical},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: overflow\_check\textcolor{comment}{ !< If present and false, disable}}
\DoxyCodeLine{103 \textcolor{comment}{                                                !! checking for overflows in incremental results.}}
\DoxyCodeLine{104 \textcolor{comment}{                                                !! This can speed up calculations if the number}}
\DoxyCodeLine{105 \textcolor{comment}{                                                !! of values being summed is small enough}}
\DoxyCodeLine{106   \textcolor{keywordtype}{integer},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: err\textcolor{comment}{  !< If present, return an error code instead of}}
\DoxyCodeLine{107 \textcolor{comment}{                                                !! triggering any fatal errors directly from}}
\DoxyCodeLine{108 \textcolor{comment}{                                                !! this routine.}}
\DoxyCodeLine{109   \textcolor{keywordtype}{logical},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: only\_on\_PE\textcolor{comment}{ !< If present and true, do not do the sum}}
\DoxyCodeLine{110 \textcolor{comment}{                                                !! across processors, only reporting the local sum}}
\DoxyCodeLine{111   \textcolor{keywordtype}{type}(EFP\_type)                        :: EFP\_sum\textcolor{comment}{  !< The result in extended fixed point format}}
\DoxyCodeLine{112 }
\DoxyCodeLine{113   \textcolor{comment}{!   This subroutine uses a conversion to an integer representation}}
\DoxyCodeLine{114   \textcolor{comment}{! of real numbers to give order-\/invariant sums that will reproduce}}
\DoxyCodeLine{115   \textcolor{comment}{! across PE count.  This idea comes from R. Hallberg and A. Adcroft.}}
\DoxyCodeLine{116 }
\DoxyCodeLine{117   \textcolor{keywordtype}{integer(kind=8)}, \textcolor{keywordtype}{dimension(ni)}  :: ints\_sum}
\DoxyCodeLine{118   \textcolor{keywordtype}{integer(kind=8)} :: ival, prec\_error}
\DoxyCodeLine{119 \textcolor{keywordtype}{  real}    :: rs}
\DoxyCodeLine{120 \textcolor{keywordtype}{  real}    :: max\_mag\_term}
\DoxyCodeLine{121   \textcolor{keywordtype}{logical} :: over\_check, do\_sum\_across\_PEs}
\DoxyCodeLine{122   \textcolor{keywordtype}{character(len=256)} :: mesg}
\DoxyCodeLine{123   \textcolor{keywordtype}{integer} :: i, j, n, is, ie, js, je, sgn}
\DoxyCodeLine{124 }
\DoxyCodeLine{125   \textcolor{keywordflow}{if} (num\_pes() > max\_count\_prec) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{126     \textcolor{stringliteral}{"reproducing\_sum: Too many processors are being used for the value of "}//\&}
\DoxyCodeLine{127     \textcolor{stringliteral}{"prec.  Reduce prec to (2\string^63-\/1)/num\_PEs."})}
\DoxyCodeLine{128 }
\DoxyCodeLine{129   prec\_error = (2\_8**62 + (2\_8**62 -\/ 1)) / num\_pes()}
\DoxyCodeLine{130 }
\DoxyCodeLine{131   is = 1 ; ie = \textcolor{keyword}{size}(array,1) ; js = 1 ; je = \textcolor{keyword}{size}(array,2 )}
\DoxyCodeLine{132   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(isr)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{133     \textcolor{keywordflow}{if} (isr < is) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Value of isr too small in reproducing\_EFP\_sum\_2d."})}
\DoxyCodeLine{134     is = isr}
\DoxyCodeLine{135 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{136   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(ier)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{137     \textcolor{keywordflow}{if} (ier > ie) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Value of ier too large in reproducing\_EFP\_sum\_2d."})}
\DoxyCodeLine{138     ie = ier}
\DoxyCodeLine{139 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{140   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(jsr)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{141     \textcolor{keywordflow}{if} (jsr < js) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Value of jsr too small in reproducing\_EFP\_sum\_2d."})}
\DoxyCodeLine{142     js = jsr}
\DoxyCodeLine{143 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{144   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(jer)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{145     \textcolor{keywordflow}{if} (jer > je) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Value of jer too large in reproducing\_EFP\_sum\_2d."})}
\DoxyCodeLine{146     je = jer}
\DoxyCodeLine{147 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{148 }
\DoxyCodeLine{149   over\_check = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(overflow\_check)) over\_check = overflow\_check}
\DoxyCodeLine{150   do\_sum\_across\_pes = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(only\_on\_pe)) do\_sum\_across\_pes = .not.only\_on\_pe}
\DoxyCodeLine{151 }
\DoxyCodeLine{152   overflow\_error = .false. ; nan\_error = .false. ; max\_mag\_term = 0.0}
\DoxyCodeLine{153   ints\_sum(:) = 0}
\DoxyCodeLine{154   \textcolor{keywordflow}{if} (over\_check) \textcolor{keywordflow}{then}}
\DoxyCodeLine{155     \textcolor{keywordflow}{if} ((je+1-\/js)*(ie+1-\/is) < max\_count\_prec) \textcolor{keywordflow}{then}}
\DoxyCodeLine{156       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{157         \textcolor{keyword}{call }increment\_ints\_faster(ints\_sum, array(i,j), max\_mag\_term)}
\DoxyCodeLine{158 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{159       \textcolor{keyword}{call }carry\_overflow(ints\_sum, prec\_error)}
\DoxyCodeLine{160     \textcolor{keywordflow}{elseif} ((ie+1-\/is) < max\_count\_prec) \textcolor{keywordflow}{then}}
\DoxyCodeLine{161       \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{162         \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{163           \textcolor{keyword}{call }increment\_ints\_faster(ints\_sum, array(i,j), max\_mag\_term)}
\DoxyCodeLine{164 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{165         \textcolor{keyword}{call }carry\_overflow(ints\_sum, prec\_error)}
\DoxyCodeLine{166 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{167     \textcolor{keywordflow}{else}}
\DoxyCodeLine{168       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{169         \textcolor{keyword}{call }increment\_ints(ints\_sum, real\_to\_ints(array(i,j), prec\_error), \&}
\DoxyCodeLine{170                             prec\_error)}
\DoxyCodeLine{171 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{172 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{173   \textcolor{keywordflow}{else}}
\DoxyCodeLine{174     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{175       sgn = 1 ; \textcolor{keywordflow}{if} (array(i,j)<0.0) sgn = -\/1}
\DoxyCodeLine{176       rs = abs(array(i,j))}
\DoxyCodeLine{177       \textcolor{keywordflow}{do} n=1,ni}
\DoxyCodeLine{178         ival = int(rs*i\_pr(n), 8)}
\DoxyCodeLine{179         rs = rs -\/ ival*pr(n)}
\DoxyCodeLine{180         ints\_sum(n) = ints\_sum(n) + sgn*ival}
\DoxyCodeLine{181 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{182 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{183     \textcolor{keyword}{call }carry\_overflow(ints\_sum, prec\_error)}
\DoxyCodeLine{184 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{185 }
\DoxyCodeLine{186   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(err)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{187     err = 0}
\DoxyCodeLine{188     \textcolor{keywordflow}{if} (overflow\_error) \&}
\DoxyCodeLine{189       err = err+2}
\DoxyCodeLine{190     \textcolor{keywordflow}{if} (nan\_error) \&}
\DoxyCodeLine{191       err = err+4}
\DoxyCodeLine{192     \textcolor{keywordflow}{if} (err > 0) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} n=1,ni ; ints\_sum(n) = 0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{193   \textcolor{keywordflow}{else}}
\DoxyCodeLine{194     \textcolor{keywordflow}{if} (nan\_error) \textcolor{keywordflow}{then}}
\DoxyCodeLine{195       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"NaN in input field of reproducing\_EFP\_sum(\_2d)."})}
\DoxyCodeLine{196 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{197     \textcolor{keywordflow}{if} (abs(max\_mag\_term) >= prec\_error*pr(1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{198       \textcolor{keyword}{write}(mesg, \textcolor{stringliteral}{'(ES13.5)'}) max\_mag\_term}
\DoxyCodeLine{199       \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"Overflow in reproducing\_EFP\_sum(\_2d) conversion of "}//trim(mesg))}
\DoxyCodeLine{200 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{201     \textcolor{keywordflow}{if} (overflow\_error) \textcolor{keywordflow}{then}}
\DoxyCodeLine{202       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Overflow in reproducing\_EFP\_sum(\_2d)."})}
\DoxyCodeLine{203 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{204 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{205 }
\DoxyCodeLine{206   \textcolor{keywordflow}{if} (do\_sum\_across\_pes) \textcolor{keyword}{call }sum\_across\_pes(ints\_sum, ni)}
\DoxyCodeLine{207 }
\DoxyCodeLine{208   \textcolor{keyword}{call }regularize\_ints(ints\_sum)}
\DoxyCodeLine{209 }
\DoxyCodeLine{210   efp\_sum\%v(:) = ints\_sum(:)}
\DoxyCodeLine{211 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__coms_a82b35df61c7d0aba1712fc3ce7b47685}\label{namespacemom__coms_a82b35df61c7d0aba1712fc3ce7b47685}} 
\index{mom\_coms@{mom\_coms}!reproducing\_sum\_2d@{reproducing\_sum\_2d}}
\index{reproducing\_sum\_2d@{reproducing\_sum\_2d}!mom\_coms@{mom\_coms}}
\doxysubsubsection{\texorpdfstring{reproducing\_sum\_2d()}{reproducing\_sum\_2d()}}
{\footnotesize\ttfamily real function mom\+\_\+coms\+::reproducing\+\_\+sum\+\_\+2d (\begin{DoxyParamCaption}\item[{real, dimension(\+:,\+:), intent(in)}]{array,  }\item[{integer, intent(in), optional}]{isr,  }\item[{integer, intent(in), optional}]{ier,  }\item[{integer, intent(in), optional}]{jsr,  }\item[{integer, intent(in), optional}]{jer,  }\item[{type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}), intent(out), optional}]{E\+F\+P\+\_\+sum,  }\item[{logical, intent(in), optional}]{reproducing,  }\item[{logical, intent(in), optional}]{overflow\+\_\+check,  }\item[{integer, intent(out), optional}]{err,  }\item[{logical, intent(in), optional}]{only\+\_\+on\+\_\+\+PE }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine uses a conversion to an integer representation of real numbers to give an order-\/invariant sum of distributed 2-\/D arrays that reproduces across domain decomposition. This technique is described in Hallberg \& Adcroft, 2014, Parallel Computing, doi\+:10.\+1016/j.parco.\+2014.\+04.\+007. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em array} & The array to be summed \\
\hline
\mbox{\texttt{ in}}  & {\em isr} & The starting i-\/index of the sum, noting that the array indices starts at 1 \\
\hline
\mbox{\texttt{ in}}  & {\em ier} & The ending i-\/index of the sum, noting that the array indices starts at 1 \\
\hline
\mbox{\texttt{ in}}  & {\em jsr} & The starting j-\/index of the sum, noting that the array indices starts at 1 \\
\hline
\mbox{\texttt{ in}}  & {\em jer} & The ending j-\/index of the sum, noting that the array indices starts at 1 \\
\hline
\mbox{\texttt{ out}}  & {\em efp\+\_\+sum} & The result in extended fixed point format \\
\hline
\mbox{\texttt{ in}}  & {\em reproducing} & If present and false, do the sum using the naive non-\/reproducing approach \\
\hline
\mbox{\texttt{ in}}  & {\em overflow\+\_\+check} & If present and false, disable checking for overflows in incremental results. This can speed up calculations if the number of values being summed is small enough \\
\hline
\mbox{\texttt{ out}}  & {\em err} & If present, return an error code instead of triggering any fatal errors directly from this routine. \\
\hline
\mbox{\texttt{ in}}  & {\em only\+\_\+on\+\_\+pe} & If present and true, do not do the sum across processors, only reporting the local sum \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Result 
\end{DoxyReturn}


Definition at line 220 of file M\+O\+M\+\_\+coms.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{220 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},     \textcolor{keywordtype}{intent(in)}  :: array\textcolor{comment}{   !< The array to be summed}}
\DoxyCodeLine{221   \textcolor{keywordtype}{integer},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: isr\textcolor{comment}{     !< The starting i-\/index of the sum, noting}}
\DoxyCodeLine{222 \textcolor{comment}{                                                   !! that the array indices starts at 1}}
\DoxyCodeLine{223   \textcolor{keywordtype}{integer},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: ier\textcolor{comment}{     !< The ending i-\/index of the sum, noting}}
\DoxyCodeLine{224 \textcolor{comment}{                                                   !! that the array indices starts at 1}}
\DoxyCodeLine{225   \textcolor{keywordtype}{integer},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: jsr\textcolor{comment}{     !< The starting j-\/index of the sum, noting}}
\DoxyCodeLine{226 \textcolor{comment}{                                                   !! that the array indices starts at 1}}
\DoxyCodeLine{227   \textcolor{keywordtype}{integer},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: jer\textcolor{comment}{     !< The ending j-\/index of the sum, noting}}
\DoxyCodeLine{228 \textcolor{comment}{                                                   !! that the array indices starts at 1}}
\DoxyCodeLine{229   \textcolor{keywordtype}{type}(EFP\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: EFP\_sum\textcolor{comment}{  !< The result in extended fixed point format}}
\DoxyCodeLine{230   \textcolor{keywordtype}{logical},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: reproducing\textcolor{comment}{ !< If present and false, do the sum}}
\DoxyCodeLine{231 \textcolor{comment}{                                                !! using the naive non-\/reproducing approach}}
\DoxyCodeLine{232   \textcolor{keywordtype}{logical},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: overflow\_check\textcolor{comment}{ !< If present and false, disable}}
\DoxyCodeLine{233 \textcolor{comment}{                                                !! checking for overflows in incremental results.}}
\DoxyCodeLine{234 \textcolor{comment}{                                                !! This can speed up calculations if the number}}
\DoxyCodeLine{235 \textcolor{comment}{                                                !! of values being summed is small enough}}
\DoxyCodeLine{236   \textcolor{keywordtype}{integer},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: err\textcolor{comment}{  !< If present, return an error code instead of}}
\DoxyCodeLine{237 \textcolor{comment}{                                                !! triggering any fatal errors directly from}}
\DoxyCodeLine{238 \textcolor{comment}{                                                !! this routine.}}
\DoxyCodeLine{239   \textcolor{keywordtype}{logical},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: only\_on\_PE\textcolor{comment}{ !< If present and true, do not do the sum}}
\DoxyCodeLine{240 \textcolor{comment}{                                                !! across processors, only reporting the local sum}}
\DoxyCodeLine{241 \textcolor{keywordtype}{  real}                                  :: sum\textcolor{comment}{  !< Result}}
\DoxyCodeLine{242 }
\DoxyCodeLine{243   \textcolor{comment}{!   This subroutine uses a conversion to an integer representation}}
\DoxyCodeLine{244   \textcolor{comment}{! of real numbers to give order-\/invariant sums that will reproduce}}
\DoxyCodeLine{245   \textcolor{comment}{! across PE count.  This idea comes from R. Hallberg and A. Adcroft.}}
\DoxyCodeLine{246 }
\DoxyCodeLine{247   \textcolor{keywordtype}{integer(kind=8)}, \textcolor{keywordtype}{dimension(ni)}  :: ints\_sum}
\DoxyCodeLine{248   \textcolor{keywordtype}{integer(kind=8)} :: prec\_error}
\DoxyCodeLine{249 \textcolor{keywordtype}{  real}    :: rsum(1), rs}
\DoxyCodeLine{250   \textcolor{keywordtype}{logical} :: repro, do\_sum\_across\_PEs}
\DoxyCodeLine{251   \textcolor{keywordtype}{character(len=256)} :: mesg}
\DoxyCodeLine{252   \textcolor{keywordtype}{type}(EFP\_type) :: EFP\_val \textcolor{comment}{! An extended fixed point version of the sum}}
\DoxyCodeLine{253   \textcolor{keywordtype}{integer} :: i, j, n, is, ie, js, je}
\DoxyCodeLine{254 }
\DoxyCodeLine{255   \textcolor{keywordflow}{if} (num\_pes() > max\_count\_prec) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{256     \textcolor{stringliteral}{"reproducing\_sum: Too many processors are being used for the value of "}//\&}
\DoxyCodeLine{257     \textcolor{stringliteral}{"prec.  Reduce prec to (2\string^63-\/1)/num\_PEs."})}
\DoxyCodeLine{258 }
\DoxyCodeLine{259   prec\_error = (2\_8**62 + (2\_8**62 -\/ 1)) / num\_pes()}
\DoxyCodeLine{260 }
\DoxyCodeLine{261   is = 1 ; ie = \textcolor{keyword}{size}(array,1) ; js = 1 ; je = \textcolor{keyword}{size}(array,2 )}
\DoxyCodeLine{262   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(isr)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{263     \textcolor{keywordflow}{if} (isr < is) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Value of isr too small in reproducing\_sum\_2d."})}
\DoxyCodeLine{264     is = isr}
\DoxyCodeLine{265 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{266   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(ier)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{267     \textcolor{keywordflow}{if} (ier > ie) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Value of ier too large in reproducing\_sum\_2d."})}
\DoxyCodeLine{268     ie = ier}
\DoxyCodeLine{269 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{270   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(jsr)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{271     \textcolor{keywordflow}{if} (jsr < js) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Value of jsr too small in reproducing\_sum\_2d."})}
\DoxyCodeLine{272     js = jsr}
\DoxyCodeLine{273 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{274   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(jer)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{275     \textcolor{keywordflow}{if} (jer > je) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Value of jer too large in reproducing\_sum\_2d."})}
\DoxyCodeLine{276     je = jer}
\DoxyCodeLine{277 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{278 }
\DoxyCodeLine{279   repro = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(reproducing)) repro = reproducing}
\DoxyCodeLine{280   do\_sum\_across\_pes = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(only\_on\_pe)) do\_sum\_across\_pes = .not.only\_on\_pe}
\DoxyCodeLine{281 }
\DoxyCodeLine{282   \textcolor{keywordflow}{if} (repro) \textcolor{keywordflow}{then}}
\DoxyCodeLine{283     efp\_val = reproducing\_efp\_sum\_2d(array, isr, ier, jsr, jer, overflow\_check, err, only\_on\_pe)}
\DoxyCodeLine{284     sum = ints\_to\_real(efp\_val\%v)}
\DoxyCodeLine{285     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(efp\_sum)) efp\_sum = efp\_val}
\DoxyCodeLine{286     \textcolor{keywordflow}{if} (debug) ints\_sum(:) = efp\_sum\%v(:)}
\DoxyCodeLine{287   \textcolor{keywordflow}{else}}
\DoxyCodeLine{288     rsum(1) = 0.0}
\DoxyCodeLine{289     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{290       rsum(1) = rsum(1) + array(i,j)}
\DoxyCodeLine{291 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{292     \textcolor{keywordflow}{if} (do\_sum\_across\_pes) \textcolor{keyword}{call }sum\_across\_pes(rsum,1)}
\DoxyCodeLine{293     sum = rsum(1)}
\DoxyCodeLine{294 }
\DoxyCodeLine{295     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(err)) \textcolor{keywordflow}{then} ; err = 0 ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{296 }
\DoxyCodeLine{297     \textcolor{keywordflow}{if} (debug .or. \textcolor{keyword}{present}(efp\_sum)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{298       overflow\_error = .false.}
\DoxyCodeLine{299       ints\_sum = real\_to\_ints(sum, prec\_error, overflow\_error)}
\DoxyCodeLine{300       \textcolor{keywordflow}{if} (overflow\_error) \textcolor{keywordflow}{then}}
\DoxyCodeLine{301         \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(err)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{302           err = err + 2}
\DoxyCodeLine{303         \textcolor{keywordflow}{else}}
\DoxyCodeLine{304           \textcolor{keyword}{write}(mesg, \textcolor{stringliteral}{'(ES13.5)'}) sum}
\DoxyCodeLine{305           \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"Repro\_sum\_2d: Overflow in real\_to\_ints conversion of "}//trim(mesg))}
\DoxyCodeLine{306 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{307 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{308 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{309     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(efp\_sum)) efp\_sum\%v(:) = ints\_sum(:)}
\DoxyCodeLine{310 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{311 }
\DoxyCodeLine{312   \textcolor{keywordflow}{if} (debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{313     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("2d RS: ", ES24.16, 6 Z17.16)'}) sum, ints\_sum(1:ni)}
\DoxyCodeLine{314     \textcolor{keyword}{call }mom\_mesg(mesg, 3)}
\DoxyCodeLine{315 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{316 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__coms_aa98bb5adb44798d397f668edf62832e8}\label{namespacemom__coms_aa98bb5adb44798d397f668edf62832e8}} 
\index{mom\_coms@{mom\_coms}!reproducing\_sum\_3d@{reproducing\_sum\_3d}}
\index{reproducing\_sum\_3d@{reproducing\_sum\_3d}!mom\_coms@{mom\_coms}}
\doxysubsubsection{\texorpdfstring{reproducing\_sum\_3d()}{reproducing\_sum\_3d()}}
{\footnotesize\ttfamily real function mom\+\_\+coms\+::reproducing\+\_\+sum\+\_\+3d (\begin{DoxyParamCaption}\item[{real, dimension(\+:,\+:,\+:), intent(in)}]{array,  }\item[{integer, intent(in), optional}]{isr,  }\item[{integer, intent(in), optional}]{ier,  }\item[{integer, intent(in), optional}]{jsr,  }\item[{integer, intent(in), optional}]{jer,  }\item[{real, dimension(\+:), intent(out), optional}]{sums,  }\item[{type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}), intent(out), optional}]{E\+F\+P\+\_\+sum,  }\item[{type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}), dimension(\+:), intent(out), optional}]{E\+F\+P\+\_\+lay\+\_\+sums,  }\item[{integer, intent(out), optional}]{err,  }\item[{logical, intent(in), optional}]{only\+\_\+on\+\_\+\+PE }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine uses a conversion to an integer representation of real numbers to give an order-\/invariant sum of distributed 3-\/D arrays that reproduces across domain decomposition. This technique is described in Hallberg \& Adcroft, 2014, Parallel Computing, doi\+:10.\+1016/j.parco.\+2014.\+04.\+007. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em array} & The array to be summed \\
\hline
\mbox{\texttt{ in}}  & {\em isr} & The starting i-\/index of the sum, noting that the array indices starts at 1 \\
\hline
\mbox{\texttt{ in}}  & {\em ier} & The ending i-\/index of the sum, noting that the array indices starts at 1 \\
\hline
\mbox{\texttt{ in}}  & {\em jsr} & The starting j-\/index of the sum, noting that the array indices starts at 1 \\
\hline
\mbox{\texttt{ in}}  & {\em jer} & The ending j-\/index of the sum, noting that the array indices starts at 1 \\
\hline
\mbox{\texttt{ out}}  & {\em sums} & The sums by vertical layer \\
\hline
\mbox{\texttt{ out}}  & {\em efp\+\_\+sum} & The result in extended fixed point format \\
\hline
\mbox{\texttt{ out}}  & {\em efp\+\_\+lay\+\_\+sums} & The sums by vertical layer in E\+FP format \\
\hline
\mbox{\texttt{ out}}  & {\em err} & If present, return an error code instead of triggering any fatal errors directly from this routine. \\
\hline
\mbox{\texttt{ in}}  & {\em only\+\_\+on\+\_\+pe} & If present and true, do not do the sum across processors, only reporting the local sum \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Result 
\end{DoxyReturn}


Definition at line 325 of file M\+O\+M\+\_\+coms.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{325 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)},       \textcolor{keywordtype}{intent(in)}  :: array\textcolor{comment}{   !< The array to be summed}}
\DoxyCodeLine{326   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: isr\textcolor{comment}{     !< The starting i-\/index of the sum, noting}}
\DoxyCodeLine{327 \textcolor{comment}{                                                       !! that the array indices starts at 1}}
\DoxyCodeLine{328   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: ier\textcolor{comment}{     !< The ending i-\/index of the sum, noting}}
\DoxyCodeLine{329 \textcolor{comment}{                                                       !! that the array indices starts at 1}}
\DoxyCodeLine{330   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: jsr\textcolor{comment}{     !< The starting j-\/index of the sum, noting}}
\DoxyCodeLine{331 \textcolor{comment}{                                                       !! that the array indices starts at 1}}
\DoxyCodeLine{332   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: jer\textcolor{comment}{     !< The ending j-\/index of the sum, noting}}
\DoxyCodeLine{333 \textcolor{comment}{                                                       !! that the array indices starts at 1}}
\DoxyCodeLine{334 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: sums\textcolor{comment}{    !< The sums by vertical layer}}
\DoxyCodeLine{335   \textcolor{keywordtype}{type}(EFP\_type),     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: EFP\_sum\textcolor{comment}{ !< The result in extended fixed point format}}
\DoxyCodeLine{336   \textcolor{keywordtype}{type}(EFP\_type), \textcolor{keywordtype}{dimension(:)}, \&}
\DoxyCodeLine{337                       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: EFP\_lay\_sums\textcolor{comment}{ !< The sums by vertical layer in EFP format}}
\DoxyCodeLine{338   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: err\textcolor{comment}{  !< If present, return an error code instead of}}
\DoxyCodeLine{339 \textcolor{comment}{                                                    !! triggering any fatal errors directly from}}
\DoxyCodeLine{340 \textcolor{comment}{                                                    !! this routine.}}
\DoxyCodeLine{341   \textcolor{keywordtype}{logical},            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: only\_on\_PE\textcolor{comment}{ !< If present and true, do not do the sum}}
\DoxyCodeLine{342 \textcolor{comment}{                                                    !! across processors, only reporting the local sum}}
\DoxyCodeLine{343 \textcolor{keywordtype}{  real}                                      :: sum\textcolor{comment}{  !< Result}}
\DoxyCodeLine{344 }
\DoxyCodeLine{345   \textcolor{comment}{!   This subroutine uses a conversion to an integer representation}}
\DoxyCodeLine{346   \textcolor{comment}{! of real numbers to give order-\/invariant sums that will reproduce}}
\DoxyCodeLine{347   \textcolor{comment}{! across PE count.  This idea comes from R. Hallberg and A. Adcroft.}}
\DoxyCodeLine{348 }
\DoxyCodeLine{349 \textcolor{keywordtype}{  real}    :: val, max\_mag\_term}
\DoxyCodeLine{350   \textcolor{keywordtype}{integer(kind=8)}, \textcolor{keywordtype}{dimension(ni)}  :: ints\_sum}
\DoxyCodeLine{351   \textcolor{keywordtype}{integer(kind=8)}, \textcolor{keywordtype}{dimension(ni,size(array,3))}  :: ints\_sums}
\DoxyCodeLine{352   \textcolor{keywordtype}{integer(kind=8)} :: prec\_error}
\DoxyCodeLine{353   \textcolor{keywordtype}{character(len=256)} :: mesg}
\DoxyCodeLine{354   \textcolor{keywordtype}{logical} :: do\_sum\_across\_PEs}
\DoxyCodeLine{355   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, ke, isz, jsz, n}
\DoxyCodeLine{356 }
\DoxyCodeLine{357   \textcolor{keywordflow}{if} (num\_pes() > max\_count\_prec) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{358     \textcolor{stringliteral}{"reproducing\_sum: Too many processors are being used for the value of "}//\&}
\DoxyCodeLine{359     \textcolor{stringliteral}{"prec.  Reduce prec to (2\string^63-\/1)/num\_PEs."})}
\DoxyCodeLine{360 }
\DoxyCodeLine{361   prec\_error = (2\_8**62 + (2\_8**62 -\/ 1)) / num\_pes()}
\DoxyCodeLine{362   max\_mag\_term = 0.0}
\DoxyCodeLine{363 }
\DoxyCodeLine{364   is = 1 ; ie = \textcolor{keyword}{size}(array,1) ; js = 1 ; je = \textcolor{keyword}{size}(array,2) ; ke = \textcolor{keyword}{size}(array,3)}
\DoxyCodeLine{365   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(isr)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{366     \textcolor{keywordflow}{if} (isr < is) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Value of isr too small in reproducing\_sum(\_3d)."})}
\DoxyCodeLine{367     is = isr}
\DoxyCodeLine{368 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{369   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(ier)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{370     \textcolor{keywordflow}{if} (ier > ie) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Value of ier too large in reproducing\_sum(\_3d)."})}
\DoxyCodeLine{371     ie = ier}
\DoxyCodeLine{372 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{373   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(jsr)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{374     \textcolor{keywordflow}{if} (jsr < js) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Value of jsr too small in reproducing\_sum(\_3d)."})}
\DoxyCodeLine{375     js = jsr}
\DoxyCodeLine{376 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{377   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(jer)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{378     \textcolor{keywordflow}{if} (jer > je) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Value of jer too large in reproducing\_sum(\_3d)."})}
\DoxyCodeLine{379     je = jer}
\DoxyCodeLine{380 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{381   jsz = je+1-\/js; isz = ie+1-\/is}
\DoxyCodeLine{382 }
\DoxyCodeLine{383   do\_sum\_across\_pes = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(only\_on\_pe)) do\_sum\_across\_pes = .not.only\_on\_pe}
\DoxyCodeLine{384 }
\DoxyCodeLine{385   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(sums) .or. \textcolor{keyword}{present}(efp\_lay\_sums)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{386     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(sums)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{size}(sums) < ke) \textcolor{keywordflow}{then}}
\DoxyCodeLine{387       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Sums is smaller than the vertical extent of array in reproducing\_sum(\_3d)."})}
\DoxyCodeLine{388 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{389     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(efp\_lay\_sums)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{size}(efp\_lay\_sums) < ke) \textcolor{keywordflow}{then}}
\DoxyCodeLine{390       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Sums is smaller than the vertical extent of array in reproducing\_sum(\_3d)."})}
\DoxyCodeLine{391 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{392     ints\_sums(:,:) = 0}
\DoxyCodeLine{393     overflow\_error = .false. ; nan\_error = .false. ; max\_mag\_term = 0.0}
\DoxyCodeLine{394     \textcolor{keywordflow}{if} (jsz*isz < max\_count\_prec) \textcolor{keywordflow}{then}}
\DoxyCodeLine{395       \textcolor{keywordflow}{do} k=1,ke}
\DoxyCodeLine{396         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{397           \textcolor{keyword}{call }increment\_ints\_faster(ints\_sums(:,k), array(i,j,k), max\_mag\_term)}
\DoxyCodeLine{398 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{399         \textcolor{keyword}{call }carry\_overflow(ints\_sums(:,k), prec\_error)}
\DoxyCodeLine{400 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{401     \textcolor{keywordflow}{elseif} (isz < max\_count\_prec) \textcolor{keywordflow}{then}}
\DoxyCodeLine{402       \textcolor{keywordflow}{do} k=1,ke ; \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{403         \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{404           \textcolor{keyword}{call }increment\_ints\_faster(ints\_sums(:,k), array(i,j,k), max\_mag\_term)}
\DoxyCodeLine{405 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{406         \textcolor{keyword}{call }carry\_overflow(ints\_sums(:,k), prec\_error)}
\DoxyCodeLine{407 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{408     \textcolor{keywordflow}{else}}
\DoxyCodeLine{409       \textcolor{keywordflow}{do} k=1,ke ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{410         \textcolor{keyword}{call }increment\_ints(ints\_sums(:,k), \&}
\DoxyCodeLine{411                             real\_to\_ints(array(i,j,k), prec\_error), prec\_error)}
\DoxyCodeLine{412 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{413 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{414     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(err)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{415       err = 0}
\DoxyCodeLine{416       \textcolor{keywordflow}{if} (abs(max\_mag\_term) >= prec\_error*pr(1)) err = err+1}
\DoxyCodeLine{417       \textcolor{keywordflow}{if} (overflow\_error) err = err+2}
\DoxyCodeLine{418       \textcolor{keywordflow}{if} (nan\_error) err = err+2}
\DoxyCodeLine{419       \textcolor{keywordflow}{if} (err > 0) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,ke ; \textcolor{keywordflow}{do} n=1,ni ; ints\_sums(n,k) = 0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{420     \textcolor{keywordflow}{else}}
\DoxyCodeLine{421       \textcolor{keywordflow}{if} (nan\_error) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"NaN in input field of reproducing\_sum(\_3d)."})}
\DoxyCodeLine{422       \textcolor{keywordflow}{if} (abs(max\_mag\_term) >= prec\_error*pr(1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{423         \textcolor{keyword}{write}(mesg, \textcolor{stringliteral}{'(ES13.5)'}) max\_mag\_term}
\DoxyCodeLine{424         \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"Overflow in reproducing\_sum(\_3d) conversion of "}//trim(mesg))}
\DoxyCodeLine{425 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{426       \textcolor{keywordflow}{if} (overflow\_error) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Overflow in reproducing\_sum(\_3d)."})}
\DoxyCodeLine{427 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{428 }
\DoxyCodeLine{429     \textcolor{keywordflow}{if} (do\_sum\_across\_pes) \textcolor{keyword}{call }sum\_across\_pes(ints\_sums(:,1:ke), ni*ke)}
\DoxyCodeLine{430 }
\DoxyCodeLine{431     sum = 0.0}
\DoxyCodeLine{432     \textcolor{keywordflow}{do} k=1,ke}
\DoxyCodeLine{433       \textcolor{keyword}{call }regularize\_ints(ints\_sums(:,k))}
\DoxyCodeLine{434       val = ints\_to\_real(ints\_sums(:,k))}
\DoxyCodeLine{435       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(sums)) sums(k) = val}
\DoxyCodeLine{436       sum = sum + val}
\DoxyCodeLine{437 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{438     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(efp\_lay\_sums)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,ke}
\DoxyCodeLine{439       efp\_lay\_sums(k)\%v(:) = ints\_sums(:,k)}
\DoxyCodeLine{440 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{441 }
\DoxyCodeLine{442     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(efp\_sum)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{443       efp\_sum\%v(:) = 0}
\DoxyCodeLine{444       \textcolor{keywordflow}{do} k=1,ke ; \textcolor{keyword}{call }increment\_ints(efp\_sum\%v(:), ints\_sums(:,k)) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{445 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{446 }
\DoxyCodeLine{447     \textcolor{keywordflow}{if} (debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{448       \textcolor{keywordflow}{do} n=1,ni ; ints\_sum(n) = 0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{449       \textcolor{keywordflow}{do} k=1,ke ; \textcolor{keywordflow}{do} n=1,ni ; ints\_sum(n) = ints\_sum(n) + ints\_sums(n,k) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{450       \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("3D RS: ", ES24.16, 6 Z17.16)'}) sum, ints\_sum(1:ni)}
\DoxyCodeLine{451       \textcolor{keyword}{call }mom\_mesg(mesg, 3)}
\DoxyCodeLine{452 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{453   \textcolor{keywordflow}{else}}
\DoxyCodeLine{454     ints\_sum(:) = 0}
\DoxyCodeLine{455     overflow\_error = .false. ; nan\_error = .false. ; max\_mag\_term = 0.0}
\DoxyCodeLine{456     \textcolor{keywordflow}{if} (jsz*isz < max\_count\_prec) \textcolor{keywordflow}{then}}
\DoxyCodeLine{457       \textcolor{keywordflow}{do} k=1,ke}
\DoxyCodeLine{458         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{459           \textcolor{keyword}{call }increment\_ints\_faster(ints\_sum, array(i,j,k), max\_mag\_term)}
\DoxyCodeLine{460 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{461         \textcolor{keyword}{call }carry\_overflow(ints\_sum, prec\_error)}
\DoxyCodeLine{462 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{463     \textcolor{keywordflow}{elseif} (isz < max\_count\_prec) \textcolor{keywordflow}{then}}
\DoxyCodeLine{464       \textcolor{keywordflow}{do} k=1,ke ; \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{465         \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{466           \textcolor{keyword}{call }increment\_ints\_faster(ints\_sum, array(i,j,k), max\_mag\_term)}
\DoxyCodeLine{467 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{468         \textcolor{keyword}{call }carry\_overflow(ints\_sum, prec\_error)}
\DoxyCodeLine{469 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{470     \textcolor{keywordflow}{else}}
\DoxyCodeLine{471       \textcolor{keywordflow}{do} k=1,ke ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{472         \textcolor{keyword}{call }increment\_ints(ints\_sum, real\_to\_ints(array(i,j,k), prec\_error), \&}
\DoxyCodeLine{473                             prec\_error)}
\DoxyCodeLine{474 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{475 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{476     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(err)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{477       err = 0}
\DoxyCodeLine{478       \textcolor{keywordflow}{if} (abs(max\_mag\_term) >= prec\_error*pr(1)) err = err+1}
\DoxyCodeLine{479       \textcolor{keywordflow}{if} (overflow\_error) err = err+2}
\DoxyCodeLine{480       \textcolor{keywordflow}{if} (nan\_error) err = err+2}
\DoxyCodeLine{481       \textcolor{keywordflow}{if} (err > 0) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} n=1,ni ; ints\_sum(n) = 0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{482     \textcolor{keywordflow}{else}}
\DoxyCodeLine{483       \textcolor{keywordflow}{if} (nan\_error) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"NaN in input field of reproducing\_sum(\_3d)."})}
\DoxyCodeLine{484       \textcolor{keywordflow}{if} (abs(max\_mag\_term) >= prec\_error*pr(1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{485         \textcolor{keyword}{write}(mesg, \textcolor{stringliteral}{'(ES13.5)'}) max\_mag\_term}
\DoxyCodeLine{486         \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"Overflow in reproducing\_sum(\_3d) conversion of "}//trim(mesg))}
\DoxyCodeLine{487 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{488       \textcolor{keywordflow}{if} (overflow\_error) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Overflow in reproducing\_sum(\_3d)."})}
\DoxyCodeLine{489 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{490 }
\DoxyCodeLine{491     \textcolor{keywordflow}{if} (do\_sum\_across\_pes) \textcolor{keyword}{call }sum\_across\_pes(ints\_sum, ni)}
\DoxyCodeLine{492 }
\DoxyCodeLine{493     \textcolor{keyword}{call }regularize\_ints(ints\_sum)}
\DoxyCodeLine{494     sum = ints\_to\_real(ints\_sum)}
\DoxyCodeLine{495 }
\DoxyCodeLine{496     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(efp\_sum)) efp\_sum\%v(:) = ints\_sum(:)}
\DoxyCodeLine{497 }
\DoxyCodeLine{498     \textcolor{keywordflow}{if} (debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{499       \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("3d RS: ", ES24.16, 6 Z17.16)'}) sum, ints\_sum(1:ni)}
\DoxyCodeLine{500       \textcolor{keyword}{call }mom\_mesg(mesg, 3)}
\DoxyCodeLine{501 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{502 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{503 }

\end{DoxyCode}
