50 #include <Kokkos_Core.hpp>
51 #include <Teuchos_DefaultComm.hpp>
65 int main(
int narg,
char *arg[]) {
66 Tpetra::ScopeGuard tscope(&narg, &arg);
67 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
69 int rank = comm->getRank();
70 int nprocs = comm->getSize();
74 typedef Tpetra::Map<> Map_t;
75 typedef Map_t::local_ordinal_type localId_t;
76 typedef Map_t::global_ordinal_type globalId_t;
77 typedef Tpetra::Details::DefaultTypes::scalar_type scalar_t;
78 typedef Tpetra::Map<>::node_type
node_t;
83 int localCount = 40 * (rank + 1);
84 int totalCount = 20 * nprocs * (nprocs + 1);
85 int targetCount = totalCount / nprocs;
87 Kokkos::View<globalId_t*, typename node_t::device_type>
88 globalIds(Kokkos::ViewAllocateWithoutInitializing(
"globalIds"), localCount);
89 auto host_globalIds = Kokkos::create_mirror_view(globalIds);
92 for (
int i = 0, num = 40; i < nprocs ; i++, num += 40) {
93 std::cout <<
"Rank " << i <<
" generates " << num <<
" ids." << std::endl;
97 globalId_t offset = 0;
98 for (
int i = 1; i <= rank; i++) {
102 for (
int i = 0; i < localCount; i++) {
103 host_globalIds(i) = offset++;
105 Kokkos::deep_copy(globalIds, host_globalIds);
113 const int nWeights = 1;
114 Kokkos::View<scalar_t **, typename node_t::device_type>
115 weights(
"weights", localCount, nWeights);
116 auto host_weights = Kokkos::create_mirror_view(weights);
118 for (
int index = 0; index < localCount; index++) {
119 host_weights(index, 0) = 1;
122 Kokkos::deep_copy(weights, host_weights);
124 inputAdapter_t ia(globalIds, weights);
129 Teuchos::ParameterList params(
"test params");
130 params.set(
"debug_level",
"basic_status");
131 params.set(
"debug_procs",
"0");
132 params.set(
"error_check_level",
"debug_mode_assertions");
134 params.set(
"algorithm",
"block");
135 params.set(
"imbalance_tolerance", 1.1);
136 params.set(
"num_global_parts", nprocs);
153 Kokkos::View<const globalId_t *, typename node_t::device_type> ids;
154 ia.getIDsKokkosView(ids);
156 auto host_ids = Kokkos::create_mirror_view(ids);
157 Kokkos::deep_copy(host_ids, ids);
159 Kokkos::View<int*, Kokkos::HostSpace> partCounts(
"partCounts", nprocs);
161 Kokkos::View<int*, Kokkos::HostSpace>
162 globalPartCounts(
"globalPartCounts", nprocs);
164 for (
size_t i = 0; i < ia.getLocalNumIDs(); i++) {
165 int pp = problem->
getSolution().getPartListView()[i];
166 std::cout << rank <<
" LID " << i <<
" GID " << host_ids(i)
167 <<
" PART " << pp << std::endl;
171 Teuchos::reduceAll<int, int>(*comm, Teuchos::REDUCE_SUM, nprocs,
172 partCounts.data(), globalPartCounts.data());
176 for (
int i = 0; i < nprocs; i++) {
177 if (globalPartCounts(i) != targetCount) {
178 std::cout <<
"FAIL: part " << i <<
" has " << globalPartCounts(i)
179 <<
" != " << targetCount <<
"; " << ++ierr <<
" errors"
184 std::cout <<
"PASS" << std::endl;
A simple class that can be the User template argument for an InputAdapter.
int main(int narg, char **arg)
Defines the PartitioningSolution class.
This class represents a collection of global Identifiers and their associated weights, if any.
Defines the BasicKokkosIdentifierAdapter class.
const PartitioningSolution< Adapter > & getSolution()
Get the solution to the problem.
PartitioningProblem sets up partitioning problems for the user.
Defines the PartitioningProblem class.
void solve(bool updateInputData=true)
Direct the problem to create a solution.