Zoltan2
Loading...
Searching...
No Matches
BasicKokkosIdentifierInput.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
10//
11// Basic testing of Zoltan2::BasicKokkosIdentifierAdapter
12
13#include <Kokkos_Core.hpp>
14#include <Teuchos_DefaultComm.hpp>
15#include <Teuchos_RCP.hpp>
16#include <Teuchos_CommHelpers.hpp>
19
20int main(int narg, char *arg[]) {
21
22 Tpetra::ScopeGuard tscope(&narg, &arg);
23 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
24
26
27 int rank = comm->getRank();
28 int nprocs = comm->getSize();
29 int fail = 0, gfail = 0;
30
31 // Create global identifiers with weights
32 zlno_t numLocalIds = 10;
33 const int nWeights = 2;
34
35 Kokkos::View<zgno_t *, typename znode_t::device_type>
36 myIds(Kokkos::ViewAllocateWithoutInitializing("myIds"), numLocalIds);
37 zgno_t myFirstId = rank * numLocalIds * numLocalIds;
38 Kokkos::View<zscalar_t **, typename znode_t::device_type>
39 weights(Kokkos::ViewAllocateWithoutInitializing("weights"),
40 numLocalIds, nWeights);
41
42 Kokkos::parallel_for(
43 Kokkos::RangePolicy<typename znode_t::execution_space,
44 zlno_t> (0, numLocalIds), KOKKOS_LAMBDA (zlno_t i) {
45 myIds(i) = zgno_t(myFirstId + i);
46 weights(i, 0) = 1.0;
47 weights(i, 1) = (nprocs - rank) / (i + 1);
48 });
49
51
52 if (!fail && ia.getLocalNumIDs() != size_t(numLocalIds)) {
53 fail = 4;
54 }
55 if (!fail && ia.getNumWeightsPerID() != nWeights) {
56 fail = 5;
57 }
58
59 Kokkos::View<const zgno_t *, typename znode_t::device_type> globalIdsIn;
60 Kokkos::View<zscalar_t **, typename znode_t::device_type> weightsIn;
61
62 ia.getIDsKokkosView(globalIdsIn);
63
64 ia.getWeightsKokkosView(weightsIn);
65
66 auto host_globalIdsIn = Kokkos::create_mirror_view(globalIdsIn);
67 Kokkos::deep_copy(host_globalIdsIn, globalIdsIn);
68 auto host_weightsIn = Kokkos::create_mirror_view(weightsIn);
69 Kokkos::deep_copy(host_weightsIn, weightsIn);
70 auto host_weights = Kokkos::create_mirror_view(weights);
71 Kokkos::deep_copy(host_weights, weights);
72
73 auto host_w0 = Kokkos::subview(host_weightsIn, Kokkos::ALL, 0);
74 auto host_w1 = Kokkos::subview(host_weightsIn, Kokkos::ALL, 1);
75
76 for (zlno_t i = 0; !fail && i < numLocalIds; i++){
77 if (host_globalIdsIn(i) != zgno_t(myFirstId + i)) {
78 fail = 8;
79 }
80 if (!fail && host_w0(i) != 1.0) {
81 fail = 9;
82 }
83 if (!fail && host_w1(i) != host_weights(i, 1)) {
84 fail = 10;
85 }
86 }
87
88 gfail = globalFail(*comm, fail);
89 if (gfail) {
90 printFailureCode(*comm, fail); // will exit(1)
91 }
92 if (rank == 0) {
93 std::cout << "PASS" << std::endl;
94 }
95}
int globalFail(const Comm< int > &comm, int fail)
void printFailureCode(const Comm< int > &comm, int fail)
Defines the BasicKokkosIdentifierAdapter class.
common code used by tests
Tpetra::Map ::local_ordinal_type zlno_t
Tpetra::Map ::global_ordinal_type zgno_t
int main()
This class represents a collection of global Identifiers and their associated weights,...
A simple class that can be the User template argument for an InputAdapter.
static const std::string fail
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > userTypes_t
static ArrayRCP< ArrayRCP< zscalar_t > > weights