45 #ifndef _ZOLTAN2_ALGBLOCKMAPPING_HPP_ 46 #define _ZOLTAN2_ALGBLOCKMAPPING_HPP_ 52 #include <Tpetra_Map.hpp> 67 template <
typename Adapter,
typename MachineRep>
73 typedef typename Adapter::lno_t lno_t;
74 typedef typename Adapter::gno_t gno_t;
75 typedef typename Adapter::scalar_t scalar_t;
76 typedef typename Adapter::part_t part_t;
77 typedef typename Adapter::user_t user_t;
78 typedef typename Adapter::userCoord_t userCoord_t;
88 const Teuchos::RCP <
const Teuchos::Comm<int> > &comm_,
89 const Teuchos::RCP <const MachineRep> &machine_,
90 const Teuchos::RCP <const Adapter> &adapter_,
92 const Teuchos::RCP <const Environment> &envConst):
93 nRanks(comm_->getSize()), myRank(comm_->getRank()),
94 nMyParts(0), myParts(
Teuchos::null)
98 const part_t *partList;
99 if (psoln_ != Teuchos::null) {
100 partList = psoln_->getPartListView();
103 adapter_->getPartsView(partList);
108 part_t minPart, maxPart;
110 if (partList == NULL) {
122 size_t nLocal = adapter_->getLocalNumIDs();
124 std::set<part_t> unique;
125 for (
size_t i = 0; i < nLocal; i++)
126 unique.insert(partList[i]);
128 size_t nUnique = unique.size();
129 Array<part_t> uniquePartList(nUnique);
131 for (
typename std::set<part_t>::iterator it = unique.begin();
132 it != unique.end(); it++)
133 uniquePartList[k++] = *it;
142 Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid();
143 Tpetra::Map<lno_t, part_t> tmap(nGlobalElts, uniquePartList(), 0, comm_);
145 nParts = Teuchos::as<part_t>(tmap.getGlobalNumElements());
146 minPart = tmap.getMinAllGlobalIndex();
147 maxPart = tmap.getMaxAllGlobalIndex();
153 if ((minPart != 0) || (maxPart != nParts-1)) {
155 throw std::runtime_error(
"Cannot use mapping_algorithm = contiguous " 156 "unless parts are numbered from 0 to nParts-1");
167 const Teuchos::RCP <
const Teuchos::Comm<int> > comm_,
168 const part_t nparts) :
169 nRanks(comm_->getSize()),
171 myRank(comm_->getRank()),
180 nParts_Div_nRanks = nParts / nRanks;
181 nParts_Mod_nRanks = nParts % nRanks;
182 nMyParts = nParts_Div_nRanks + (myRank < nParts_Mod_nRanks);
192 if (p < 0 || p >= nParts)
193 throw std::runtime_error(
"Invalid part in getRankForPart");
195 int tmp = p / nParts_Div_nRanks;
196 while (firstPart(tmp) > p) tmp--;
197 while (firstPart(tmp+1) < p) tmp++;
207 if (myParts == Teuchos::null) {
208 myParts = arcp(
new part_t[nMyParts], 0, nMyParts,
true);
209 for (part_t i = 0; i < nMyParts; i++)
210 myParts[i] = firstPart(myRank) + i;
212 parts = myParts.getRawPtr();
220 inline part_t firstPart(
int rank) {
222 return (rank * nParts_Div_nRanks + min(rank, nParts_Mod_nRanks));
227 part_t nParts_Div_nRanks;
228 part_t nParts_Mod_nRanks;
232 ArrayRCP<part_t> myParts;
PartitionMapping maps a solution or an input distribution to ranks.
void getMyPartsView(part_t &numParts, part_t *&parts)
In mapping, returns a view of parts assigned to the current rank.
Defines the PartitioningSolution class.
void map(const Teuchos::RCP< MappingSolution< Adapter > > &msoln)
AlgBlockMapping(const Teuchos::RCP< const Teuchos::Comm< int > > &comm_, const Teuchos::RCP< const MachineRep > &machine_, const Teuchos::RCP< const Adapter > &adapter_, const Teuchos::RCP< const Zoltan2::PartitioningSolution< Adapter > > &psoln_, const Teuchos::RCP< const Environment > &envConst)
AlgBlockMapping(const Teuchos::RCP< const Teuchos::Comm< int > > comm_, const part_t nparts)
Constructor that allows this mapping method to be used as a.
A PartitioningSolution is a solution to a partitioning problem.
int getRankForPart(part_t p)
In mapping, returns the rank to which a part is assigned.
Algorithm defines the base class for all algorithms.
Gathering definitions used in software development.
A gathering of useful namespace methods.