30 #define __worldcomm_H 1
32 #include <boost/mpi.hpp>
33 #if defined(FEELPP_HAS_MPI_H)
36 #include <boost/smart_ptr/enable_shared_from_this.hpp>
42 class WorldComm :
public boost::mpi::communicator,
public boost::enable_shared_from_this<WorldComm>
45 typedef boost::mpi::communicator super;
49 typedef WorldComm self_type;
50 typedef boost::shared_ptr<WorldComm> self_ptrtype;
51 typedef boost::mpi::communicator communicator_type;
54 WorldComm( super
const& );
56 WorldComm(
int _color );
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() );
64 WorldComm( WorldComm
const& _wc );
66 WorldComm( communicator_type
const& _globalComm,
70 WorldComm(
int _colorLocal,
int localRank,
int _colorGlobal,
int globalRank,
71 communicator_type
const& _godComm,
73 bool _doInitActiveMap=
true );
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,
84 std::vector<int>
const& isActive );
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
93 communicator_type
const& localComm()
const
97 communicator_type
const& godComm()
const
101 communicator_type
const& comm()
const
106 int globalSize()
const
108 return this->globalComm().size();
110 int localSize()
const
112 return this->localComm().size();
116 return this->godComm().size();
119 int globalRank()
const
121 return this->globalComm().rank();
123 int localRank()
const
125 return this->localComm().rank();
129 return this->godComm().rank();
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 ) ;
138 std::vector<int>
const& mapColorWorld()
const
140 return M_mapColorWorld;
142 std::vector<int>
const& mapLocalRankToGlobalRank()
const
144 return M_mapLocalRankToGlobalRank;
146 std::vector<int>
const& mapGlobalRankToGodRank()
const
148 return M_mapGlobalRankToGodRank;
151 int mapColorWorld(
int k)
const
153 return M_mapColorWorld[k];
155 int mapLocalRankToGlobalRank(
int k)
const
157 return M_mapLocalRankToGlobalRank[k];
159 int mapGlobalRankToGodRank(
int k)
const
161 return M_mapGlobalRankToGodRank[k];
165 int masterRank()
const
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;
177 WorldComm subWorldCommSeq()
const;
180 bool isActive()
const
182 return M_isActive[this->godRank()];
185 std::vector<int>
const& activityOnWorld()
const
190 int localColorToGlobalRank(
int _color,
int _localRank )
const;
192 void setColorMap( std::vector<int>
const& colormap );
197 void showMe( std::ostream& __out = std::cout )
const;
199 WorldComm operator+( WorldComm
const & _worldComm )
const;
201 void setIsActive( std::vector<int>
const& _isActive )
const { M_isActive=_isActive; }
205 void applyActivityOnlyOn(
int _localColor)
const;
207 boost::tuple<bool,std::set<int> > hasMultiLocalActivity()
const;
212 void registerSubWorlds(
int n );
213 void registerSubWorldsGroupBySubspace(
int n );
217 communicator_type M_localComm;
218 communicator_type M_godComm;
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;
226 mutable std::vector<
int> M_isActive;
232 #endif // __worldcomm_H