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 typename Adapter::base_adapter_t > adapter;
107 const RCP<const Environment> &env_,
108 const RCP<
const Comm<int> > &problemComm_,
109 const RCP<const typename Adapter::base_adapter_t > &adapter_
111 env(env_), problemComm(problemComm_), adapter(adapter_)
119 int rank = env->myRank_;
120 int nprocs = env->numProcs_;
132 ArrayView<const gno_t> idList;
134 ArrayView<input_t> wgtList;
139 bool uniformWeights = (wgtList.size() == 0);
146 const Teuchos::ParameterList &pl = env->getParameters();
147 const Teuchos::ParameterEntry *pe;
149 pe = pl.getEntryPtr(
"partitioning_objective");
151 std::string po = pe->getValue<std::string>(&po);
152 if (po == std::string(
"balance_object_count"))
153 uniformWeights =
true;
156 double imbalanceTolerance=1.1;
157 pe = pl.getEntryPtr(
"imbalance_tolerance");
158 if (pe) imbalanceTolerance = pe->getValue<
double>(&imbalanceTolerance);
164 size_t numGlobalParts = solution->getTargetGlobalNumberOfParts();
166 Array<scalar_t> part_sizes(numGlobalParts);
168 if (solution->criteriaHasUniformPartSizes(0))
169 for (
unsigned int i=0; i<numGlobalParts; i++)
170 part_sizes[i] = 1.0 / numGlobalParts;
172 for (
unsigned int i=0; i<numGlobalParts; i++)
173 part_sizes[i] = solution->getCriteriaPartSize(0, i);
175 for (
unsigned int i=1; i<numGlobalParts; i++)
176 part_sizes[i] += part_sizes[i-1];
191 if (!uniformWeights) {
192 for (
size_t i=0; i<numGnos; i++)
193 wtsum += wgtList[0][i];
196 wtsum =
static_cast<scalar_t>(numGnos);
198 Array<scalar_t> scansum(nprocs+1, 0);
200 Teuchos::gatherAll<int, scalar_t>(*problemComm, 1, &wtsum, nprocs,
201 scansum.getRawPtr()+1);
205 for (
int i=2; i<=nprocs; i++)
206 scansum[i] += scansum[i-1];
208 scalar_t globalTotalWeight = scansum[nprocs];
211 std::ostringstream oss(
"Part sizes: ");
212 for (
unsigned int i=0; i < numGlobalParts; i++)
213 oss << part_sizes[i] <<
" ";
214 oss << std::endl << std::endl <<
"Weights : ";
215 for (
int i=0; i <= nprocs; i++)
216 oss << scansum[i] <<
" ";
223 wtsum = scansum[rank];
224 Array<scalar_t> partTotal(numGlobalParts, 0);
225 ArrayRCP<part_t> gnoPart= arcp(
new part_t[numGnos], 0, numGnos);
227 env->memory(
"Block algorithm memory");
229 for (
size_t i=0; i<numGnos; i++){
230 scalar_t gnoWeight = (uniformWeights ? 1.0 : wgtList[0][i]);
234 while (
unsigned(part)<numGlobalParts-1 &&
235 (wtsum+0.5*gnoWeight) > part_sizes[part]*globalTotalWeight)
238 partTotal[part] += gnoWeight;
245 solution->setParts(gnoPart);
AlgBlock(const RCP< const Environment > &env_, const RCP< const Comm< int > > &problemComm_, const RCP< const typename Adapter::base_adapter_t > &adapter_)
std::bitset< NUM_MODEL_FLAGS > modelFlag_t
map_t::global_ordinal_type gno_t
Defines the PartitioningSolution class.
sub-steps, each method's entry and exit
SparseMatrixAdapter_t::part_t part_t
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.
map_t::local_ordinal_type lno_t
size_t getLocalNumIdentifiers() const
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.
size_t getIdentifierList(ArrayView< const gno_t > &Ids, ArrayView< input_t > &wgts) const