60 using Teuchos::ArrayRCP;
70 template<
class idInput_t>
71 void doTest(RCP<
const Comm<int> > comm,
int numLocalObj,
72 int nWeights,
int numLocalParts,
bool givePartSizes);
80 typedef Tpetra::CrsGraph<zlno_t, zgno_t, znode_t>
tcrsGraph_t;
85 template<
class idInput_t>
void runTestSuite(RCP<
const Comm<int> > comm) {
86 doTest<idInput_t>(comm, 10, 0, -1,
false);
87 doTest<idInput_t>(comm, 10, 0, 1,
false);
88 doTest<idInput_t>(comm, 10, 0, 1,
true);
89 doTest<idInput_t>(comm, 10, 1, 1,
false);
90 doTest<idInput_t>(comm, 10, 1, 1,
true);
91 doTest<idInput_t>(comm, 10, 2, 1,
false);
92 doTest<idInput_t>(comm, 10, 2, 1,
true);
93 doTest<idInput_t>(comm, 10, 1, 2,
true);
94 doTest<idInput_t>(comm, 10, 1, 2,
false);
95 doTest<idInput_t>(comm, 10, 1, -1,
false);
96 doTest<idInput_t>(comm, 10, 1, -1,
true);
97 doTest<idInput_t>(comm, 10, 2, -1,
false);
100 int main(
int narg,
char *arg[])
102 Tpetra::ScopeGuard tscope(&narg, &arg);
103 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
105 int rank = comm->getRank();
108 runTestSuite<basic_idInput_t>(comm);
113 runTestSuite<graph_idInput_t>(comm);
117 std::cout <<
"PASS" << std::endl;
126 template<
class idInput_t>
129 int nWeights,
int original_numLocalParts,
bool givePartSizes) {
131 int rank = comm->getRank();
135 object_count_imbalance = metricObject->getObjectCountImbalance();
137 cout <<
"Object imbalance: " << object_count_imbalance << endl;
140 catch (std::exception &e){
147 for (
int i=0; i < nWeights; i++){
148 zscalar_t imb = metricObject->getWeightImbalance(i);
150 cout <<
"Weight " << i <<
" imbalance: " << imb << endl;
154 catch (std::exception &e){
157 if (!fail && nWeights > 1){
159 zscalar_t imb = metricObject->getNormedImbalance();
161 cout <<
"Normed weight imbalance: " << imb << endl;
164 catch (std::exception &e){
172 template<
class idInput_t>
175 int nWeights,
int original_numLocalParts,
bool givePartSizes) {
176 throw std::logic_error(
"evaluate_result not implemented.");
181 RCP<Zoltan2::EvaluatePartition<graph_idInput_t>> metricObject,
int numLocalObj,
182 int nWeights,
int original_numLocalParts,
bool givePartSizes) {
184 int rank = comm->getRank();
186 int total_edge_cut = -1;
190 total_edge_cut =
static_cast<int>(metricObject->getTotalEdgeCut());
192 cout <<
"Total Edge Cut: " << total_edge_cut << endl;
195 catch (std::exception &e){
200 int max_edge_cut = -1;
202 max_edge_cut =
static_cast<int>(metricObject->getMaxEdgeCut());
204 cout <<
"Max Edge Cut: " << max_edge_cut << endl;
207 catch (std::exception &e){
212 int total_messages = -1;
214 total_messages =
static_cast<int>(metricObject->getTotalMessages());
216 cout <<
"Total Messages: " << total_messages << endl;
219 catch (std::exception &e){
224 int max_messages = -1;
226 max_messages =
static_cast<int>(metricObject->getMaxMessages());
228 cout <<
"Max Messages: " << max_messages << endl;
231 catch (std::exception &e){
247 int num_procs = comm->getSize();
248 int expected_total_edge_cuts = (num_procs == 1) ? 0 :
249 (2 * numLocalObj) + ((num_procs-2) * numLocalObj * 2);
251 "getTotalEdgeCut is not the expected ", 1);
258 int expected_max_edge_cuts = (num_procs == 1) ? 0 :
259 (num_procs == 2) ? numLocalObj : numLocalObj * 2;
261 "getMaxEdgeCut is not the expected value", 1);
265 int expected_total_messages = expected_total_edge_cuts / numLocalObj;
267 "getTotalMessages is not the expected value", 1);
271 int expected_max_messages = expected_max_edge_cuts / numLocalObj;
273 "getMaxMessages is not the expected value", 1);
276 numLocalObj, nWeights, original_numLocalParts, givePartSizes);
283 RCP<Zoltan2::EvaluatePartition<basic_idInput_t>> metricObject,
int numLocalObj,
284 int nWeights,
int original_numLocalParts,
bool givePartSizes) {
286 numLocalObj, nWeights, original_numLocalParts, givePartSizes);
289 template<
class idInput_t>
291 int numLocalObj,
zgno_t *myGids,
292 std::vector<const zscalar_t *> &
weights,
293 std::vector<int> & strides) {
294 throw std::logic_error(
"create_adapter not implemented.");
299 int numLocalObj,
zgno_t *myGids,
300 std::vector<const zscalar_t *> &
weights,
301 std::vector<int> & strides) {
303 typedef Tpetra::Map<zlno_t, zgno_t> map_t;
304 typedef Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t> matrix_t;
306 const zgno_t gNvtx = numLocalObj * comm->getSize();
307 const Teuchos::ArrayView<const zgno_t> indexList(myGids, numLocalObj);
308 Teuchos::RCP<const map_t> map = rcp(
new map_t(gNvtx, indexList, 0, comm));
311 size_t maxRowLen = 1;
312 Teuchos::RCP<matrix_t> matrix = rcp(
new matrix_t(map, maxRowLen));
325 Teuchos::Array<zgno_t> col(2);
326 Teuchos::Array<zscalar_t> val(2); val[0] = 1.; val[1] = 1.;
327 zgno_t first_id = map->getMinAllGlobalIndex();
328 zgno_t last_id = map->getMaxAllGlobalIndex();
329 for (
zlno_t i = 0; i < numLocalObj; i++) {
330 zgno_t id = map->getGlobalElement(i);
333 matrix->insertGlobalValues(
id, col(), val());
336 matrix->fillComplete(map, map);
338 size_t nVwgts =
weights.size();
342 for (
size_t j = 0; j < nVwgts; j++) {
351 int numLocalObj,
zgno_t *myGids,
352 std::vector<const zscalar_t *> &
weights,
353 std::vector<int> & strides) {
358 template<
class idInput_t>
359 void doTest(RCP<
const Comm<int> > comm,
int numLocalObj,
360 int nWeights,
int numLocalParts,
bool givePartSizes)
366 int rank = comm->getRank();
368 int original_numLocalParts = numLocalParts;
370 int nprocs = comm->getSize();
373 bool testEmptyParts = (numLocalParts < 1);
374 int numGlobalParts = 0;
377 numGlobalParts = nprocs / 2;
378 if (numGlobalParts >= 1)
379 numLocalParts = (rank < numGlobalParts ? 1 : 0);
382 testEmptyParts =
false;
386 numGlobalParts = nprocs * numLocalParts;
391 <<
"Test: number of weights " << nWeights
392 <<
", desired number of parts " << numGlobalParts
393 <<
", calculated num local parts " << numLocalParts
394 <<
", original num local parts " << original_numLocalParts
395 << (givePartSizes ?
", with differing part sizes." :
396 ", with uniform part sizes.")
397 <<
", Number of procs " << nprocs
398 <<
", each with " << numLocalObj <<
" objects, part = rank." << endl;
403 Teuchos::ParameterList pl(
"test list");
404 pl.set(
"num_local_parts", numLocalParts);
406 RCP<const Zoltan2::Environment> env =
412 for (
int i=0, x=rank*numLocalObj; i < numLocalObj; i++, x++){
419 int partSizeDim = (givePartSizes ? (nWeights ? nWeights : 1) : 0);
420 ArrayRCP<ArrayRCP<part_t> > ids(partSizeDim);
421 ArrayRCP<ArrayRCP<zscalar_t> > sizes(partSizeDim);
423 if (givePartSizes && numLocalParts > 0){
424 part_t *myParts =
new part_t [numLocalParts];
425 myParts[0] = rank * numLocalParts;
426 for (
int i=1; i < numLocalParts; i++)
427 myParts[i] = myParts[i-1] + 1;
428 ArrayRCP<part_t> partNums(myParts, 0, numLocalParts,
true);
431 if (sizeFactor < 0) sizeFactor *= -1;
434 for (
int dim=0; dim < partSizeDim; dim++){
436 for (
int i=0; i < numLocalParts; i++)
437 psizes[i] = sizeFactor;
438 sizes[dim] = arcp(psizes, 0, numLocalParts,
true);
445 std::vector<const zscalar_t *>
weights;
446 std::vector<int> strides;
448 int len = numLocalObj*nWeights;
449 ArrayRCP<zscalar_t> wgtBuf;
454 wgtBuf = arcp(wgts, 0, len,
true);
455 for (
int i=0; i < len; i++)
459 for (
int i=0; i < nWeights; i++, wgts+=numLocalObj)
460 weights.push_back(wgts);
465 ia = create_adapter<idInput_t>(comm, numLocalObj, myGids,
weights, strides);
467 catch (std::exception &e){
475 RCP<Zoltan2::PartitioningSolution<idInput_t> > solution;
481 ids.view(0,partSizeDim), sizes.view(0,partSizeDim)));
484 env, comm, nWeights));
486 catch (std::exception &e){
494 part_t *partNum =
new part_t [numLocalObj];
495 ArrayRCP<part_t> partAssignment(partNum, 0, numLocalObj,
true);
496 for (
int i=0; i < numLocalObj; i++)
499 solution->setParts(partAssignment);
503 RCP<quality_t> metricObject;
506 metricObject = rcp(
new quality_t(ia, &pl, comm, solution.getRawPtr()));
508 catch (std::exception &e){
515 metricObject->printMetrics(cout);
518 catch (std::exception &e){
524 evaluate_adapter_results<idInput_t>(comm, metricObject,
525 numLocalObj, nWeights, original_numLocalParts, givePartSizes);
idInput_t * create_adapter(RCP< const Comm< int > > comm, int numLocalObj, zgno_t *myGids, std::vector< const zscalar_t * > &weights, std::vector< int > &strides)
basic_idInput_t * create_adapter< basic_idInput_t >(RCP< const Comm< int > > comm, int numLocalObj, zgno_t *myGids, std::vector< const zscalar_t * > &weights, std::vector< int > &strides)
void evaluate_adapter_results(RCP< const Comm< int > > comm, RCP< Zoltan2::EvaluatePartition< idInput_t >> metricObject, int numLocalObj, int nWeights, int original_numLocalParts, bool givePartSizes)
graph_idInput_t * create_adapter< graph_idInput_t >(RCP< const Comm< int > > comm, int numLocalObj, zgno_t *myGids, std::vector< const zscalar_t * > &weights, std::vector< int > &strides)
void setWeights(const scalar_t *val, int stride, int idx)
Provide a pointer to weights for the primary entity type.
int main(int narg, char *arg[])
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
Provides access for Zoltan2 to Xpetra::CrsGraph data.
common code used by tests
Defines XpetraCrsGraphAdapter class.
SparseMatrixAdapter_t::part_t part_t
This class represents a collection of global Identifiers and their associated weights, if any.
A PartitioningSolution is a solution to a partitioning problem.
Tpetra::CrsGraph< zlno_t, zgno_t, znode_t > tcrsGraph_t
Defines the EvaluatePartition class.
void doTest(RCP< const Comm< int > > comm, int numLocalObj, int nWeights, int numLocalParts, bool givePartSizes)
Zoltan2::BasicIdentifierAdapter< user_t > basic_idInput_t
Zoltan2::XpetraCrsGraphAdapter< tcrsGraph_t, user_t > graph_idInput_t
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
static const std::string fail
InputTraits< User >::part_t part_t
Defines the BasicIdentifierAdapter class.
A class that computes and returns quality metrics.
void evaluate_adapter_results< graph_idInput_t >(RCP< const Comm< int > > comm, RCP< Zoltan2::EvaluatePartition< graph_idInput_t >> metricObject, int numLocalObj, int nWeights, int original_numLocalParts, bool givePartSizes)
void runTestSuite(RCP< const Comm< int > > comm)
void evaluate_imbalance_results(RCP< const Comm< int > > comm, RCP< Zoltan2::EvaluatePartition< idInput_t >> metricObject, int numLocalObj, int nWeights, int original_numLocalParts, bool givePartSizes)
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t
void evaluate_adapter_results< basic_idInput_t >(RCP< const Comm< int > > comm, RCP< Zoltan2::EvaluatePartition< basic_idInput_t >> metricObject, int numLocalObj, int nWeights, int original_numLocalParts, bool givePartSizes)