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;
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();
128 typedef Tpetra::Map<>::global_ordinal_type use_this_gno_t;
130 std::set<use_this_gno_t> unique;
131 for (
size_t i = 0; i < nLocal; i++)
132 unique.insert(partList[i]);
134 size_t nUnique = unique.size();
135 Array<use_this_gno_t> uniquePartList(nUnique);
137 for (
typename std::set<use_this_gno_t>::iterator it = unique.begin();
138 it != unique.end(); it++)
139 uniquePartList[k++] = *it;
144 Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid();
145 Tpetra::Map<lno_t, use_this_gno_t> tmap(nGlobalElts, uniquePartList(),
148 nParts = Teuchos::as<part_t>(tmap.getGlobalNumElements());
149 minPart = tmap.getMinAllGlobalIndex();
150 maxPart = tmap.getMaxAllGlobalIndex();
156 if ((minPart != 0) || (maxPart != nParts-1)) {
158 throw std::runtime_error(
"Cannot use mapping_algorithm = contiguous "
159 "unless parts are numbered from 0 to nParts-1");
170 const Teuchos::RCP <
const Teuchos::Comm<int> > comm_,
171 const part_t nparts) :
172 nRanks(comm_->getSize()),
174 myRank(comm_->getRank()),
176 myParts(Teuchos::null)
183 nParts_Div_nRanks = nParts / nRanks;
184 nParts_Mod_nRanks = nParts % nRanks;
185 nMyParts = nParts_Div_nRanks + (myRank < nParts_Mod_nRanks);
195 if (p < 0 || p >= nParts)
196 throw std::runtime_error(
"Invalid part in getRankForPart");
198 int tmp = p / nParts_Div_nRanks;
199 while (firstPart(tmp) > p) tmp--;
200 while (firstPart(tmp+1) < p) tmp++;
210 if (myParts == Teuchos::null) {
211 myParts = arcp(
new part_t[nMyParts], 0, nMyParts,
true);
212 for (part_t i = 0; i < nMyParts; i++)
213 myParts[i] = firstPart(myRank) + i;
215 parts = myParts.getRawPtr();
223 inline part_t firstPart(
int rank) {
225 return (rank * nParts_Div_nRanks + std::min(rank, nParts_Mod_nRanks));
235 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)
SparseMatrixAdapter_t::part_t part_t
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.
Tpetra::global_size_t global_size_t
A gathering of useful namespace methods.
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t