Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mj_epetra.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Zoltan2: A package of combinatorial algorithms for scientific computing
4 //
5 // Copyright 2012 NTESS and the Zoltan2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
15 #include <vector>
16 #include <numeric>
17 #include "Epetra_ConfigDefs.h"
18 #ifdef HAVE_MPI
19 #include <Epetra_MpiComm.h>
20 #else
21 #include <Epetra_SerialComm.h>
22 #endif
23 #include <Epetra_MultiVector.h>
27 #include <Zoltan2_InputTraits.hpp>
28 
29 int main(int narg, char *arg[])
30 {
31  Tpetra::ScopeGuard scope(&narg, &arg);
32  const Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
33 
34  typedef int gid_t;
35 
36  const int N = 100; // num coords
37  const int num_parts = 5;
38  const int dim = 3;
39 
40  int rank = comm->getRank();
41 
42  // params
43  Teuchos::ParameterList params("test params");
44  params.set("algorithm", "multijagged");
45  params.set("num_global_parts", num_parts);
46 
47  // create gids
48  std::vector<gid_t> global_ids(N);
49  std::iota(global_ids.begin(), global_ids.end(), rank * N);
50 
51 #ifdef HAVE_MPI
52  Epetra_MpiComm epetra_comm(MPI_COMM_WORLD);
53 #else
54  Epetra_SerialComm epetra_comm;
55 #endif
56 
57  Epetra_BlockMap map(-1, N, 1, 0, epetra_comm);
58 
59  typedef Epetra_MultiVector mv_t;
60  Teuchos::RCP<mv_t> mv = Teuchos::rcp(new mv_t(map, dim)); // all 0's
61 
62  std::vector<int> stride;
63  std::vector<const double *> weights;
64  Teuchos::RCP<const mv_t> cmv = Teuchos::rcp_const_cast<const mv_t>(mv);
65 
66  typedef Zoltan2::XpetraMultiVectorAdapter<mv_t> inputAdapter_t;
67 
68  Teuchos::RCP<inputAdapter_t> ia =
69  Teuchos::rcp(new inputAdapter_t(cmv, weights, stride));
70 
71  Teuchos::RCP<Zoltan2::PartitioningProblem<inputAdapter_t>> problem =
72  Teuchos::rcp(new Zoltan2::PartitioningProblem<inputAdapter_t>(ia.get(), &params));
73 
74  problem->solve();
75 
77  Teuchos::RCP<quality_t> metricObject = Teuchos::rcp(new quality_t(
78  ia.get(), &params, comm, &problem->getSolution()));
79 
80  int err = 0;
81  if (comm->getRank() == 0) {
82  metricObject->printMetrics(std::cout);
83  double imb = metricObject->getObjectCountImbalance();
84  if (imb <= 1.01)
85  std::cout << "balance satisfied " << imb << std::endl;
86  else {
87  std::cout << "balance failed " << imb << std::endl;
88  err++;
89  }
90  }
91 
92  if(rank == 0 && err == 0) {
93  std::cout << "PASS" << std::endl;
94  }
95 
96  return 0;
97 }
98 
static ArrayRCP< ArrayRCP< zscalar_t > > weights
Zoltan2::EvaluatePartition< matrixAdapter_t > quality_t
int main(int narg, char **arg)
Definition: coloring1.cpp:164
Defines the PartitioningSolution class.
Defines the XpetraMultiVectorAdapter.
Traits for application input objects.
An adapter for Xpetra::MultiVector.
PartitioningProblem sets up partitioning problems for the user.
Defines the PartitioningProblem class.
A class that computes and returns quality metrics.