45 #ifndef _ZOLTAN2_ALGDEFAULTMAPPING_HPP_
46 #define _ZOLTAN2_ALGDEFAULTMAPPING_HPP_
62 template <
typename Adapter>
63 class AlgDefaultMapping :
public Algorithm<Adapter>
68 typedef typename Adapter::lno_t lno_t;
69 typedef typename Adapter::gno_t gno_t;
70 typedef typename Adapter::scalar_t scalar_t;
73 typedef typename Adapter::userCoord_t userCoord_t;
75 const RCP<const Environment> env;
76 const RCP<const Comm<int> > problemComm;
77 const RCP<const typename Adapter::base_adapter_t> adapter;
87 const Teuchos::RCP <
const Teuchos::Comm<int> > &comm_,
89 const Teuchos::RCP <const Adapter> &adapter_,
91 const Teuchos::RCP <const Environment> &envConst):
92 env(env__), comm(comm_), adapter(adapter_),
93 partIsRank(false), haveContigousParts(false)
94 rankForPart(Teuchos::null)
96 int nRanks = comm->getSize();
101 if (psoln_ != Teuchos::null) {
102 partList = psoln_->getPartListView();
105 adapter->getPartsView(partList);
109 typedef typename Tpetra::Map<lno_t, part_t> tpetraMap_t
110 Teuchos::RCP<tpetraMap_t> tmap;
112 part_t minPart, maxPart;
114 if (partList == NULL) {
126 size_t nLocal = adapter->getLocalNumIDs();
128 std::set<part_t> unique(nLocal);
129 for (
size_t i; i < adapter->getLocalNumIDs(); i++)
130 unique.insert(partList[i]);
132 size_t nUnique = unique.size();
133 Array<const part_t> uniquePartList(nUnique);
135 for (
typename std::set<part_t>::iterator it = set.begin();
136 it != set.end(); it++)
137 uniquePartList[k++] = *it;
142 Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid();
143 tmap = rcp(
new tpetraMap_t(nGlobalElts, uniquePartList(), 0, comm));
145 nParts = as<part_t>(tmap->getGlobalNumElements());
146 minPart = tmap->getMinAllGlobalIndex();
147 maxPart = tmap->getMaxAllGlobalIndex();
150 nParts_Div_nRanks =
nParts / nRanks;
151 nParts_Mod_nRanks =
nParts % nRanks;
156 if (maxPart < nRanks)
159 if ((minPart == 0) && (maxPart ==
nParts-1))
161 haveContiguousParts =
true;
163 if (!partIsRank && !haveContiguousParts) {
165 Teuchos::RCP<tpetraMap_t> oneToOneMap = Tpetra::createOneToOne(tmap);
170 Teuchos::RCP<tpetraMap_t> gatheredMap = ;
172 Teuchos::ArrayView<const part_t> allParts =
173 gatheredMap->getNodeElementList();
176 Teuchos::Array<int> allRanks(allParts.size());
177 oneToOneMap->getRemoveIndexList(allParts, allRanks());
179 for (
size_t i = 0; i < allPart.size())
180 (*rankForPart)[allParts[i]] = allRanks[i];
192 if (p < 0 || p > maxPart)
193 throw std::runtime_error(
"Invalid part in getRankForPart");
200 if (haveContiguousParts) {
201 int tmp = p / nParts_Div_nRanks;
202 while (firstContiguousPart(tmp) > p) tmp--;
203 while (firstContiguousPart(tmp+1) < p) tmp++;
208 return rankForPart[p];
215 partsForRankIdx = rcp(
new part_t[nRanks+1]);
216 partsForRank = rcp(
new part_t[
nParts]);
224 inline part_t firstContiguousPart(
int rank) {
226 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)
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.
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