53 #include "Kokkos_StaticCrsGraph.hpp"
54 #include "Kokkos_UnorderedMap.hpp"
65 #include <Teuchos_ArrayView.hpp>
66 #include <Teuchos_Comm.hpp>
67 #include <Teuchos_DefaultComm.hpp>
68 #include <Teuchos_TestingHelpers.hpp>
70 using Teuchos::ArrayView;
74 using Teuchos::rcp_const_cast;
75 using Teuchos::rcp_dynamic_cast;
79 using tcrsMatrix_t = Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>;
80 using trowMatrix_t = Tpetra::RowMatrix<zscalar_t, zlno_t, zgno_t, znode_t>;
81 using tmap_t = Tpetra::Map<zlno_t, zgno_t, znode_t>;
89 int main(
int narg,
char *arg[]) {
90 Tpetra::ScopeGuard tscope(&narg, &arg);
91 Teuchos::RCP<const Teuchos::Comm<int>> comm = Tpetra::getDefaultComm();
93 int rank = comm->getRank();
97 std::string
fname(
"simple");
100 std::cout <<
"TESTING base case (global)" << std::endl;
108 RCP<trowMatrix_t> trM = rcp_dynamic_cast<
trowMatrix_t>(M);
109 RCP<const trowMatrix_t> ctrM = rcp_const_cast<
const trowMatrix_t>(trM);
110 zlno_t nLocalRows = M->getLocalNumRows();
111 std::cout <<
"nLocalRows: " << nLocalRows << std::endl;
121 auto wgts0Host = Kokkos::create_mirror_view(wgts0);
122 auto wgts1Host = Kokkos::create_mirror_view(wgts1);
124 for (
zlno_t i = 0; i < nLocalRows; i++) {
126 wgts1Host(i) = 200000 + i;
129 if (nVtxWeights > 0) {
130 rowWeights =
new zscalar_t *[nVtxWeights];
131 for (
int i = 0; i < nVtxWeights; i++) {
132 if (nnzWgtIdx == i) {
133 rowWeights[i] =
nullptr;
135 rowWeights[i] =
new zscalar_t[nLocalRows];
136 for (
zlno_t j = 0; j < nLocalRows; j++) {
137 rowWeights[i][j] = 200000 * i + j;
143 Kokkos::deep_copy(wgts0, wgts0Host);
144 Kokkos::deep_copy(wgts1, wgts1Host);
147 for (
int i = 0; i < nVtxWeights; i++) {
148 tmi.setWeights(rowWeights[i], 1, i);
150 tmi.setRowWeightsDevice(wgts0, 0);
151 tmi.setRowWeightsDevice(wgts1, 1);
161 for (
int i = 0; i < coordDim; i++) {
163 for (
zlno_t j = 0; j < nLocalRows; j++) {
164 coords[i][j] = 100000 * i + j;
171 gids =
new zgno_t[nLocalRows];
172 for (
zlno_t i = 0; i < nLocalRows; i++)
173 gids[i] = M->getRowMap()->getGlobalElement(i);
175 (coordDim > 1 ? coords[1] :
nullptr),
176 (coordDim > 2 ? coords[2] :
nullptr), 1, 1, 1);
177 tmi.setCoordinateInput(via);
190 tmi.getRowIDsView(rowIds);
191 tmi.getIDsKokkosView(kIds);
192 auto kIdsHost = Kokkos::create_mirror_view(kIds);
193 Kokkos::deep_copy(kIdsHost, kIds);
195 tmi.getRowIDsHostView(kHostIds);
196 tmi.getRowIDsDeviceView(kDeviceIds);
198 auto kDeviceIdsHost = Kokkos::create_mirror_view(kDeviceIds);
199 Kokkos::deep_copy(kDeviceIdsHost, kDeviceIds);
202 for (
size_t i = 0; i < tmi.getLocalNumIDs(); ++i) {
203 TEUCHOS_TEST_EQUALITY(ids[i], kIdsHost(i), std::cout, success);
204 TEUCHOS_TEST_EQUALITY(ids[i], rowIds[i], std::cout, success);
205 TEUCHOS_TEST_EQUALITY(kIdsHost(i), kHostIds(i), std::cout, success);
206 TEUCHOS_TEST_EQUALITY(kIdsHost(i), kDeviceIdsHost(i), std::cout, success);
212 ArrayRCP<const zoffset_t> offsets;
213 ArrayRCP<const zgno_t> colIds;
218 tmi.getCRSView(offsets, colIds);
219 tmi.getCRSHostView(kHostOffsets, kHostColIds);
220 tmi.getCRSDeviceView(kDeviceOffsets, kDeviceColIds);
222 auto kDeviceColIdsHost = Kokkos::create_mirror_view(kDeviceColIds);
223 Kokkos::deep_copy(kDeviceColIdsHost, kDeviceColIds);
225 auto kDeviceOffsetsHost = Kokkos::create_mirror_view(kDeviceOffsets);
226 Kokkos::deep_copy(kDeviceOffsetsHost, kDeviceOffsets);
228 for (
int i = 0; success && i < colIds.size(); i++) {
229 TEUCHOS_TEST_EQUALITY(colIds[i], kHostColIds(i), std::cout, success);
230 TEUCHOS_TEST_EQUALITY(colIds[i], kDeviceColIdsHost(i), std::cout, success);
235 for (
int i = 0; success && i < offsets.size(); i++) {
236 TEUCHOS_TEST_EQUALITY(offsets[i], kHostOffsets(i), std::cout, success);
237 TEUCHOS_TEST_EQUALITY(offsets[i], kDeviceOffsetsHost(i), std::cout,
241 "offsets != kHostOffsets != kDeviceOffsets", 1)
243 ArrayRCP<const zscalar_t> values;
247 tmi.getCRSView(offsets, colIds, values);
248 tmi.getCRSHostView(kHostOffsets, kHostColIds, kHostValues);
249 tmi.getCRSDeviceView(kDeviceOffsets, kDeviceColIds, kDeviceValues);
250 auto kDeviceValuesHost = Kokkos::create_mirror_view(kDeviceValues);
251 Kokkos::deep_copy(kDeviceValuesHost, kDeviceValues);
253 for (
int i = 0; success && i < colIds.size(); i++) {
254 TEUCHOS_TEST_EQUALITY(colIds[i], kHostColIds(i), std::cout, success);
255 TEUCHOS_TEST_EQUALITY(colIds[i], kDeviceColIdsHost(i), std::cout, success);
260 for (
int i = 0; success && i < offsets.size(); i++) {
261 TEUCHOS_TEST_EQUALITY(offsets[i], kHostOffsets(i), std::cout, success);
262 TEUCHOS_TEST_EQUALITY(offsets[i], kDeviceOffsetsHost(i), std::cout,
266 "offsets != kHostOffsets != kDeviceOffsets", 1)
268 for (
int i = 0; success && i < values.size(); i++) {
269 TEUCHOS_TEST_EQUALITY(values[i], kHostValues(i), std::cout, success);
270 TEUCHOS_TEST_EQUALITY(values[i], kDeviceValuesHost(i), std::cout, success);
283 tmi.getRowWeightsHostView(weightsHost0, 0);
284 tmi.getRowWeightsDeviceView(weightsDevice0, 0);
286 tmi.getRowWeightsHostView(weightsHost1, 1);
287 tmi.getRowWeightsDeviceView(weightsDevice1, 1);
289 auto hostWeightsDevice0 = Kokkos::create_mirror_view(weightsDevice0);
290 Kokkos::deep_copy(hostWeightsDevice0, weightsDevice0);
292 auto hostWeightsDevice1 = Kokkos::create_mirror_view(weightsDevice1);
293 Kokkos::deep_copy(hostWeightsDevice1, weightsDevice1);
295 for (
int w = 0; success && w < nVtxWeights; w++) {
298 Kokkos::View<zscalar_t *, typename znode_t::device_type> wkgts;
300 tmi.getRowWeightsView(wgts, stride, w);
304 for (
zlno_t i = 0; success && i < nLocalRows; ++i) {
305 TEUCHOS_TEST_EQUALITY(wgts[stride * i], weightsHost0(i), std::cout,
307 TEUCHOS_TEST_EQUALITY(wgts[stride * i], hostWeightsDevice0(i), std::cout,
311 for (
zlno_t i = 0; success && i < nLocalRows; ++i) {
312 TEUCHOS_TEST_EQUALITY(wgts[stride * i], weightsHost1(i), std::cout,
314 TEUCHOS_TEST_EQUALITY(wgts[stride * i], hostWeightsDevice1(i), std::cout,
338 if (nVtxWeights > 0) {
339 for (
int i = 0; i < nVtxWeights; i++) {
341 delete[] rowWeights[i];
349 for (
int i = 0; i < coordDim; i++) {
359 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(".")