26 int me = comm->getRank();
27 int np = comm->getSize();
30 bool distributeInput =
true;
31 std::string filename =
"";
32 size_t xdim = 10, ydim = 11, zdim = 12;
34 Teuchos::CommandLineProcessor cmdp(
false,
false);
35 cmdp.setOption(
"file", &filename,
36 "Name of the Matrix Market file to use");
37 cmdp.setOption(
"xdim", &xdim,
38 "Number of nodes in x-direction for generated matrix");
39 cmdp.setOption(
"ydim", &ydim,
40 "Number of nodes in y-direction for generated matrix");
41 cmdp.setOption(
"zdim", &zdim,
42 "Number of nodes in z-direction for generated matrix");
43 cmdp.setOption(
"distribute",
"no-distribute", &distributeInput,
44 "Should Zoltan2 distribute the matrix as it is read?");
45 cmdp.setOption(
"symmetric",
"non-symmetric", &symmetric,
46 "Is the matrix symmetric?");
47 cmdp.parse(narg, arg);
53 JBlock = uinput.getUITpetraCrsMatrix();
58 true, distributeInput);
59 JBlock = uinput.getUITpetraCrsMatrix();
66 size_t nIndices = std::max(JBlock->getGlobalNumCols(),
67 JBlock->getGlobalNumRows());
68 Teuchos::Array<gno_t> indices(nIndices);
70 Teuchos::RCP<const map_t> vMapCyclic =
71 getCyclicMap(JBlock->getGlobalNumCols(), indices, np-1, comm);
72 Teuchos::RCP<const map_t> wMapCyclic =
73 getCyclicMap(JBlock->getGlobalNumRows(), indices, np-2, comm);
78 using IST =
typename Kokkos::Details::ArithTraits<zscalar_t>::val_type;
80 Kokkos::Random_XorShift64_Pool<execution_space_t>;
81 pool_type rand_pool(
static_cast<uint64_t
>(me));
83 Kokkos::fill_random(JBlock->getLocalMatrixDevice().values, rand_pool,
84 static_cast<IST
>(1.),
static_cast<IST
>(9999.));
85 JBlock->fillComplete();
89 RCP<const graph_t> block_graph = JBlock->getCrsGraph();
90 RCP<graph_t> cyclic_graph = rcp(
new graph_t(*block_graph));
91 cyclic_graph->resumeFill();
92 cyclic_graph->fillComplete(vMapCyclic, wMapCyclic);
93 JCyclic = rcp(
new matrix_t(cyclic_graph));
94 JCyclic->resumeFill();
95 TEUCHOS_ASSERT(block_graph->getLocalNumRows() == cyclic_graph->getLocalNumRows());
97 auto val_s = JBlock->getLocalMatrixHost().values;
98 auto val_d = JCyclic->getLocalMatrixHost().values;
99 TEUCHOS_ASSERT(val_s.extent(0) == val_d.extent(0));
100 Kokkos::deep_copy(val_d, val_s);
102 JCyclic->fillComplete();
123 const char *testname,
124 Teuchos::ParameterList ¶ms,
131 Teuchos::RCP<matrix_t> J = (useBlock ? JBlock : JCyclic);
132 int me = J->getRowMap()->getComm()->getRank();
134 std::cout <<
"Running " << testname <<
" with "
135 << (useBlock ?
"Block maps" :
"Cyclic maps")
140 colorer.computeColoring(params);
143 if (!colorer.checkColoring()) {
144 std::cout << testname <<
" with "
145 << (useBlock ?
"Block maps" :
"Cyclic maps")
146 <<
" FAILED: invalid coloring returned"
154 const int numColors = colorer.getNumColors();
159 colorer.computeSeedMatrix(V);
168 Teuchos::RCP<matrix_t> Jp = rcp(
new matrix_t(*J, Teuchos::Copy));
169 Jp->setAllToScalar(
static_cast<zscalar_t>(-1.));
171 colorer.reconstructMatrix(W, *Jp);
174 auto J_local_matrix = J->getLocalMatrixDevice();
175 auto Jp_local_matrix = Jp->getLocalMatrixDevice();
176 const size_t num_local_nz = J->getLocalNumEntries();
178 Kokkos::parallel_reduce(
179 "TpetraCrsColorer::testReconstructedMatrix()",
180 Kokkos::RangePolicy<execution_space_t>(0, num_local_nz),
181 KOKKOS_LAMBDA(
const size_t nz,
int &errorcnt) {
182 if (J_local_matrix.values(nz) != Jp_local_matrix.values(nz)) {
183 printf(
"Error in nonzero comparison %zu: %g != %g",
184 nz, J_local_matrix.values(nz), Jp_local_matrix.values(nz));
192 std::cout << testname <<
" FAILED on rank " << me <<
" with "
193 << (useBlock ?
"Block maps" :
"Cyclic maps")
223 return rcp(
new map_t(dummy, indices(0,cnt), 0, comm));
237 Tpetra::ScopeGuard scope(&narg, &arg);
238 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
246 Teuchos::ParameterList coloring_params;
247 std::string matrixType =
"Jacobian";
248 bool symmetrize =
true;
250 coloring_params.set(
"MatrixType", matrixType);
251 coloring_params.set(
"symmetrize", symmetrize);
253 ok = testColorer.run(
"Test One", coloring_params);
258 Teuchos::ParameterList coloring_params;
259 std::string matrixType =
"Jacobian";
260 bool symmetrize =
false;
262 coloring_params.set(
"MatrixType", matrixType);
263 coloring_params.set(
"symmetrize", symmetrize);
265 ok = testColorer.run(
"Test Two", coloring_params);
270 Teuchos::ParameterList coloring_params;
271 std::string matrixType =
"Jacobian";
273 coloring_params.set(
"MatrixType", matrixType);
275 ok = testColorer.run(
"Test Three", coloring_params);
280 Teuchos::reduceAll<int, int>(*comm, Teuchos::REDUCE_SUM, 1, &ierr, &gerr);
281 if (comm->getRank() == 0) {
283 std::cout <<
"TEST PASSED" << std::endl;
285 std::cout <<
"TEST FAILED" << std::endl;