\hypertarget{interfacemom__coms_1_1reproducing__sum}{}\section{mom\+\_\+coms\+::reproducing\+\_\+sum Interface Reference}
\label{interfacemom__coms_1_1reproducing__sum}\index{mom\_coms::reproducing\_sum@{mom\_coms::reproducing\_sum}}


\subsection{Detailed Description}
Find an accurate and order-\/invariant sum of a distributed 2d or 3d field. 

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

\subsection*{Private functions}
\begin{DoxyCompactItemize}
\item 
real function \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum_ab2f6e6add0bf919823551d1bb480d37c}{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{interfacemom__coms_1_1reproducing__sum_a302c8e698e72494e208161ba8ca7fe87}{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}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Find an accurate and order-\/invariant sum of a distributed 2d or 3d field. 

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



\subsection{Functions and subroutines}
\mbox{\Hypertarget{interfacemom__coms_1_1reproducing__sum_ab2f6e6add0bf919823551d1bb480d37c}\label{interfacemom__coms_1_1reproducing__sum_ab2f6e6add0bf919823551d1bb480d37c}} 
\index{mom\_coms::reproducing\_sum@{mom\_coms::reproducing\_sum}!reproducing\_sum\_2d@{reproducing\_sum\_2d}}
\index{reproducing\_sum\_2d@{reproducing\_sum\_2d}!mom\_coms::reproducing\_sum@{mom\_coms::reproducing\_sum}}
\subsubsection{\texorpdfstring{reproducing\_sum\_2d()}{reproducing\_sum\_2d()}}
{\footnotesize\ttfamily real function mom\+\_\+coms\+::reproducing\+\_\+sum\+::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{interfacemom__coms_1_1reproducing__sum_a302c8e698e72494e208161ba8ca7fe87}\label{interfacemom__coms_1_1reproducing__sum_a302c8e698e72494e208161ba8ca7fe87}} 
\index{mom\_coms::reproducing\_sum@{mom\_coms::reproducing\_sum}!reproducing\_sum\_3d@{reproducing\_sum\_3d}}
\index{reproducing\_sum\_3d@{reproducing\_sum\_3d}!mom\_coms::reproducing\_sum@{mom\_coms::reproducing\_sum}}
\subsubsection{\texorpdfstring{reproducing\_sum\_3d()}{reproducing\_sum\_3d()}}
{\footnotesize\ttfamily real function mom\+\_\+coms\+::reproducing\+\_\+sum\+::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}


The documentation for this interface was generated from the following file\+:\begin{DoxyCompactItemize}
\item 
/home/cermak/src/\+M\+O\+M6.\+devrob/src/framework/M\+O\+M\+\_\+coms.\+F90\end{DoxyCompactItemize}
