Rheolef  7.1
an efficient C++ finite element environment
distributor.h
Go to the documentation of this file.
1 #ifndef _RHEO_DISTRIBUTOR_H
2 #define _RHEO_DISTRIBUTOR_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 // AUTHOR: Pierre.Saramito@imag.fr
24 // DATE: 27 november 1998
25 
26 namespace rheolef {
53 } // namespace rheolef
54 
55 # include "rheolef/distributed.h"
56 # include "rheolef/dis_macros.h"
57 # include "rheolef/Vector.h"
58 
59 namespace rheolef {
60 
61 // [verbatim_distributor]
62 class distributor : public Vector<std::allocator<int>::size_type> {
63 public:
64 
65 // typedefs:
66 
71  typedef int tag_type;
72  typedef communicator communicator_type;
73 
74 // constants:
75 
76  static const size_type decide = size_type(-1);
77 
78 // allocators/deallocators:
79 
81  size_type dis_size = 0,
83  size_type loc_size = decide);
84 
85  distributor(const distributor&);
86  ~distributor();
87 
88  void resize(
89  size_type dis_size = 0,
91  size_type loc_size = decide);
92 
93 // accessors:
94 
95  const communicator_type& comm() const;
96 
98  size_type dis_size () const;
99 
101  size_type process () const;
102 
104  size_type n_process () const;
105 
107  size_type find_owner (size_type dis_i) const;
108 
110  size_type first_index (size_type iproc) const;
111  size_type last_index (size_type iproc) const;
112  size_type size (size_type iproc) const;
113 
115  size_type first_index () const;
116  size_type last_index () const;
117  size_type size () const;
118 
120  bool is_owned (size_type dis_i, size_type iproc) const;
121 
122  // the same with ip=current process
123  bool is_owned (size_type dis_i) const;
124 
125 
127  static tag_type get_new_tag();
128 
129 // comparators:
130 
131  bool operator== (const distributor&) const;
132  bool operator!= (const distributor&) const;
133 // [verbatim_distributor]
134 
135 // data:
136 protected:
138 // [verbatim_distributor_cont]
139 };
140 // [verbatim_distributor_cont]
141 
142 // inline'd
143 inline
146 {
147  return _comm;
148 }
149 inline
152 {
153  return at(j);
154 }
155 inline
158 {
159  return at(j+1);
160 }
161 inline
164 {
165  return last_index(j) - first_index(j);
166 }
167 inline
170 {
171 #ifdef _RHEOLEF_HAVE_MPI
172  return _comm.size();
173 #else // _RHEOLEF_HAVE_MPI
174  return 1;
175 #endif // _RHEOLEF_HAVE_MPI
176 }
177 inline
180 {
181 #ifdef _RHEOLEF_HAVE_MPI
182  return _comm.rank();
183 #else // _RHEOLEF_HAVE_MPI
184  return 0;
185 #endif // _RHEOLEF_HAVE_MPI
186 }
187 inline
190 {
191  return first_index(process());
192 }
193 inline
196 {
197  return last_index(process());
198 }
199 inline
202 {
203  return size(process());
204 }
205 inline
208 {
209  return at(n_process());
210 }
211 inline
212 bool
214 {
215  return dis_i >= first_index(ip) && dis_i < last_index(ip);
216 }
217 inline
218 bool
220 {
221  return is_owned (dis_i, process());
222 }
223 inline
224 bool
226 {
227  return !operator==(x);
228 }
229 inline
230 bool
232 {
233  return (x.n_process() == n_process()) && (x.size() == size()) && (x.dis_size() == dis_size());
234 }
235 
236 } // namespace rheolef
237 #endif // _RHEO_DISTRIBUTOR_H
rheolef::distributor::iterator
_base::iterator iterator
Definition: distributor.h:69
rheolef::distributor::get_new_tag
static tag_type get_new_tag()
returns a new tag
Definition: distributor.cc:133
rheolef::distributor::n_process
size_type n_process() const
number of processes
Definition: distributor.h:169
rheolef::Vector
Definition: Vector.h:175
rheolef::Vector< std::allocator< int >::size_type >::at
const_reference at(size_type n) const
Definition: Vector.h:283
rheolef::distributor::comm
const communicator_type & comm() const
Definition: distributor.h:145
rheolef::distributor::find_owner
size_type find_owner(size_type dis_i) const
find iproc associated to a global index dis_i: CPU=log(nproc)
Definition: distributor.cc:106
rheolef::distributor::communicator_type
communicator communicator_type
Definition: distributor.h:72
rheolef::distributor
see the distributor page for the full documentation
Definition: distributor.h:62
mkgeo_ball.c
c
Definition: mkgeo_ball.sh:153
rheolef::distributor::decide
static const size_type decide
Definition: distributor.h:76
rheolef::Vector::iterator
DATA::iterator iterator
Definition: Vector.h:183
rheolef::distributor::size
size_type size() const
Definition: distributor.h:201
rheolef::distributor::first_index
size_type first_index() const
global index range and local size owned by current process
Definition: distributor.h:189
rheolef::distributor::last_index
size_type last_index() const
Definition: distributor.h:195
rheolef::distributor::_comm
communicator_type _comm
Definition: distributor.h:137
rheolef::distributor::const_iterator
_base::const_iterator const_iterator
Definition: distributor.h:70
rheolef::distributor::process
size_type process() const
current process id
Definition: distributor.h:179
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::distributor::dis_size
size_type dis_size() const
global and local sizes
Definition: distributor.h:207
size_type
field::size_type size_type
Definition: branch.cc:425
rheolef::distributor::is_owned
bool is_owned(size_type dis_i, size_type iproc) const
true when dis_i in [first_index(iproc):last_index(iproc)[
Definition: distributor.h:213
rheolef::distributor::operator==
bool operator==(const distributor &) const
Definition: distributor.h:231
rheolef::distributor::resize
void resize(size_type dis_size=0, const communicator_type &c=communicator_type(), size_type loc_size=decide)
Definition: distributor.cc:30
rheolef::distributor::tag_type
int tag_type
Definition: distributor.h:71
rheolef::distributor::_base
Vector< size_type > _base
Definition: distributor.h:68
rheolef::distributor::size_type
std::allocator< int >::size_type size_type
Definition: distributor.h:67
rheolef::distributor::distributor
distributor(size_type dis_size=0, const communicator_type &c=communicator_type(), size_type loc_size=decide)
Definition: distributor.cc:88
rheolef::distributor::size
size_type size(size_type iproc) const
Definition: distributor.h:163
rheolef::distributor::~distributor
~distributor()
Definition: distributor.cc:102
rheolef::Vector::const_iterator
DATA::const_iterator const_iterator
Definition: Vector.h:184
rheolef::distributor::operator!=
bool operator!=(const distributor &) const
Definition: distributor.h:225