18 #include "Kokkos_UnorderedMap.hpp"
29 #include <Teuchos_ArrayView.hpp>
30 #include <Teuchos_Comm.hpp>
31 #include <Teuchos_DefaultComm.hpp>
32 #include <Teuchos_TestingHelpers.hpp>
34 using Teuchos::ArrayView;
38 using Teuchos::rcp_const_cast;
39 using Teuchos::rcp_dynamic_cast;
43 using tcrsMatrix_t = Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>;
44 using trowMatrix_t = Tpetra::RowMatrix<zscalar_t, zlno_t, zgno_t, znode_t>;
45 using tmap_t = Tpetra::Map<zlno_t, zgno_t, znode_t>;
53 int main(
int narg,
char *arg[]) {
54 Tpetra::ScopeGuard tscope(&narg, &arg);
55 Teuchos::RCP<const Teuchos::Comm<int>> comm = Tpetra::getDefaultComm();
57 int rank = comm->getRank();
61 std::string
fname(
"simple");
64 std::cout <<
"TESTING base case (global)" << std::endl;
72 RCP<trowMatrix_t> trM = rcp_dynamic_cast<
trowMatrix_t>(M);
73 RCP<const trowMatrix_t> ctrM = rcp_const_cast<
const trowMatrix_t>(trM);
74 zlno_t nLocalRows = M->getLocalNumRows();
75 std::cout <<
"nLocalRows: " << nLocalRows << std::endl;
85 auto wgts0Host = Kokkos::create_mirror_view(wgts0);
86 auto wgts1Host = Kokkos::create_mirror_view(wgts1);
88 for (
zlno_t i = 0; i < nLocalRows; i++) {
90 wgts1Host(i) = 200000 + i;
93 if (nVtxWeights > 0) {
94 rowWeights =
new zscalar_t *[nVtxWeights];
95 for (
int i = 0; i < nVtxWeights; i++) {
97 rowWeights[i] =
nullptr;
99 rowWeights[i] =
new zscalar_t[nLocalRows];
100 for (
zlno_t j = 0; j < nLocalRows; j++) {
101 rowWeights[i][j] = 200000 * i + j;
107 Kokkos::deep_copy(wgts0, wgts0Host);
108 Kokkos::deep_copy(wgts1, wgts1Host);
111 for (
int i = 0; i < nVtxWeights; i++) {
112 tmi.setWeights(rowWeights[i], 1, i);
114 tmi.setRowWeightsDevice(wgts0, 0);
115 tmi.setRowWeightsDevice(wgts1, 1);
125 for (
int i = 0; i < coordDim; i++) {
127 for (
zlno_t j = 0; j < nLocalRows; j++) {
128 coords[i][j] = 100000 * i + j;
135 gids =
new zgno_t[nLocalRows];
136 for (
zlno_t i = 0; i < nLocalRows; i++)
137 gids[i] = M->getRowMap()->getGlobalElement(i);
139 (coordDim > 1 ? coords[1] :
nullptr),
140 (coordDim > 2 ? coords[2] :
nullptr), 1, 1, 1);
141 tmi.setCoordinateInput(via);
154 tmi.getRowIDsView(rowIds);
155 tmi.getIDsKokkosView(kIds);
156 auto kIdsHost = Kokkos::create_mirror_view(kIds);
157 Kokkos::deep_copy(kIdsHost, kIds);
159 tmi.getRowIDsHostView(kHostIds);
160 tmi.getRowIDsDeviceView(kDeviceIds);
162 auto kDeviceIdsHost = Kokkos::create_mirror_view(kDeviceIds);
163 Kokkos::deep_copy(kDeviceIdsHost, kDeviceIds);
166 for (
size_t i = 0; i < tmi.getLocalNumIDs(); ++i) {
167 TEUCHOS_TEST_EQUALITY(ids[i], kIdsHost(i), std::cout, success);
168 TEUCHOS_TEST_EQUALITY(ids[i], rowIds[i], std::cout, success);
169 TEUCHOS_TEST_EQUALITY(kIdsHost(i), kHostIds(i), std::cout, success);
170 TEUCHOS_TEST_EQUALITY(kIdsHost(i), kDeviceIdsHost(i), std::cout, success);
176 ArrayRCP<const zoffset_t> offsets;
177 ArrayRCP<const zgno_t> colIds;
182 tmi.getCRSView(offsets, colIds);
183 tmi.getCRSHostView(kHostOffsets, kHostColIds);
184 tmi.getCRSDeviceView(kDeviceOffsets, kDeviceColIds);
186 auto kDeviceColIdsHost = Kokkos::create_mirror_view(kDeviceColIds);
187 Kokkos::deep_copy(kDeviceColIdsHost, kDeviceColIds);
189 auto kDeviceOffsetsHost = Kokkos::create_mirror_view(kDeviceOffsets);
190 Kokkos::deep_copy(kDeviceOffsetsHost, kDeviceOffsets);
192 for (
int i = 0; success && i < colIds.size(); i++) {
193 TEUCHOS_TEST_EQUALITY(colIds[i], kHostColIds(i), std::cout, success);
194 TEUCHOS_TEST_EQUALITY(colIds[i], kDeviceColIdsHost(i), std::cout, success);
199 for (
int i = 0; success && i < offsets.size(); i++) {
200 TEUCHOS_TEST_EQUALITY(offsets[i], kHostOffsets(i), std::cout, success);
201 TEUCHOS_TEST_EQUALITY(offsets[i], kDeviceOffsetsHost(i), std::cout,
205 "offsets != kHostOffsets != kDeviceOffsets", 1)
207 ArrayRCP<const zscalar_t> values;
211 tmi.getCRSView(offsets, colIds, values);
212 tmi.getCRSHostView(kHostOffsets, kHostColIds, kHostValues);
213 tmi.getCRSDeviceView(kDeviceOffsets, kDeviceColIds, kDeviceValues);
214 auto kDeviceValuesHost = Kokkos::create_mirror_view(kDeviceValues);
215 Kokkos::deep_copy(kDeviceValuesHost, kDeviceValues);
217 for (
int i = 0; success && i < colIds.size(); i++) {
218 TEUCHOS_TEST_EQUALITY(colIds[i], kHostColIds(i), std::cout, success);
219 TEUCHOS_TEST_EQUALITY(colIds[i], kDeviceColIdsHost(i), std::cout, success);
224 for (
int i = 0; success && i < offsets.size(); i++) {
225 TEUCHOS_TEST_EQUALITY(offsets[i], kHostOffsets(i), std::cout, success);
226 TEUCHOS_TEST_EQUALITY(offsets[i], kDeviceOffsetsHost(i), std::cout,
230 "offsets != kHostOffsets != kDeviceOffsets", 1)
232 for (
int i = 0; success && i < values.size(); i++) {
233 TEUCHOS_TEST_EQUALITY(values[i], kHostValues(i), std::cout, success);
234 TEUCHOS_TEST_EQUALITY(values[i], kDeviceValuesHost(i), std::cout, success);
247 tmi.getRowWeightsHostView(weightsHost0, 0);
248 tmi.getRowWeightsDeviceView(weightsDevice0, 0);
250 tmi.getRowWeightsHostView(weightsHost1, 1);
251 tmi.getRowWeightsDeviceView(weightsDevice1, 1);
253 auto hostWeightsDevice0 = Kokkos::create_mirror_view(weightsDevice0);
254 Kokkos::deep_copy(hostWeightsDevice0, weightsDevice0);
256 auto hostWeightsDevice1 = Kokkos::create_mirror_view(weightsDevice1);
257 Kokkos::deep_copy(hostWeightsDevice1, weightsDevice1);
259 for (
int w = 0; success && w < nVtxWeights; w++) {
262 Kokkos::View<zscalar_t *, typename znode_t::device_type> wkgts;
264 tmi.getRowWeightsView(wgts, stride, w);
268 for (
zlno_t i = 0; success && i < nLocalRows; ++i) {
269 TEUCHOS_TEST_EQUALITY(wgts[stride * i], weightsHost0(i), std::cout,
271 TEUCHOS_TEST_EQUALITY(wgts[stride * i], hostWeightsDevice0(i), std::cout,
275 for (
zlno_t i = 0; success && i < nLocalRows; ++i) {
276 TEUCHOS_TEST_EQUALITY(wgts[stride * i], weightsHost1(i), std::cout,
278 TEUCHOS_TEST_EQUALITY(wgts[stride * i], hostWeightsDevice1(i), std::cout,
302 if (nVtxWeights > 0) {
303 for (
int i = 0; i < nVtxWeights; i++) {
305 delete[] rowWeights[i];
313 for (
int i = 0; i < coordDim; i++) {
323 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(".")