10 #ifndef _ZOLTAN2_ALGBLOCKMAPPING_HPP_
11 #define _ZOLTAN2_ALGBLOCKMAPPING_HPP_
17 #include <Tpetra_Map.hpp>
32 template <
typename Adapter,
typename MachineRep>
40 typedef typename Adapter::scalar_t scalar_t;
43 typedef typename Adapter::userCoord_t userCoord_t;
53 const Teuchos::RCP <
const Teuchos::Comm<int> > &comm_,
54 const Teuchos::RCP <const MachineRep> &machine_,
55 const Teuchos::RCP <const Adapter> &adapter_,
57 const Teuchos::RCP <const Environment> &envConst):
58 nRanks(comm_->getSize()), myRank(comm_->getRank()),
59 nMyParts(0), myParts(Teuchos::null)
63 const part_t *partList;
64 if (psoln_ != Teuchos::null) {
65 partList = psoln_->getPartListView();
68 adapter_->getPartsView(partList);
73 part_t minPart, maxPart;
75 if (partList == NULL) {
87 size_t nLocal = adapter_->getLocalNumIDs();
93 typedef Tpetra::Map<>::global_ordinal_type use_this_gno_t;
95 std::set<use_this_gno_t> unique;
96 for (
size_t i = 0; i < nLocal; i++)
97 unique.insert(partList[i]);
99 size_t nUnique = unique.size();
100 Array<use_this_gno_t> uniquePartList(nUnique);
102 for (
typename std::set<use_this_gno_t>::iterator it = unique.begin();
103 it != unique.end(); it++)
104 uniquePartList[k++] = *it;
109 Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid();
110 Tpetra::Map<lno_t, use_this_gno_t> tmap(nGlobalElts, uniquePartList(),
113 nParts = Teuchos::as<part_t>(tmap.getGlobalNumElements());
114 minPart = tmap.getMinAllGlobalIndex();
115 maxPart = tmap.getMaxAllGlobalIndex();
121 if ((minPart != 0) || (maxPart != nParts-1)) {
123 throw std::runtime_error(
"Cannot use mapping_algorithm = contiguous "
124 "unless parts are numbered from 0 to nParts-1");
135 const Teuchos::RCP <
const Teuchos::Comm<int> > comm_,
136 const part_t nparts) :
137 nRanks(comm_->getSize()),
139 myRank(comm_->getRank()),
141 myParts(Teuchos::null)
148 nParts_Div_nRanks = nParts / nRanks;
149 nParts_Mod_nRanks = nParts % nRanks;
150 nMyParts = nParts_Div_nRanks + (myRank < nParts_Mod_nRanks);
160 if (p < 0 || p >= nParts)
161 throw std::runtime_error(
"Invalid part in getRankForPart");
163 int tmp = p / nParts_Div_nRanks;
164 while (firstPart(tmp) > p) tmp--;
165 while (firstPart(tmp+1) < p) tmp++;
175 if (myParts == Teuchos::null) {
176 myParts = arcp(
new part_t[nMyParts], 0, nMyParts,
true);
177 for (part_t i = 0; i < nMyParts; i++)
178 myParts[i] = firstPart(myRank) + i;
180 parts = myParts.getRawPtr();
188 inline part_t firstPart(
int rank) {
190 return (rank * nParts_Div_nRanks + std::min(rank, nParts_Mod_nRanks));
200 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.
map_t::global_ordinal_type gno_t
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.
map_t::local_ordinal_type lno_t
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