Rheolef  7.2
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 {
60 } // namespace rheolef
61 
62 # include "rheolef/communicator.h"
63 # include "rheolef/dis_macros.h"
64 # include "rheolef/Vector.h"
65 
66 namespace rheolef {
67 
68 // [verbatim_distributor]
69 class distributor : public Vector<std::allocator<int>::size_type> {
70 public:
71 
72 // typedefs:
73 
78  typedef int tag_type;
79  typedef communicator communicator_type;
80 
81 // constants:
82 
83  static const size_type decide = size_type(-1);
84 
85 // allocators/deallocators:
86 
88  size_type dis_size = 0,
90  size_type loc_size = decide);
91 
92  distributor(const distributor&);
93  ~distributor();
94 
95  void resize(
96  size_type dis_size = 0,
98  size_type loc_size = decide);
99 
100 // accessors:
101 
102  const communicator_type& comm() const;
103 
105  size_type dis_size () const;
106 
108  size_type process () const;
109 
111  size_type n_process () const;
112 
114  size_type find_owner (size_type dis_i) const;
115 
117  size_type first_index (size_type iproc) const;
118  size_type last_index (size_type iproc) const;
119  size_type size (size_type iproc) const;
120 
122  size_type first_index () const;
123  size_type last_index () const;
124  size_type size () const;
125 
127  bool is_owned (size_type dis_i, size_type iproc) const;
128 
129  // the same with ip=current process
130  bool is_owned (size_type dis_i) const;
131 
132 
134  static tag_type get_new_tag();
135 
136 // comparators:
137 
138  bool operator== (const distributor&) const;
139  bool operator!= (const distributor&) const;
140 // [verbatim_distributor]
141 
142 // data:
143 protected:
145 // [verbatim_distributor_cont]
146 };
147 // [verbatim_distributor_cont]
148 
149 // inline'd
150 inline
153 {
154  return _comm;
155 }
156 inline
159 {
160  return at(j);
161 }
162 inline
165 {
166  return at(j+1);
167 }
168 inline
171 {
172  return last_index(j) - first_index(j);
173 }
174 inline
177 {
178 #ifdef _RHEOLEF_HAVE_MPI
179  return _comm.size();
180 #else // _RHEOLEF_HAVE_MPI
181  return 1;
182 #endif // _RHEOLEF_HAVE_MPI
183 }
184 inline
187 {
188 #ifdef _RHEOLEF_HAVE_MPI
189  return _comm.rank();
190 #else // _RHEOLEF_HAVE_MPI
191  return 0;
192 #endif // _RHEOLEF_HAVE_MPI
193 }
194 inline
197 {
198  return first_index(process());
199 }
200 inline
203 {
204  return last_index(process());
205 }
206 inline
209 {
210  return size(process());
211 }
212 inline
215 {
216  return at(n_process());
217 }
218 inline
219 bool
221 {
222  return dis_i >= first_index(ip) && dis_i < last_index(ip);
223 }
224 inline
225 bool
227 {
228  return is_owned (dis_i, process());
229 }
230 inline
231 bool
233 {
234  return !operator==(x);
235 }
236 inline
237 bool
239 {
240  return (x.n_process() == n_process()) && (x.size() == size()) && (x.dis_size() == dis_size());
241 }
242 
243 } // namespace rheolef
244 #endif // _RHEO_DISTRIBUTOR_H
field::size_type size_type
Definition: branch.cc:430
see the distributor page for the full documentation
Definition: distributor.h:69
size_type last_index() const
Definition: distributor.h:202
size_type n_process() const
number of processes
Definition: distributor.h:176
Vector< size_type > _base
Definition: distributor.h:75
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
void resize(size_type dis_size=0, const communicator_type &c=communicator_type(), size_type loc_size=decide)
Definition: distributor.cc:30
size_type dis_size() const
global and local sizes
Definition: distributor.h:214
communicator communicator_type
Definition: distributor.h:79
size_type size(size_type iproc) const
Definition: distributor.h:170
static tag_type get_new_tag()
returns a new tag
Definition: distributor.cc:133
_base::iterator iterator
Definition: distributor.h:76
size_type process() const
current process id
Definition: distributor.h:186
bool operator!=(const distributor &) const
Definition: distributor.h:232
size_type first_index() const
global index range and local size owned by current process
Definition: distributor.h:196
bool operator==(const distributor &) const
Definition: distributor.h:238
_base::const_iterator const_iterator
Definition: distributor.h:77
communicator_type _comm
Definition: distributor.h:144
size_type size() const
Definition: distributor.h:208
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:220
static const size_type decide
Definition: distributor.h:83
distributor(size_type dis_size=0, const communicator_type &c=communicator_type(), size_type loc_size=decide)
Definition: distributor.cc:88
std::allocator< int >::size_type size_type
Definition: distributor.h:74
const communicator_type & comm() const
Definition: distributor.h:152
This file is part of Rheolef.
DATA::iterator iterator
Definition: Vector.h:183
DATA::const_iterator const_iterator
Definition: Vector.h:184
const_reference at(size_type n) const
Definition: Vector.h:283