\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{\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 out}  & {\em efp\+\_\+sum} & The result in extended fixed point format\\
\hline
\mbox{\tt in}  & {\em reproducing} & If present and false, do the sum using the naive non-\/reproducing approach\\
\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}
Result 
\end{DoxyReturn}


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


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


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


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