10 #ifndef _ZOLTAN2_ALGDEFAULTMAPPING_HPP_
11 #define _ZOLTAN2_ALGDEFAULTMAPPING_HPP_
27 template <
typename Adapter>
28 class AlgDefaultMapping :
public Algorithm<Adapter>
35 typedef typename Adapter::scalar_t scalar_t;
38 typedef typename Adapter::userCoord_t userCoord_t;
40 const RCP<const Environment> env;
41 const RCP<const Comm<int> > problemComm;
42 const RCP<const typename Adapter::base_adapter_t> adapter;
52 const Teuchos::RCP <
const Teuchos::Comm<int> > &comm_,
54 const Teuchos::RCP <const Adapter> &adapter_,
56 const Teuchos::RCP <const Environment> &envConst):
57 env(env__), comm(comm_), adapter(adapter_),
58 partIsRank(false), haveContigousParts(false)
59 rankForPart(Teuchos::null)
61 int nRanks = comm->getSize();
66 if (psoln_ != Teuchos::null) {
67 partList = psoln_->getPartListView();
70 adapter->getPartsView(partList);
74 typedef typename Tpetra::Map<lno_t, part_t> tpetraMap_t
75 Teuchos::RCP<tpetraMap_t> tmap;
77 part_t minPart, maxPart;
79 if (partList == NULL) {
91 size_t nLocal = adapter->getLocalNumIDs();
93 std::set<part_t> unique(nLocal);
94 for (
size_t i; i < adapter->getLocalNumIDs(); i++)
95 unique.insert(partList[i]);
97 size_t nUnique = unique.size();
98 Array<const part_t> uniquePartList(nUnique);
100 for (
typename std::set<part_t>::iterator it = set.begin();
101 it != set.end(); it++)
102 uniquePartList[k++] = *it;
107 Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid();
108 tmap = rcp(
new tpetraMap_t(nGlobalElts, uniquePartList(), 0, comm));
110 nParts = as<part_t>(tmap->getGlobalNumElements());
111 minPart = tmap->getMinAllGlobalIndex();
112 maxPart = tmap->getMaxAllGlobalIndex();
115 nParts_Div_nRanks =
nParts / nRanks;
116 nParts_Mod_nRanks =
nParts % nRanks;
121 if (maxPart < nRanks)
124 if ((minPart == 0) && (maxPart ==
nParts-1))
126 haveContiguousParts =
true;
128 if (!partIsRank && !haveContiguousParts) {
130 Teuchos::RCP<tpetraMap_t> oneToOneMap = Tpetra::createOneToOne(tmap);
135 Teuchos::RCP<tpetraMap_t> gatheredMap = ;
137 Teuchos::ArrayView<const part_t> allParts =
138 gatheredMap->getLocalElementList();
141 Teuchos::Array<int> allRanks(allParts.size());
142 oneToOneMap->getRemoveIndexList(allParts, allRanks());
144 for (
size_t i = 0; i < allPart.size())
145 (*rankForPart)[allParts[i]] = allRanks[i];
157 if (p < 0 || p > maxPart)
158 throw std::runtime_error(
"Invalid part in getRankForPart");
165 if (haveContiguousParts) {
166 int tmp = p / nParts_Div_nRanks;
167 while (firstContiguousPart(tmp) > p) tmp--;
168 while (firstContiguousPart(tmp+1) < p) tmp++;
173 return rankForPart[p];
180 partsForRankIdx = rcp(
new part_t[nRanks+1]);
181 partsForRank = rcp(
new part_t[
nParts]);
189 inline part_t firstContiguousPart(
int rank) {
191 return (rank * nParts_Div_nRanks + min(rank, nParts_Mod_nRanks));
void getPartsForRankView(int rank, part_t &numParts, part_t *&parts)
PartitionMapping maps a solution or an input distribution to ranks.
void map(Teuchos::RCP< MappingSolution< Adapter > > msoln)
map_t::global_ordinal_type gno_t
Defines the PartitioningSolution class.
AlgDefaultMapping(const Teuchos::RCP< const Teuchos::Comm< int > > &comm_, const Teuchos::RCP< const MachineRepresentation< pcoord_t, part_t > > &machine_, const Teuchos::RCP< const Adapter > &adapter_, const Teuchos::RCP< const Zoltan2::PartitioningSolution< Adapter > > &psoln_, const Teuchos::RCP< const Environment > &envConst)
SparseMatrixAdapter_t::part_t part_t
A PartitioningSolution is a solution to a partitioning problem.
map_t::local_ordinal_type lno_t
MachineRepresentation Class Base class for representing machine coordinates, networks, etc.
int getRankForPart(part_t p)
In mapping, returns the rank to which a part is assigned.
Gathering definitions used in software development.
Tpetra::global_size_t global_size_t
A gathering of useful namespace methods.
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t