18 #include "Kokkos_StaticCrsGraph.hpp"
19 #include "Kokkos_UnorderedMap.hpp"
30 #include <Teuchos_ArrayView.hpp>
31 #include <Teuchos_Comm.hpp>
32 #include <Teuchos_DefaultComm.hpp>
33 #include <Teuchos_TestingHelpers.hpp>
35 using Teuchos::ArrayView;
39 using Teuchos::rcp_const_cast;
40 using Teuchos::rcp_dynamic_cast;
44 using tcrsMatrix_t = Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>;
45 using trowMatrix_t = Tpetra::RowMatrix<zscalar_t, zlno_t, zgno_t, znode_t>;
46 using tmap_t = Tpetra::Map<zlno_t, zgno_t, znode_t>;
54 int main(
int narg,
char *arg[]) {
55 Tpetra::ScopeGuard tscope(&narg, &arg);
56 Teuchos::RCP<const Teuchos::Comm<int>> comm = Tpetra::getDefaultComm();
58 int rank = comm->getRank();
62 std::string
fname(
"simple");
65 std::cout <<
"TESTING base case (global)" << std::endl;
73 RCP<trowMatrix_t> trM = rcp_dynamic_cast<
trowMatrix_t>(M);
74 RCP<const trowMatrix_t> ctrM = rcp_const_cast<
const trowMatrix_t>(trM);
75 zlno_t nLocalRows = M->getLocalNumRows();
76 std::cout <<
"nLocalRows: " << nLocalRows << std::endl;
86 auto wgts0Host = Kokkos::create_mirror_view(wgts0);
87 auto wgts1Host = Kokkos::create_mirror_view(wgts1);
89 for (
zlno_t i = 0; i < nLocalRows; i++) {
91 wgts1Host(i) = 200000 + i;
94 if (nVtxWeights > 0) {
95 rowWeights =
new zscalar_t *[nVtxWeights];
96 for (
int i = 0; i < nVtxWeights; i++) {
98 rowWeights[i] =
nullptr;
100 rowWeights[i] =
new zscalar_t[nLocalRows];
101 for (
zlno_t j = 0; j < nLocalRows; j++) {
102 rowWeights[i][j] = 200000 * i + j;
108 Kokkos::deep_copy(wgts0, wgts0Host);
109 Kokkos::deep_copy(wgts1, wgts1Host);
112 for (
int i = 0; i < nVtxWeights; i++) {
113 tmi.setWeights(rowWeights[i], 1, i);
115 tmi.setRowWeightsDevice(wgts0, 0);
116 tmi.setRowWeightsDevice(wgts1, 1);
126 for (
int i = 0; i < coordDim; i++) {
128 for (
zlno_t j = 0; j < nLocalRows; j++) {
129 coords[i][j] = 100000 * i + j;
136 gids =
new zgno_t[nLocalRows];
137 for (
zlno_t i = 0; i < nLocalRows; i++)
138 gids[i] = M->getRowMap()->getGlobalElement(i);
140 (coordDim > 1 ? coords[1] :
nullptr),
141 (coordDim > 2 ? coords[2] :
nullptr), 1, 1, 1);
142 tmi.setCoordinateInput(via);
155 tmi.getRowIDsView(rowIds);
156 tmi.getIDsKokkosView(kIds);
157 auto kIdsHost = Kokkos::create_mirror_view(kIds);
158 Kokkos::deep_copy(kIdsHost, kIds);
160 tmi.getRowIDsHostView(kHostIds);
161 tmi.getRowIDsDeviceView(kDeviceIds);
163 auto kDeviceIdsHost = Kokkos::create_mirror_view(kDeviceIds);
164 Kokkos::deep_copy(kDeviceIdsHost, kDeviceIds);
167 for (
size_t i = 0; i < tmi.getLocalNumIDs(); ++i) {
168 TEUCHOS_TEST_EQUALITY(ids[i], kIdsHost(i), std::cout, success);
169 TEUCHOS_TEST_EQUALITY(ids[i], rowIds[i], std::cout, success);
170 TEUCHOS_TEST_EQUALITY(kIdsHost(i), kHostIds(i), std::cout, success);
171 TEUCHOS_TEST_EQUALITY(kIdsHost(i), kDeviceIdsHost(i), std::cout, success);
177 ArrayRCP<const zoffset_t> offsets;
178 ArrayRCP<const zgno_t> colIds;
183 tmi.getCRSView(offsets, colIds);
184 tmi.getCRSHostView(kHostOffsets, kHostColIds);
185 tmi.getCRSDeviceView(kDeviceOffsets, kDeviceColIds);
187 auto kDeviceColIdsHost = Kokkos::create_mirror_view(kDeviceColIds);
188 Kokkos::deep_copy(kDeviceColIdsHost, kDeviceColIds);
190 auto kDeviceOffsetsHost = Kokkos::create_mirror_view(kDeviceOffsets);
191 Kokkos::deep_copy(kDeviceOffsetsHost, kDeviceOffsets);
193 for (
int i = 0; success && i < colIds.size(); i++) {
194 TEUCHOS_TEST_EQUALITY(colIds[i], kHostColIds(i), std::cout, success);
195 TEUCHOS_TEST_EQUALITY(colIds[i], kDeviceColIdsHost(i), std::cout, success);
200 for (
int i = 0; success && i < offsets.size(); i++) {
201 TEUCHOS_TEST_EQUALITY(offsets[i], kHostOffsets(i), std::cout, success);
202 TEUCHOS_TEST_EQUALITY(offsets[i], kDeviceOffsetsHost(i), std::cout,
206 "offsets != kHostOffsets != kDeviceOffsets", 1)
208 ArrayRCP<const zscalar_t> values;
212 tmi.getCRSView(offsets, colIds, values);
213 tmi.getCRSHostView(kHostOffsets, kHostColIds, kHostValues);
214 tmi.getCRSDeviceView(kDeviceOffsets, kDeviceColIds, kDeviceValues);
215 auto kDeviceValuesHost = Kokkos::create_mirror_view(kDeviceValues);
216 Kokkos::deep_copy(kDeviceValuesHost, kDeviceValues);
218 for (
int i = 0; success && i < colIds.size(); i++) {
219 TEUCHOS_TEST_EQUALITY(colIds[i], kHostColIds(i), std::cout, success);
220 TEUCHOS_TEST_EQUALITY(colIds[i], kDeviceColIdsHost(i), std::cout, success);
225 for (
int i = 0; success && i < offsets.size(); i++) {
226 TEUCHOS_TEST_EQUALITY(offsets[i], kHostOffsets(i), std::cout, success);
227 TEUCHOS_TEST_EQUALITY(offsets[i], kDeviceOffsetsHost(i), std::cout,
231 "offsets != kHostOffsets != kDeviceOffsets", 1)
233 for (
int i = 0; success && i < values.size(); i++) {
234 TEUCHOS_TEST_EQUALITY(values[i], kHostValues(i), std::cout, success);
235 TEUCHOS_TEST_EQUALITY(values[i], kDeviceValuesHost(i), std::cout, success);
248 tmi.getRowWeightsHostView(weightsHost0, 0);
249 tmi.getRowWeightsDeviceView(weightsDevice0, 0);
251 tmi.getRowWeightsHostView(weightsHost1, 1);
252 tmi.getRowWeightsDeviceView(weightsDevice1, 1);
254 auto hostWeightsDevice0 = Kokkos::create_mirror_view(weightsDevice0);
255 Kokkos::deep_copy(hostWeightsDevice0, weightsDevice0);
257 auto hostWeightsDevice1 = Kokkos::create_mirror_view(weightsDevice1);
258 Kokkos::deep_copy(hostWeightsDevice1, weightsDevice1);
260 for (
int w = 0; success && w < nVtxWeights; w++) {
263 Kokkos::View<zscalar_t *, typename znode_t::device_type> wkgts;
265 tmi.getRowWeightsView(wgts, stride, w);
269 for (
zlno_t i = 0; success && i < nLocalRows; ++i) {
270 TEUCHOS_TEST_EQUALITY(wgts[stride * i], weightsHost0(i), std::cout,
272 TEUCHOS_TEST_EQUALITY(wgts[stride * i], hostWeightsDevice0(i), std::cout,
276 for (
zlno_t i = 0; success && i < nLocalRows; ++i) {
277 TEUCHOS_TEST_EQUALITY(wgts[stride * i], weightsHost1(i), std::cout,
279 TEUCHOS_TEST_EQUALITY(wgts[stride * i], hostWeightsDevice1(i), std::cout,
303 if (nVtxWeights > 0) {
304 for (
int i = 0; i < nVtxWeights; i++) {
306 delete[] rowWeights[i];
314 for (
int i = 0; i < coordDim; i++) {
324 std::cout <<
"PASS" << std::endl;
typename baseMAdapter_t::offset_t zoffset_t
typename Zoltan2::TpetraRowMatrixAdapter< trowMatrix_t, simpleUser_t > tRowMAdapter_t
MatrixAdapter defines the adapter interface for matrices.
Kokkos::View< scalar_t *, device_t > WeightsDeviceView1D
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
int main(int narg, char **arg)
common code used by tests
Kokkos::View< const gno_t *, device_t > ConstIdsDeviceView
typename ConstScalarsDeviceView::HostMirror ConstScalarsHostView
Provides access for Zoltan2 to Tpetra::RowMatrix data.
Defines the XpetraCrsMatrixAdapter class.
Kokkos::View< const scalar_t *, device_t > ConstScalarsDeviceView
Zoltan2::BasicVectorAdapter< simpleUser_t > simpleVAdapter_t
typename ConstOffsetsDeviceView::HostMirror ConstOffsetsHostView
typename ConstIdsDeviceView::HostMirror ConstIdsHostView
BasicVectorAdapter represents a vector (plus optional weights) supplied by the user as pointers to st...
Defines the TpetraRowMatrixAdapter class.
Tpetra::Map::local_ordinal_type zlno_t
Tpetra::CrsMatrix< zscalar_t, zlno_t, zgno_t, znode_t > tcrsMatrix_t
Tpetra::Map< zlno_t, zgno_t, znode_t > tmap_t
typename InputTraits< User >::offset_t offset_t
typename WeightsDeviceView1D::HostMirror WeightsHostView1D
Defines the BasicVectorAdapter class.
Kokkos::View< const offset_t *, device_t > ConstOffsetsDeviceView
Tpetra::Map::global_ordinal_type zgno_t
Tpetra::RowMatrix< zscalar_t, zlno_t, zgno_t, znode_t > trowMatrix_t
std::string testDataFilePath(".")