\hypertarget{interfacemom__coms_1_1reproducing__sum__efp}{}\doxysection{mom\+\_\+coms\+::reproducing\+\_\+sum\+\_\+efp Interface Reference}
\label{interfacemom__coms_1_1reproducing__sum__efp}\index{mom\_coms::reproducing\_sum\_efp@{mom\_coms::reproducing\_sum\_efp}}


\doxysubsection{Detailed Description}
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. 

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

\doxysubsection*{Private functions}
\begin{DoxyCompactItemize}
\item 
type(\mbox{\hyperlink{structmom__coms_1_1efp__type}{efp\+\_\+type}}) function \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum__efp_a8316e3d021227cb9b54598d62b049fab}{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}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
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. 

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



\doxysubsection{Functions and subroutines}
\mbox{\Hypertarget{interfacemom__coms_1_1reproducing__sum__efp_a8316e3d021227cb9b54598d62b049fab}\label{interfacemom__coms_1_1reproducing__sum__efp_a8316e3d021227cb9b54598d62b049fab}} 
\index{mom\_coms::reproducing\_sum\_efp@{mom\_coms::reproducing\_sum\_efp}!reproducing\_efp\_sum\_2d@{reproducing\_efp\_sum\_2d}}
\index{reproducing\_efp\_sum\_2d@{reproducing\_efp\_sum\_2d}!mom\_coms::reproducing\_sum\_efp@{mom\_coms::reproducing\_sum\_efp}}
\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\+\_\+sum\+\_\+efp\+::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 92 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}


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}
