50 #ifndef _ZOLTAN2_MAPPINGSOLUTION_HPP_
51 #define _ZOLTAN2_MAPPINGSOLUTION_HPP_
52 #include "Teuchos_Comm.hpp"
56 #include <unordered_map>
63 template <
typename Adapter>
68 #ifndef DOXYGEN_SHOULD_SKIP_THIS
70 typedef typename Adapter::scalar_t t_scalar_t;
71 typedef typename Adapter::lno_t lno_t;
72 typedef typename Adapter::gno_t gno_t;
78 const RCP<const Environment> &env,
79 const RCP<
const Comm<int> > &comm,
82 env, comm, 1, algorithm),
83 nParts(0), nRanks(1), myRank(comm->getRank()), maxPart(0),
84 mapping_algorithm(algorithm) {}
99 if (mapping_algorithm != Teuchos::null) {
101 mapping_algorithm->getMyPartsView(numParts, parts);
116 if ((partsForRank==Teuchos::null) && (rankForPart==Teuchos::null)) {
119 throw std::runtime_error(
"No mapping solution available.");
122 if (partsForRank == Teuchos::null) {
124 Teuchos::Array<part_t> tmp;
127 for (
typename rankmap_t::iterator it = rankForPart->begin();
128 it != rankForPart->end(); it++) {
129 if (it->second == myRank) {
130 tmp.push_back(it->first);
135 partsForRank = arcp(&tmp[0], 0, cnt,
true);
138 numParts = partsForRank.size();
140 parts = partsForRank.getRawPtr();
160 if (mapping_algorithm != Teuchos::null) {
162 r = mapping_algorithm->getRankForPart(part);
172 if (rankForPart==Teuchos::null) {
173 throw std::runtime_error(
"No mapping solution available.");
176 if (part < 0 || part > maxPart) {
177 throw std::runtime_error(
"Invalid part number input to getRankForPart");
181 typename rankmap_t::iterator it;
182 if ((it = rankForPart->find(part)) != rankForPart->end())
185 throw std::runtime_error(
"Invalid part number input to getRankForPart");
197 nRanks = idx.size() - 1;
198 nParts = parts.size();
201 rankForPart = rcp(
new rankmap_t(idx[nRanks]));
204 for (
int i = 0; i < nRanks; i++) {
205 for (
part_t j = idx[i]; j < idx[i+1]; j++) {
206 (*rankForPart)[parts[j]] = i;
207 if (parts[j] > maxPart) maxPart = parts[j];
213 partsForRank = parts.persistingView(idx[myRank],idx[myRank+1]-idx[myRank]);
229 nParts = parts.size();
233 rankForPart = rcp(
new rankmap_t(parts.size()));
235 for (
size_t i = 0; i < nParts; i++) {
236 (*rankForPart)[parts[i]] = ranks[i];
237 if (parts[i] > maxPart) maxPart = parts[i];
238 if (ranks[i] > maxRank) maxRank = ranks[i];
244 rankForPart = rankmap;
245 nParts = rankForPart.size();
247 typename rankmap_t::iterator it;
248 for (it = rankForPart->begin(); it != rankForPart->end(); it++) {
249 if (it->first > maxPart) maxPart = it->first;
250 if (it->second > maxRank) maxRank = it->second;
266 ArrayRCP<part_t> partsForRankIdx;
267 ArrayRCP<part_t> partsForRank;
268 RCP<rankmap_t> rankForPart;
270 const RCP<Algorithm<Adapter> > mapping_algorithm;
void setMap_PartsForRank(ArrayRCP< int > &idx, ArrayRCP< part_t > &parts)
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
PartitionMapping maps a solution or an input distribution to ranks.
void setMap_RankForLocalElements(ArrayRCP< int > &ranks)
This is a mapping from local elements to ranks.
std::unordered_map< lno_t, int > rankmap_t
MappingSolution(const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, const RCP< Algorithm< Adapter > > &algorithm=Teuchos::null)
Constructor.
Defines the PartitioningSolution class.
void setMap_RankForPart(ArrayRCP< part_t > &parts, ArrayRCP< int > &ranks)
SparseMatrixAdapter_t::part_t part_t
A PartitioningSolution is a solution to a partitioning problem.
Exception thrown when a called base-class method is not implemented.
Algorithm defines the base class for all algorithms.
virtual ~MappingSolution()
void setParts(ArrayRCP< part_t > &partList)
The algorithm uses setParts to set the solution.
int getRankForPart(part_t part)
Get the rank containing a part. Simplifying assumption: a part is wholy assigned to a rank; it is not...
void getMyPartsView(part_t &numParts, part_t *&parts)
Get the parts belonging to this rank.
Defines the Environment class.
void setMap_RankForPart(RCP< rankmap_t > &rankmap)