Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
dis_accumulate.h
Go to the documentation of this file.
1#ifndef _RHEO_DIS_ACCUMULATE_H
2#define _RHEO_DIS_ACCUMULATE_H
3//
4// This file is part of Rheolef.
5//
6// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
7//
8// Rheolef is free software; you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation; either version 2 of the License, or
11// (at your option) any later version.
12//
13// Rheolef is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with Rheolef; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21//
22// =========================================================================
23
24#include "rheolef/promote.h"
25#include "rheolef/communicator.h"
26#include <iterator>
27namespace rheolef {
28
29/*D:dis_accumulate
30NAME: dis_accumulate - distributed accumulate algorithm (@PACKAGE@-@VERSION@)
31DESCRIPTION:
32 STL-like accumulate for distributed containers
33 environment.
34SYNOPSIS:
35 @example
36 template<class InputIterator, class Size>
37 T dis_accumulate (InputIterator first, Size n);
38 @end example
39EXAMPLE:
40 A sample usage writes:
41 @example
42 # include "rheolef/disarray.h"
43 # include "rheolef/dis_accumulate.h"
44 int main(int argc, char**argv) {
45 environment distributed (argc, argv);
46 unsigned int n = 100;
47 disarray<double> x(n, 2.0);
48 double sum = dis_accumulate(x.begin(),x.size(),x.comm());
49 dout << "dot(x,1) = " << sum << endl;
50 }
51 @end example
52SEE ALSO: "disarray"(1)
53AUTHORS:
54 LMC-IMAG, 38041 Grenoble cedex 9, France
55 | Pierre.Saramito@imag.fr
56DATE: 24 november 1998
57End:
58*/
59template <class InputIterator, class Size>
60typename std::iterator_traits<InputIterator>::value_type
62 InputIterator first,
63 Size n,
65 sequential /* memory_model */)
66{
67 typedef typename std::iterator_traits<InputIterator>::value_type T;
68 T sum = T(0);
69 for (Size i = 0; i < n; ++i, ++first) {
70 sum = sum + (*first);
71 }
72 return sum;
73}
74#ifdef _RHEOLEF_HAVE_MPI
75template <class InputIterator,class Size>
76inline
77typename std::iterator_traits<InputIterator>::value_type
79 InputIterator first,
80 Size n,
82 distributed /* memory_model */)
83{
84 typedef typename std::iterator_traits<InputIterator>::value_type T;
85 T local_sum = dis_accumulate (first, n, comm, sequential());
86 return mpi::all_reduce (comm, local_sum, std::plus<T>());
87}
88#endif // _RHEOLEF_HAVE_MPI
89
90template <class InputIterator, class Size>
91inline
92typename std::iterator_traits<InputIterator>::value_type
94 InputIterator first,
95 Size n,
97{
98 return dis_accumulate (first, n, comm, rheo_default_memory_model());
99}
100
101} // namespace rheolef
102#endif // _RHEO_DIS_ACCUMULATE_H
communicator communicator_type
Definition distributor.h:79
#define rheo_default_memory_model
Expr1::float_type T
Definition field_expr.h:230
This file is part of Rheolef.
std::iterator_traits< InputIterator >::value_type dis_accumulate(InputIterator first, Size n, const distributor::communicator_type &comm, sequential)