50 #include <Teuchos_RCP.hpp>
51 #include <Tpetra_CrsMatrix.hpp>
52 #include <MatrixMarket_Tpetra.hpp>
62 typedef Tpetra::Map<zlno_t, zgno_t>
zmap_t;
63 typedef Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t>
zmatrix_t;
64 typedef Tpetra::CrsGraph<zlno_t, zgno_t>
zgraph_t;
70 template <
typename CC_T>
82 if (cc.getNumComponents() != nccAnswer) {
83 std::cout << name <<
"Invalid number of components "
84 << cc.getNumComponents() <<
" should be " << nccAnswer
89 if (cc.getMaxComponentSize() != maxAnswer) {
90 std::cout << name <<
"Maximum component size "
91 << cc.getMaxComponentSize() <<
" should be " << maxAnswer
96 if (cc.getMinComponentSize() != minAnswer) {
97 std::cout << name <<
"Minimum component size "
98 << cc.getMinComponentSize() <<
" should be " << minAnswer
103 if (cc.getAvgComponentSize() != avgAnswer) {
104 std::cout << name <<
"Average component size "
105 << cc.getAvgComponentSize() <<
" should be " << avgAnswer
119 std::ostringstream namestream;
120 namestream << comm->getRank() <<
" every_third ";
121 std::string name = namestream.str();
126 const size_t gNvtx = 27;
128 Teuchos::RCP<const zmap_t> map = rcp(
new zmap_t(gNvtx, 0, comm));
129 size_t nVtx = map->getNodeNumElements();
132 size_t maxRowLen = 3;
133 Teuchos::RCP<zmatrix_t> matrix = rcp(
new zmatrix_t(map, maxRowLen));
135 Teuchos::Array<zgno_t> col(3);
136 Teuchos::Array<zscalar_t> val(3); val[0] = 1.; val[1] = 1.; val[2] = 1.;
138 for (
size_t i = 0; i < nVtx; i++) {
139 zgno_t id = map->getGlobalElement(i);
140 col[0] = (
id+3)%gNvtx;
141 col[1] = (
id+6)%gNvtx;
142 col[2] = (
id+9)%gNvtx;
143 matrix->insertGlobalValues(
id, col(), val());
146 matrix->fillComplete(map, map);
156 size_t nccAnswer = std::min<size_t>(3, nVtx);
157 size_t maxAnswer = nVtx/3 + ((nVtx%3)!=0);
158 size_t minAnswer = (nVtx ? std::max<size_t>(nVtx/3, 1) : 0);
159 double avgAnswer = (nVtx ? double(nVtx) / double(std::min<size_t>(nVtx,3))
162 ierr = checkResult<cc_t>(name, cc,
163 nccAnswer, maxAnswer, minAnswer, avgAnswer);
174 std::ostringstream namestream;
175 namestream << comm->getRank() <<
" dist_component ";
176 std::string name = namestream.str();
181 const size_t gNvtx = 25;
183 Teuchos::RCP<const zmap_t> map = rcp(
new zmap_t(gNvtx, 0, comm));
184 size_t nVtx = map->getNodeNumElements();
187 size_t maxRowLen = 3;
188 Teuchos::RCP<zmatrix_t> matrix = rcp(
new zmatrix_t(map, maxRowLen));
190 Teuchos::Array<zgno_t> col(3);
191 Teuchos::Array<zscalar_t> val(3); val[0] = 1.; val[1] = 1.; val[2] = 1.;
193 for (
size_t i = 0; i < nVtx; i++) {
194 zgno_t id = map->getGlobalElement(i);
195 col[0] = (
id+4)%gNvtx;
196 col[1] = (
id+1)%gNvtx;
197 col[2] = (
id+3)%gNvtx;
198 matrix->insertGlobalValues(
id, col(), val());
201 matrix->fillComplete(map, map);
212 size_t nccAnswer = size_t(nVtx > 0);
213 size_t maxAnswer = nVtx;
214 size_t minAnswer = nVtx;
215 double avgAnswer = nVtx;
217 ierr = checkResult<cc_t>(name, cc,
218 nccAnswer, maxAnswer, minAnswer, avgAnswer);
229 std::ostringstream namestream;
230 namestream << comm->getRank() <<
" one_proc ";
231 std::string name = namestream.str();
235 int me = comm->getRank();
236 int np = comm->getSize();
237 bool allOnThisProc = (me == np-1);
240 const size_t gNvtx = 25;
243 if (allOnThisProc) nVtx = gNvtx;
246 Teuchos::RCP<const zmap_t> map = rcp(
new zmap_t(gNvtx, nVtx, 0, comm));
249 size_t maxRowLen = 2;
250 Teuchos::RCP<zmatrix_t> matrix = rcp(
new zmatrix_t(map, maxRowLen));
252 Teuchos::Array<zgno_t> col(2);
253 Teuchos::Array<zscalar_t> val(2); val[0] = 1.; val[1] = 1.;
254 for (
size_t i = 0; i < nVtx; i++) {
255 zgno_t id = map->getGlobalElement(i);
257 col[1] = (
id+1)%gNvtx;
258 matrix->insertGlobalValues(
id, col(), val());
261 matrix->fillComplete(map, map);
273 size_t nccAnswer = 1;
274 size_t maxAnswer = gNvtx;
275 size_t minAnswer = gNvtx;
276 double avgAnswer = double(gNvtx);
278 ierr = checkResult<cc_t>(name, cc,
279 nccAnswer, maxAnswer, minAnswer, avgAnswer);
283 size_t nccAnswer = 0;
284 size_t maxAnswer = 0;
285 size_t minAnswer = 0;
286 double avgAnswer = 0.;
288 ierr = checkResult<cc_t>(name, cc,
289 nccAnswer, maxAnswer, minAnswer, avgAnswer);
302 std::ostringstream namestream;
303 namestream << comm->getRank() <<
" no_graph ";
304 std::string name = namestream.str();
309 const size_t gNvtx = 25;
311 Teuchos::RCP<const zmap_t> map = rcp(
new zmap_t(gNvtx, 0, comm));
312 size_t nVtx = map->getNodeNumElements();
315 size_t maxRowLen = 1;
316 Teuchos::RCP<zmatrix_t> matrix = rcp(
new zmatrix_t(map, maxRowLen));
317 matrix->fillComplete(map, map);
322 #ifdef HAVE_ZOLTAN2_MPI
326 if (comm->getRank() == 0) std::cout <<
" using MPI_Comm " << std::endl;
327 MPI_Comm useThisComm = Teuchos::getRawMpiComm(*comm);
329 const Teuchos::Comm<int> &useThisComm = *comm;
334 cc_t cc(ia, useThisComm);
338 size_t nccAnswer = nVtx;
339 size_t maxAnswer = size_t(nVtx > 0);
340 size_t minAnswer = size_t(nVtx > 0);
341 double avgAnswer = double(nVtx > 0);
343 ierr = checkResult<cc_t>(name, cc,
344 nccAnswer, maxAnswer, minAnswer, avgAnswer);
353 Tpetra::ScopeGuard tscope(&narg, &arg);
354 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
355 int me = comm->getRank();
358 if (me == 0) std::cout <<
"test_one_proc..." << std::endl;
360 if (me == 0) std::cout <<
"test_no_graph..." << std::endl;
362 if (me == 0) std::cout <<
"test_dist_component..." << std::endl;
364 if (me == 0) std::cout <<
"test_every_third..." << std::endl;
368 Teuchos::reduceAll<int, int>(*comm, Teuchos::REDUCE_MAX, 1,
369 &testReturn, >estReturn);
371 if (gtestReturn) std::cout <<
"FAIL" << std::endl;
372 else std::cout <<
"PASS" << std::endl;
Tpetra::CrsGraph< zlno_t, zgno_t > zgraph_t
Provides access for Zoltan2 to Xpetra::CrsMatrix data.
int test_dist_component(Teuchos::RCP< const Teuchos::Comm< int > > &comm)
int main(int narg, char *arg[])
Zoltan2::XpetraCrsMatrixAdapter< zmatrix_t > matrixAdapter_t
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)
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