14 #ifndef _ZOLTAN2_MAPPINGSOLUTION_HPP_
15 #define _ZOLTAN2_MAPPINGSOLUTION_HPP_
16 #include "Teuchos_Comm.hpp"
20 #include <unordered_map>
27 template <
typename Adapter>
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
34 typedef typename Adapter::scalar_t t_scalar_t;
42 const RCP<const Environment> &env,
43 const RCP<
const Comm<int> > &comm,
46 env, comm, 1, algorithm),
47 nParts(0), nRanks(1), myRank(comm->getRank()), maxPart(0),
48 mapping_algorithm(algorithm) {}
63 if (mapping_algorithm != Teuchos::null) {
65 mapping_algorithm->getMyPartsView(numParts, parts);
80 if ((partsForRank==Teuchos::null) && (rankForPart==Teuchos::null)) {
83 throw std::runtime_error(
"No mapping solution available.");
86 if (partsForRank == Teuchos::null) {
88 Teuchos::Array<part_t> tmp;
91 for (
typename rankmap_t::iterator it = rankForPart->begin();
92 it != rankForPart->end(); it++) {
93 if (it->second == myRank) {
94 tmp.push_back(it->first);
99 partsForRank = arcp(&tmp[0], 0, cnt,
true);
102 numParts = partsForRank.size();
104 parts = partsForRank.getRawPtr();
124 if (mapping_algorithm != Teuchos::null) {
126 r = mapping_algorithm->getRankForPart(part);
136 if (rankForPart==Teuchos::null) {
137 throw std::runtime_error(
"No mapping solution available.");
140 if (part < 0 || part > maxPart) {
141 throw std::runtime_error(
"Invalid part number input to getRankForPart");
145 typename rankmap_t::iterator it;
146 if ((it = rankForPart->find(part)) != rankForPart->end())
149 throw std::runtime_error(
"Invalid part number input to getRankForPart");
161 nRanks = idx.size() - 1;
162 nParts = parts.size();
165 rankForPart = rcp(
new rankmap_t(idx[nRanks]));
168 for (
int i = 0; i < nRanks; i++) {
169 for (
part_t j = idx[i]; j < idx[i+1]; j++) {
170 (*rankForPart)[parts[j]] = i;
171 if (parts[j] > maxPart) maxPart = parts[j];
177 partsForRank = parts.persistingView(idx[myRank],idx[myRank+1]-idx[myRank]);
193 nParts = parts.size();
197 rankForPart = rcp(
new rankmap_t(parts.size()));
199 for (
size_t i = 0; i < nParts; i++) {
200 (*rankForPart)[parts[i]] = ranks[i];
201 if (parts[i] > maxPart) maxPart = parts[i];
202 if (ranks[i] > maxRank) maxRank = ranks[i];
208 rankForPart = rankmap;
209 nParts = rankForPart.size();
211 typename rankmap_t::iterator it;
212 for (it = rankForPart->begin(); it != rankForPart->end(); it++) {
213 if (it->first > maxPart) maxPart = it->first;
214 if (it->second > maxRank) maxRank = it->second;
230 ArrayRCP<part_t> partsForRankIdx;
231 ArrayRCP<part_t> partsForRank;
232 RCP<rankmap_t> rankForPart;
234 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.
map_t::global_ordinal_type gno_t
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.
map_t::local_ordinal_type lno_t
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)