Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
worldcomm.hpp
Go to the documentation of this file.
1 /* -*- mode: c++; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; show-trailing-whitespace: t -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2 
3  This file is part of the Feel library
4 
5  Author(s): Vincent Chabannes <vincent.chabannes@imag.fr>
6  Date: 2012-02-14
7 
8  Copyright (C) 2012 Université Joseph Fourier (Grenoble I)
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 3.0 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
29 #ifndef __worldcomm_H
30 #define __worldcomm_H 1
31 
32 #include <boost/mpi.hpp>
33 #if defined(FEELPP_HAS_MPI_H)
34 #include <mpi.h>
35 #endif /* FEELPP_HAS_MPI_H */
36 #include <boost/smart_ptr/enable_shared_from_this.hpp>
37 
38 namespace Feel
39 {
40 
41 
42 class WorldComm : public boost::mpi::communicator, public boost::enable_shared_from_this<WorldComm>
43 {
44 
45  typedef boost::mpi::communicator super;
46 
47 public:
48 
49  typedef WorldComm self_type;
50  typedef boost::shared_ptr<WorldComm> self_ptrtype;
51  typedef boost::mpi::communicator communicator_type;
52 
53  WorldComm();
54  WorldComm( super const& );
55 
56  WorldComm( int _color );
57 
58  // A supp
59  WorldComm( std::vector<int> const& _colorWorld );
60  WorldComm( std::vector<int> const& _colorWorld, int localRank,
61  communicator_type const& _globalComm=communicator_type(),
62  communicator_type const& _godComm=communicator_type() );
63 
64  WorldComm( WorldComm const& _wc );
65 
66  WorldComm( communicator_type const& _globalComm,
67  int _color,
68  bool _isActive );
69 
70  WorldComm( int _colorLocal,int localRank,int _colorGlobal,int globalRank,
71  communicator_type const& _godComm,
72  bool _isActive,
73  bool _doInitActiveMap=true );
74 
75  // A supp
76  WorldComm( communicator_type const& _globalComm,
77  communicator_type const& _godComm,
78  int _localColor, int localRank,
79  std::vector<int> const& isActive );
80  WorldComm( communicator_type const& _globalComm,
81  communicator_type const& _localComm,
82  communicator_type const& _godComm,
83  int _localColor,// int localRank,
84  std::vector<int> const& isActive );
85 
86  static self_ptrtype New() { return self_ptrtype(new self_type); }
87  static self_ptrtype New( super const& s ) { return self_ptrtype(new self_type( s )); }
88  void init( int color = 0, bool colormap = false );
89  communicator_type const& globalComm() const
90  {
91  return *this;
92  }
93  communicator_type const& localComm() const
94  {
95  return M_localComm;
96  }
97  communicator_type const& godComm() const
98  {
99  return M_godComm;
100  }
101  communicator_type const& comm() const
102  {
103  return M_localComm;
104  }
105 
106  int globalSize() const
107  {
108  return this->globalComm().size();
109  }
110  int localSize() const
111  {
112  return this->localComm().size();
113  }
114  int godSize() const
115  {
116  return this->godComm().size();
117  }
118 
119  int globalRank() const
120  {
121  return this->globalComm().rank();
122  }
123  int localRank() const
124  {
125  return this->localComm().rank();
126  }
127  int godRank() const
128  {
129  return this->godComm().rank();
130  }
131 
132  bool hasSubWorlds( int n );
133  std::vector<WorldComm> const& subWorlds( int n );
134  std::vector<WorldComm> const& subWorldsGroupBySubspace( int n );
135  WorldComm const& subWorld( int n ) ;
136  int subWorldId( int n ) ;
137 
138  std::vector<int> const& mapColorWorld() const
139  {
140  return M_mapColorWorld;
141  }
142  std::vector<int> const& mapLocalRankToGlobalRank() const
143  {
144  return M_mapLocalRankToGlobalRank;
145  }
146  std::vector<int> const& mapGlobalRankToGodRank() const
147  {
148  return M_mapGlobalRankToGodRank;
149  }
150 
151  int mapColorWorld(int k) const
152  {
153  return M_mapColorWorld[k];
154  }
155  int mapLocalRankToGlobalRank(int k) const
156  {
157  return M_mapLocalRankToGlobalRank[k];
158  }
159  int mapGlobalRankToGodRank(int k) const
160  {
161  return M_mapGlobalRankToGodRank[k];
162  }
163 
164 
165  int masterRank() const
166  {
167  return M_masterRank;
168  }
169 
170  WorldComm subWorldComm() const;
171  WorldComm subWorldComm( int color ) const;
172  WorldComm subWorldComm( std::vector<int> const& colormap ) ;
173  WorldComm subWorldComm( int color, std::vector<int> const& colormap ) ;
174  WorldComm const& masterWorld( int n );
175  int numberOfSubWorlds() const;
176 
177  WorldComm subWorldCommSeq() const;
178 
179 
180  bool isActive() const
181  {
182  return M_isActive[this->godRank()];
183  }
184 
185  std::vector<int> const& activityOnWorld() const
186  {
187  return M_isActive;
188  }
189 
190  int localColorToGlobalRank( int _color,int _localRank ) const;
191 
192  void setColorMap( std::vector<int> const& colormap );
193 
197  void showMe( std::ostream& __out = std::cout ) const;
198 
199  WorldComm operator+( WorldComm const & _worldComm ) const;
200 
201  void setIsActive( std::vector<int> const& _isActive ) const { M_isActive=_isActive; }
202 
203  void upMasterRank();
204 
205  void applyActivityOnlyOn(int _localColor) const;
206 
207  boost::tuple<bool,std::set<int> > hasMultiLocalActivity() const;
208 
212  void registerSubWorlds( int n );
213  void registerSubWorldsGroupBySubspace( int n );
214 
215 private :
216 
217  communicator_type M_localComm;
218  communicator_type M_godComm;
219 
220  std::vector<int> M_mapColorWorld;
221  std::vector<int> M_mapLocalRankToGlobalRank;
222  std::vector<int> M_mapGlobalRankToGodRank;
223  std::map<int, std::pair<WorldComm,std::vector<WorldComm> > > M_subworlds;
224 
225  int M_masterRank;
226  mutable std::vector<int/*bool*/> M_isActive;
227 
228 };
229 
230 } //namespace Feel
231 
232 #endif // __worldcomm_H

Generated on Sun Oct 20 2013 08:25:06 for Feel++ by doxygen 1.8.4