45 #ifndef _ZOLTAN2_ALGBLOCK_HPP_
46 #define _ZOLTAN2_ALGBLOCK_HPP_
90 template <
typename Adapter>
95 const RCP<const Environment> env;
96 const RCP<const Comm<int> > problemComm;
97 const RCP<const IdentifierModel<typename Adapter::base_adapter_t> > ids;
100 typedef typename Adapter::lno_t
lno_t;
101 typedef typename Adapter::gno_t
gno_t;
107 const RCP<const Environment> &env_,
108 const RCP<
const Comm<int> > &problemComm_,
111 env(env_), problemComm(problemComm_), ids(ids_)
119 int rank = env->myRank_;
120 int nprocs = env->numProcs_;
128 size_t numGnos = ids->getLocalNumIdentifiers();
130 ArrayView<const gno_t>
idList;
132 ArrayView<input_t> wgtList;
134 ids->getIdentifierList(idList, wgtList);
137 bool uniformWeights = (wgtList.size() == 0);
144 const Teuchos::ParameterList &pl = env->getParameters();
145 const Teuchos::ParameterEntry *pe;
147 pe = pl.getEntryPtr(
"partitioning_objective");
149 std::string po = pe->getValue<std::string>(&po);
150 if (po == std::string(
"balance_object_count"))
151 uniformWeights =
true;
154 double imbalanceTolerance=1.1;
155 pe = pl.getEntryPtr(
"imbalance_tolerance");
156 if (pe) imbalanceTolerance = pe->getValue<
double>(&imbalanceTolerance);
162 size_t numGlobalParts = solution->getTargetGlobalNumberOfParts();
164 Array<scalar_t> part_sizes(numGlobalParts);
166 if (solution->criteriaHasUniformPartSizes(0))
167 for (
unsigned int i=0; i<numGlobalParts; i++)
168 part_sizes[i] = 1.0 / numGlobalParts;
170 for (
unsigned int i=0; i<numGlobalParts; i++)
171 part_sizes[i] = solution->getCriteriaPartSize(0, i);
173 for (
unsigned int i=1; i<numGlobalParts; i++)
174 part_sizes[i] += part_sizes[i-1];
189 if (!uniformWeights) {
190 for (
size_t i=0; i<numGnos; i++)
191 wtsum += wgtList[0][i];
194 wtsum =
static_cast<scalar_t>(numGnos);
196 Array<scalar_t> scansum(nprocs+1, 0);
198 Teuchos::gatherAll<int, scalar_t>(*problemComm, 1, &wtsum, nprocs,
199 scansum.getRawPtr()+1);
203 for (
int i=2; i<=nprocs; i++)
204 scansum[i] += scansum[i-1];
206 scalar_t globalTotalWeight = scansum[nprocs];
209 std::ostringstream oss(
"Part sizes: ");
210 for (
unsigned int i=0; i < numGlobalParts; i++)
211 oss << part_sizes[i] <<
" ";
212 oss << std::endl << std::endl <<
"Weights : ";
213 for (
int i=0; i <= nprocs; i++)
214 oss << scansum[i] <<
" ";
221 wtsum = scansum[rank];
222 Array<scalar_t> partTotal(numGlobalParts, 0);
223 ArrayRCP<part_t> gnoPart= arcp(
new part_t[numGnos], 0, numGnos);
225 env->memory(
"Block algorithm memory");
227 for (
size_t i=0; i<numGnos; i++){
228 scalar_t gnoWeight = (uniformWeights ? 1.0 : wgtList[0][i]);
232 while (
unsigned(part)<numGlobalParts-1 &&
233 (wtsum+0.5*gnoWeight) > part_sizes[part]*globalTotalWeight)
236 partTotal[part] += gnoWeight;
243 solution->setParts(gnoPart);
AlgBlock(const RCP< const Environment > &env_, const RCP< const Comm< int > > &problemComm_, const RCP< const IdentifierModel< typename Adapter::base_adapter_t > > &ids_)
Defines the PartitioningSolution class.
sub-steps, each method's entry and exit
SparseMatrixAdapter_t::part_t part_t
list idList
Match up parameters to validators.
Defines the IdentifierModel interface.
A PartitioningSolution is a solution to a partitioning problem.
Adapter::scalar_t scalar_t
The StridedData class manages lists of weights or coordinates.
Algorithm defines the base class for all algorithms.
void partition(const RCP< PartitioningSolution< Adapter > > &solution)
Partitioning method.
IdentifierModel defines the interface for all identifier models.
include more detail about sub-steps
blockParams
The boolean parameters of interest to the Block algorithm.