15 #include <Teuchos_RCP.hpp>
16 #include <Tpetra_CrsMatrix.hpp>
17 #include <MatrixMarket_Tpetra.hpp>
27 typedef Tpetra::Map<zlno_t, zgno_t>
zmap_t;
28 typedef Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t>
zmatrix_t;
29 typedef Tpetra::CrsGraph<zlno_t, zgno_t>
zgraph_t;
35 template <
typename CC_T>
47 if (cc.getNumComponents() != nccAnswer) {
48 std::cout << name <<
"Invalid number of components "
49 << cc.getNumComponents() <<
" should be " << nccAnswer
54 if (cc.getMaxComponentSize() != maxAnswer) {
55 std::cout << name <<
"Maximum component size "
56 << cc.getMaxComponentSize() <<
" should be " << maxAnswer
61 if (cc.getMinComponentSize() != minAnswer) {
62 std::cout << name <<
"Minimum component size "
63 << cc.getMinComponentSize() <<
" should be " << minAnswer
68 if (cc.getAvgComponentSize() != avgAnswer) {
69 std::cout << name <<
"Average component size "
70 << cc.getAvgComponentSize() <<
" should be " << avgAnswer
84 std::ostringstream namestream;
85 namestream << comm->getRank() <<
" every_third ";
86 std::string name = namestream.str();
91 const size_t gNvtx = 27;
93 Teuchos::RCP<const zmap_t> map = rcp(
new zmap_t(gNvtx, 0, comm));
94 size_t nVtx = map->getLocalNumElements();
98 Teuchos::RCP<zmatrix_t> matrix = rcp(
new zmatrix_t(map, maxRowLen));
100 Teuchos::Array<zgno_t> col(3);
101 Teuchos::Array<zscalar_t> val(3); val[0] = 1.; val[1] = 1.; val[2] = 1.;
103 for (
size_t i = 0; i < nVtx; i++) {
104 zgno_t id = map->getGlobalElement(i);
105 col[0] = (
id+3)%gNvtx;
106 col[1] = (
id+6)%gNvtx;
107 col[2] = (
id+9)%gNvtx;
108 matrix->insertGlobalValues(
id, col(), val());
111 matrix->fillComplete(map, map);
121 size_t nccAnswer = std::min<size_t>(3, nVtx);
122 size_t maxAnswer = nVtx/3 + ((nVtx%3)!=0);
123 size_t minAnswer = (nVtx ? std::max<size_t>(nVtx/3, 1) : 0);
124 double avgAnswer = (nVtx ? double(nVtx) / double(std::min<size_t>(nVtx,3))
127 ierr = checkResult<cc_t>(name, cc,
128 nccAnswer, maxAnswer, minAnswer, avgAnswer);
139 std::ostringstream namestream;
140 namestream << comm->getRank() <<
" dist_component ";
141 std::string name = namestream.str();
146 const size_t gNvtx = 25;
148 Teuchos::RCP<const zmap_t> map = rcp(
new zmap_t(gNvtx, 0, comm));
149 size_t nVtx = map->getLocalNumElements();
152 size_t maxRowLen = 3;
153 Teuchos::RCP<zmatrix_t> matrix = rcp(
new zmatrix_t(map, maxRowLen));
155 Teuchos::Array<zgno_t> col(3);
156 Teuchos::Array<zscalar_t> val(3); val[0] = 1.; val[1] = 1.; val[2] = 1.;
158 for (
size_t i = 0; i < nVtx; i++) {
159 zgno_t id = map->getGlobalElement(i);
160 col[0] = (
id+4)%gNvtx;
161 col[1] = (
id+1)%gNvtx;
162 col[2] = (
id+3)%gNvtx;
163 matrix->insertGlobalValues(
id, col(), val());
166 matrix->fillComplete(map, map);
177 size_t nccAnswer = size_t(nVtx > 0);
178 size_t maxAnswer = nVtx;
179 size_t minAnswer = nVtx;
180 double avgAnswer = nVtx;
182 ierr = checkResult<cc_t>(name, cc,
183 nccAnswer, maxAnswer, minAnswer, avgAnswer);
194 std::ostringstream namestream;
195 namestream << comm->getRank() <<
" one_proc ";
196 std::string name = namestream.str();
200 int me = comm->getRank();
201 int np = comm->getSize();
202 bool allOnThisProc = (me == np-1);
205 const size_t gNvtx = 25;
208 if (allOnThisProc) nVtx = gNvtx;
211 Teuchos::RCP<const zmap_t> map = rcp(
new zmap_t(gNvtx, nVtx, 0, comm));
214 size_t maxRowLen = 2;
215 Teuchos::RCP<zmatrix_t> matrix = rcp(
new zmatrix_t(map, maxRowLen));
217 Teuchos::Array<zgno_t> col(2);
218 Teuchos::Array<zscalar_t> val(2); val[0] = 1.; val[1] = 1.;
219 for (
size_t i = 0; i < nVtx; i++) {
220 zgno_t id = map->getGlobalElement(i);
222 col[1] = (
id+1)%gNvtx;
223 matrix->insertGlobalValues(
id, col(), val());
226 matrix->fillComplete(map, map);
238 size_t nccAnswer = 1;
239 size_t maxAnswer = gNvtx;
240 size_t minAnswer = gNvtx;
241 double avgAnswer = double(gNvtx);
243 ierr = checkResult<cc_t>(name, cc,
244 nccAnswer, maxAnswer, minAnswer, avgAnswer);
248 size_t nccAnswer = 0;
249 size_t maxAnswer = 0;
250 size_t minAnswer = 0;
251 double avgAnswer = 0.;
253 ierr = checkResult<cc_t>(name, cc,
254 nccAnswer, maxAnswer, minAnswer, avgAnswer);
267 std::ostringstream namestream;
268 namestream << comm->getRank() <<
" no_graph ";
269 std::string name = namestream.str();
274 const size_t gNvtx = 25;
276 Teuchos::RCP<const zmap_t> map = rcp(
new zmap_t(gNvtx, 0, comm));
277 size_t nVtx = map->getLocalNumElements();
280 size_t maxRowLen = 1;
281 Teuchos::RCP<zmatrix_t> matrix = rcp(
new zmatrix_t(map, maxRowLen));
282 matrix->fillComplete(map, map);
287 #ifdef HAVE_ZOLTAN2_MPI
291 if (comm->getRank() == 0) std::cout <<
" using MPI_Comm " << std::endl;
292 MPI_Comm useThisComm = Teuchos::getRawMpiComm(*comm);
294 const Teuchos::Comm<int> &useThisComm = *comm;
299 cc_t cc(ia, useThisComm);
303 size_t nccAnswer = nVtx;
304 size_t maxAnswer = size_t(nVtx > 0);
305 size_t minAnswer = size_t(nVtx > 0);
306 double avgAnswer = double(nVtx > 0);
308 ierr = checkResult<cc_t>(name, cc,
309 nccAnswer, maxAnswer, minAnswer, avgAnswer);
318 Tpetra::ScopeGuard tscope(&narg, &arg);
319 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
320 int me = comm->getRank();
323 if (me == 0) std::cout <<
"test_one_proc..." << std::endl;
325 if (me == 0) std::cout <<
"test_no_graph..." << std::endl;
327 if (me == 0) std::cout <<
"test_dist_component..." << std::endl;
329 if (me == 0) std::cout <<
"test_every_third..." << std::endl;
333 Teuchos::reduceAll<int, int>(*comm, Teuchos::REDUCE_MAX, 1,
334 &testReturn, >estReturn);
336 if (gtestReturn) std::cout <<
"FAIL" << std::endl;
337 else std::cout <<
"PASS" << std::endl;
Tpetra::CrsGraph< zlno_t, zgno_t > zgraph_t
Provides access for Zoltan2 to Xpetra::CrsMatrix data.
Zoltan2::XpetraCrsMatrixAdapter< tMatrix_t, tMVector_t > matrixAdapter_t
int test_dist_component(Teuchos::RCP< const Teuchos::Comm< int > > &comm)
int checkResult(std::string &name, CC_T cc, size_t nccAnswer, size_t maxAnswer, size_t minAnswer, double avgAnswer)
Provides access for Zoltan2 to Xpetra::CrsGraph data.
Zoltan2::XpetraCrsGraphAdapter< zgraph_t > graphAdapter_t
int test_every_third(Teuchos::RCP< const Teuchos::Comm< int > > &comm)
int main(int narg, char **arg)
common code used by tests
int test_one_proc(Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Tpetra::CrsMatrix< zscalar_t, zlno_t, zgno_t > zmatrix_t
Defines XpetraCrsGraphAdapter class.
Defines the XpetraCrsMatrixAdapter class.
int test_no_graph(Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Identify and compute the number of connected components in a processor's input Note that this routine...
Tpetra::Map< zlno_t, zgno_t > zmap_t
Tpetra::Map::global_ordinal_type zgno_t