Rheolef  7.1
an efficient C++ finite element environment
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/distributed.h"
26 #include <iterator>
27 namespace rheolef {
28 
29 /*D:dis_accumulate
30 NAME: dis_accumulate - distributed accumulate algorithm (@PACKAGE@-@VERSION@)
31 DESCRIPTION:
32  STL-like accumulate for distributed containers
33  environment.
34 SYNOPSIS:
35  @example
36  template<class InputIterator, class Size>
37  T dis_accumulate (InputIterator first, Size n);
38  @end example
39 EXAMPLE:
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
52 SEE ALSO: "disarray"(1)
53 AUTHORS:
54  LMC-IMAG, 38041 Grenoble cedex 9, France
55  | Pierre.Saramito@imag.fr
56 DATE: 24 november 1998
57 End:
58 */
59 template <class InputIterator, class Size>
60 typename 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
75 template <class InputIterator,class Size>
76 inline
77 typename 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 
90 template <class InputIterator, class Size>
91 inline
92 typename 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
mkgeo_ball.n
int n
Definition: mkgeo_ball.sh:150
rheo_default_memory_model
#define rheo_default_memory_model
Definition: distributed.h:113
rheolef::sequential
Definition: distributed.h:28
rheolef::distributor::communicator_type
communicator communicator_type
Definition: distributor.h:72
rheolef::distributed
Definition: distributed.h:88
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::dis_accumulate
std::iterator_traits< InputIterator >::value_type dis_accumulate(InputIterator first, Size n, const distributor::communicator_type &comm, sequential)
Definition: dis_accumulate.h:61
T
Expr1::float_type T
Definition: field_expr.h:261