\hypertarget{interfacemom__coms_1_1reproducing__sum__efp}{}\section{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}}


\subsection{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.

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


\subsection{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.



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