18 #include <Tpetra_Map.hpp>
24 template <
typename User>
39 : nids(nids_), gids(gids_), dim(dim_), coords(coords_), weights(weights_)
49 { wgt = weights; stride = 1; }
55 coo = &(coords[idx*nids]);
69 template <
typename User>
82 : nids(nids_), gids(gids_), dim(dim_), coords(coords_), weights(weights_)
92 { wgt = weights; stride = 1; }
114 template <
typename User>
129 : nids(nids_), dim(dim_)
133 typedef Kokkos::DualView<gno_t *, device_t> view_ids_t;
134 kokkos_gids = view_ids_t(
135 Kokkos::ViewAllocateWithoutInitializing(
"gids"), nids);
137 auto host_gids = kokkos_gids.h_view;
138 for(
size_t n = 0; n < nids; ++n) {
139 host_gids(n) = gids_[n];
142 kokkos_gids.template modify<typename view_ids_t::host_mirror_space>();
143 kokkos_gids.sync_host();
144 kokkos_gids.template sync<device_t>();
150 typedef Kokkos::DualView<scalar_t **, device_t> view_weights_t;
151 kokkos_weights = view_weights_t(
152 Kokkos::ViewAllocateWithoutInitializing(
"weights"), nids, 0);
153 auto host_kokkos_weights = kokkos_weights.h_view;
154 for(
size_t n = 0; n < nids; ++n) {
155 host_kokkos_weights(n,0) = weights_[n];
158 kokkos_weights.template modify<typename view_weights_t::host_mirror_space>();
159 kokkos_weights.sync_host();
160 kokkos_weights.template sync<device_t>();
165 typedef Kokkos::DualView<scalar_t **, Kokkos::LayoutLeft, device_t> kokkos_coords_t;
166 kokkos_coords = kokkos_coords_t(
167 Kokkos::ViewAllocateWithoutInitializing(
"coords"), nids, dim);
168 auto host_kokkos_coords = kokkos_coords.h_view;
170 for(
size_t n = 0; n < nids; ++n) {
171 for(
int idx = 0; idx < dim; ++idx) {
172 host_kokkos_coords(n,idx) = coords_[n+idx*nids];
176 kokkos_coords.template modify<typename kokkos_coords_t::host_mirror_space>();
177 kokkos_coords.sync_host();
178 kokkos_coords.template sync<device_t>();
185 auto kokkosIds = kokkos_gids.view_host();
186 ids = kokkosIds.data();
190 ids = kokkos_gids.template view<device_t>();
196 int idx = 0)
const override
198 auto h_wgts_2d = kokkos_weights.view_host();
200 wgt = Kokkos::subview(h_wgts_2d, Kokkos::ALL, idx).data();
205 wgt = kokkos_weights.template view<device_t>();
211 int &stride,
int idx = 0)
const override {
212 elements = kokkos_coords.view_host().data();
217 Kokkos::LayoutLeft,
device_t> & coo)
const {
218 coo = kokkos_coords.template view<device_t>();
223 Kokkos::DualView<gno_t *, device_t> kokkos_gids;
225 Kokkos::DualView<scalar_t **, Kokkos::LayoutLeft, device_t> kokkos_coords;
226 Kokkos::DualView<scalar_t **, device_t> kokkos_weights;
234 const Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
236 int rank = comm->getRank();
237 int nprocs = comm->getSize();
239 typedef Tpetra::Map<> Map_t;
240 typedef Map_t::local_ordinal_type localId_t;
241 typedef Map_t::global_ordinal_type globalId_t;
242 typedef double scalar_t;
253 size_t localCount = 40;
257 scalar_t *cStrided =
new scalar_t [dim * localCount];
259 for (
size_t i = 0; i < localCount; i++)
260 for (
int d = 0; d < dim; d++)
261 cStrided[cnt++] = d*1000 + rank*100 + i;
264 scalar_t *cContig =
new scalar_t [dim * localCount];
266 for (
int d = 0; d < dim; d++)
267 for (
size_t i = 0; i < localCount; i++)
268 cContig[cnt++] = d*1000 + rank*100 + i;
271 globalId_t *globalIds =
new globalId_t [localCount];
272 globalId_t offset = rank * localCount;
273 for (
size_t i=0; i < localCount; i++) globalIds[i] = offset++;
278 Teuchos::ParameterList params(
"test params");
279 params.set(
"debug_level",
"basic_status");
280 params.set(
"error_check_level",
"debug_mode_assertions");
282 params.set(
"algorithm", algorithm);
283 params.set(
"num_global_parts", nprocs+1);
289 stridedAdapter_t *ia1 =
290 new stridedAdapter_t(localCount,globalIds,dim,cStrided);
297 quality_t *metricObject1 =
new quality_t(ia1, ¶ms, comm,
305 std::cout <<
"no weights -- balance satisfied: " << imb << std::endl;
307 std::cout <<
"no weights -- balance failure: " << imb << std::endl;
310 std::cout << std::endl;
314 contigAdapter_t *ia2 =
new contigAdapter_t(localCount,globalIds,dim,cContig);
322 kokkosAdapter_t *ia3 =
new kokkosAdapter_t(localCount,globalIds,dim,cContig);
331 for (
size_t i = 0; i < localCount; i++) {
332 if((problem1->
getSolution().getPartListView()[i] !=
337 std::cout << rank <<
" Error: differing parts for index " << i
338 << problem1->
getSolution().getPartListView()[i] <<
" "
339 << problem2->
getSolution().getPartListView()[i] <<
" "
340 << problem3->
getSolution().getPartListView()[i] << std::endl;
345 if (ndiff > 0) nFail++;
346 else if (rank == 0) std::cout <<
"no weights -- comparisons OK " << std::endl;
348 delete metricObject1;
360 scalar_t *
weights =
new scalar_t [localCount];
361 for (
size_t i=0; i < localCount; i++) weights[i] = 1 + scalar_t(rank);
364 ia1 =
new stridedAdapter_t(localCount, globalIds, dim, cStrided, weights);
378 std::cout <<
"weighted -- balance satisfied " << imb << std::endl;
380 std::cout <<
"weighted -- balance failed " << imb << std::endl;
383 std::cout << std::endl;
387 ia2 =
new contigAdapter_t(localCount, globalIds, dim, cContig, weights);
395 for (
size_t i = 0; i < localCount; i++) {
396 if (problem1->
getSolution().getPartListView()[i] !=
398 std::cout << rank <<
" Error: differing parts for index " << i
399 << problem1->
getSolution().getPartListView()[i] <<
" "
400 << problem2->
getSolution().getPartListView()[i] << std::endl;
405 if (ndiff > 0) nFail++;
406 else if (rank == 0) std::cout <<
"weighted -- comparisons OK " << std::endl;
408 delete metricObject1;
415 if (weights)
delete []
weights;
416 if (cStrided)
delete [] cStrided;
417 if (cContig)
delete [] cContig;
418 if (globalIds)
delete [] globalIds;
423 Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, 1, &nFail, &gnFail);
428 int main(
int narg,
char *arg[])
430 Tpetra::ScopeGuard scope(&narg, &arg);
431 const Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
438 if (comm->getRank() == 0) {
439 if (err == 0) std::cout <<
"PASS" << std::endl;
440 else std::cout <<
"FAIL: " << err <<
" tests failed" << std::endl;
OldSchoolVectorAdapterStrided(const size_t nids_, const gno_t *gids_, const int dim_, const scalar_t *coords_, const scalar_t *weights_=NULL)
void printMetrics(std::ostream &os) const
Print all metrics.
size_t getLocalNumIDs() const
Returns the number of objects on this process.
Zoltan2::InputTraits< User >::gno_t gno_t
void getEntriesView(const scalar_t *&coo, int &stride, int idx=0) const
int getNumEntriesPerID() const
Return the number of vectors.
map_t::global_ordinal_type gno_t
Zoltan2::InputTraits< User >::scalar_t scalar_t
A simple class that can be the User template argument for an InputAdapter.
Defines the VectorAdapter interface.
void getWeightsView(const scalar_t *&wgt, int &stride, int idx=0) const override
Zoltan2::EvaluatePartition< matrixAdapter_t > quality_t
int main(int narg, char **arg)
Defines the PartitioningSolution class.
virtual void getWeightsKokkosView(Kokkos::View< scalar_t **, device_t > &wgt) const
int getNumWeightsPerID() const
Returns the number of weights per object. Number of weights per object should be zero or greater...
void getEntriesView(const scalar_t *&elements, int &stride, int idx=0) const override
Zoltan2::InputTraits< User >::node_t node_t
scalar_t getWeightImbalance(int weightIndex) const
Return the imbalance for the requested weight.
void getIDsView(const gno_t *&ids) const
void getWeightsView(const scalar_t *&wgt, int &stride, int idx=0) const
virtual void getEntriesKokkosView(Kokkos::View< scalar_t **, Kokkos::LayoutLeft, device_t > &coo) const
void getEntriesView(const scalar_t *&coo, int &stride, int idx=0) const
void getIDsView(const gno_t *&ids) const
virtual void getIDsKokkosView(Kokkos::View< const gno_t *, device_t > &ids) const
size_t getLocalNumIDs() const
Returns the number of objects on this process.
VectorAdapter defines the interface for vector input.
int run_test_strided_versus_contig(const std::string &algorithm)
int getNumEntriesPerID() const
Return the number of vectors.
Zoltan2::InputTraits< User >::gno_t gno_t
node_t::device_type device_t
const PartitioningSolution< Adapter > & getSolution()
Get the solution to the problem.
PartitioningProblem sets up partitioning problems for the user.
void getIDsView(const gno_t *&ids) const override
Tpetra::Map::node_type node_t
void getWeightsView(const scalar_t *&wgt, int &stride, int idx=0) const
Defines the PartitioningProblem class.
Zoltan2::InputTraits< User >::gno_t gno_t
A class that computes and returns quality metrics.
size_t getLocalNumIDs() const
Returns the number of objects on this process.
int getNumWeightsPerID() const
Returns the number of weights per object. Number of weights per object should be zero or greater...
void solve(bool updateInputData=true)
Direct the problem to create a solution.
node_t::device_type device_t
int getNumEntriesPerID() const
Return the number of vectors.
OldSchoolVectorAdapterContig(const size_t nids_, const gno_t *gids_, const int dim_, const scalar_t *coords_, const scalar_t *weights_=NULL)
scalar_t getObjectCountImbalance() const
Return the object count imbalance.
int getNumWeightsPerID() const
Returns the number of weights per object. Number of weights per object should be zero or greater...
Zoltan2::InputTraits< User >::scalar_t scalar_t
KokkosVectorAdapter(const size_t nids_, const gno_t *gids_, const int dim_, const scalar_t *coords_, const scalar_t *weights_=NULL)
Zoltan2::InputTraits< User >::scalar_t scalar_t