188 const char *fileprefixInp,
189 const Teuchos::Comm<int> &comm
195 int fail = 0, gfail=0;
197 std::string tmp(fileprefixInp);
198 tmp = tmp +
"_generated";
199 const char *fileprefixGen = tmp.c_str();
201 ia.generateFiles(fileprefixGen, comm);
204 if (comm.getRank() == 0) {
206 size_t nIDsGen, nIDsInp;
207 size_t nEdgesGen, nEdgesInp;
208 char codeGen[4], codeInp[4];
209 int nWgtsGen = 0, nWgtsInp = 0;
210 std::string lineGen, lineInp;
212 std::ifstream fpGen, fpInp;
213 std::string graphFilenameGen = fileprefixGen;
214 graphFilenameGen = graphFilenameGen +
".graph";
215 std::string graphFilenameInp = fileprefixInp;
216 graphFilenameInp = graphFilenameInp +
".graph";
219 fpGen.open(graphFilenameGen.c_str(), std::ios::in);
223 fpInp.open(graphFilenameInp.c_str(), std::ios::in);
227 if (nIDsGen != nIDsInp) {
228 std::cout <<
"GenerateFiles: nIDsGen " << nIDsGen
229 <<
" != nIDsInp " << nIDsInp << std::endl;
234 if (!
fail && nEdgesGen != 0) {
235 std::cout <<
"GenerateFiles: nEdgesGen " << nEdgesGen <<
" != 0"
241 if (!
fail && nWgtsGen) {
245 for (cntWgtLines = 0; cntWgtLines < nIDsGen &&
246 std::getline(fpGen, lineGen) &&
247 std::getline(fpInp, lineInp); cntWgtLines++) {
249 std::istringstream issGen(lineGen);
250 std::istringstream issInp(lineInp);
253 double wgtGen, wgtInp;
255 while (issGen >> wgtGen) {
259 if (wgtGen != wgtInp)
fail = 2224;
264 if (nw != nWgtsGen)
fail = 2225;
266 if (cntWgtLines != nIDsGen)
fail = 2226;
271 size_t cntWgtLines = 0;
272 for (cntWgtLines = 0; cntWgtLines < nIDsGen &&
273 std::getline(fpGen, lineGen); cntWgtLines++) {
274 std::istringstream issGen(lineGen);
277 while (issGen) { issGen >> wgtGen; nw++; }
278 if (nw != nWgtsGen)
fail = 2227;
280 if (cntWgtLines != nIDsGen)
fail = 2228;
289 std::string coordsFilenameGen = fileprefixGen;
290 coordsFilenameGen = coordsFilenameGen +
".coords";
291 std::string coordsFilenameInp = fileprefixInp;
292 coordsFilenameInp = coordsFilenameInp +
".coords";
294 fpGen.open(coordsFilenameGen.c_str(), std::ios::in);
295 fpInp.open(coordsFilenameInp.c_str(), std::ios::in);
298 for (cnt = 0; std::getline(fpGen,lineGen) &&
299 std::getline(fpInp,lineInp); cnt++) {
302 std::istringstream issGen(lineGen);
303 std::istringstream issInp(lineInp);
308 while (issGen && issInp) {
311 std::cout <<
"Coordinates " << xGen <<
" != " << xInp
320 if (issGen || issInp) {
321 std::cout <<
"Dimension of generated file != dimension of input file"
328 if (!
fail && cnt != nIDsGen) {
329 std::cout <<
"Number of coordinates read " << cnt
330 <<
" != number of IDs " << nIDsGen << std::endl;
347 Tpetra::ScopeGuard tscope(&narg, &arg);
348 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
350 int rank = comm->getRank();
351 int fail = 0, gfail=0;
355 std::string inputFilePrefix(
"simple");
356 Teuchos::CommandLineProcessor cmdp (
false,
false);
357 cmdp.setOption(
"file", &inputFilePrefix,
358 "chaco file (prefix) to be used in test");
359 cmdp.parse(narg, arg);
364 RCP<UserInputForTests> uinput;
365 Teuchos::ParameterList params;
366 params.set(
"input file", inputFilePrefix);
367 params.set(
"file type",
"Chaco");
372 catch(std::exception &e){
374 std::cout << e.what() << std::endl;
378 RCP<tvector_t> inputMVector;
379 RCP<tvector_t> migratedMVector;
383 inputMVector = uinput->getUICoordinates();
384 size_t vlen = inputMVector->getLocalLength();
387 std::vector<const zscalar_t *> IDWeights;
388 std::vector<int> IDWeightsStrides;
391 if (uinput->hasUIWeights()) {
393 auto uiweights = uinput->getUIWeights();
395 nWeights = uiweights->getNumVectors();
396 IDWeights.resize(nWeights);
397 IDWeightsStrides.resize(nWeights);
399 for (
int w = 0; w < nWeights; w++) {
400 IDWeights[w] = uiweights->getData(w).getRawPtr();
401 IDWeightsStrides[w] = 1;
411 typedef ia_t::part_t
part_t;
414 memset(p, 0,
sizeof(
part_t) * vlen);
415 ArrayRCP<part_t> solnParts(p, 0, vlen,
true);
417 soln_t solution(env, comm, nWeights);
418 solution.setParts(solnParts);
425 std::cout <<
"Constructed with Tpetra::MultiVector" << std::endl;
427 RCP<const tvector_t> ctV = rcp_const_cast<const tvector_t>(inputMVector);
428 RCP<Zoltan2::XpetraMultiVectorAdapter<tvector_t> > tVInput;
433 IDWeights, IDWeightsStrides));
435 catch (std::exception &e){
437 std::cout << e.what() << std::endl;
441 fail = verifyInputAdapter<tvector_t>(*tVInput, *inputMVector, nVec,
442 IDWeights, IDWeightsStrides);
450 tVInput->applyPartitioningSolution(*inputMVector, vMigrate, solution);
451 migratedMVector = rcp(vMigrate);
453 catch (std::exception &e){
460 RCP<const tvector_t> cnewV =
461 rcp_const_cast<const tvector_t>(migratedMVector);
462 RCP<Zoltan2::XpetraMultiVectorAdapter<tvector_t> > newInput;
467 catch (std::exception &e){
469 std::cout << e.what() << std::endl;
474 std::cout <<
"Constructed with ";
475 std::cout <<
"Tpetra::MultiVector migrated to proc 0" << std::endl;
479 fail = verifyInputAdapter<tvector_t>(*newInput, *migratedMVector, nVec);
493 std::cout <<
"Constructed with Xpetra::MultiVector" << std::endl;
497 RCP<const xvector_t> cxV = rcp_const_cast<const xvector_t>(xV);
498 RCP<Zoltan2::XpetraMultiVectorAdapter<xvector_t> > xVInput;
506 catch (std::exception &e){
508 std::cout << e.what() << std::endl;
512 fail = verifyInputAdapter<xvector_t>(*xVInput, *inputMVector, nVec,
513 IDWeights, IDWeightsStrides);
520 xVInput->applyPartitioningSolution(*xV, vMigrate, solution);
522 catch (std::exception &e){
529 RCP<const xvector_t> cnewV(vMigrate);
530 RCP<Zoltan2::XpetraMultiVectorAdapter<xvector_t> > newInput;
535 catch (std::exception &e){
537 std::cout << e.what() << std::endl;
542 std::cout <<
"Constructed with ";
543 std::cout <<
"Xpetra::MultiVector migrated to proc 0" << std::endl;
545 fail = verifyInputAdapter<xvector_t>(*newInput, *migratedMVector, nVec);
555#ifdef HAVE_EPETRA_DATA_TYPES
558 typedef Epetra_MultiVector evector_t;
561 std::cout <<
"Constructed with Epetra_MultiVector" << std::endl;
564 rcp(
new Epetra_MultiVector(uinput->getUIEpetraCrsGraph()->RowMap(),
566 for (
int v = 0; v < nVec; v++) {
567 auto inV = inputMVector->getData(v);
568 for (
int i = 0; i < eV->MyLength(); i++)
569 eV->ReplaceMyValue(i, v, inV[i]);
572 RCP<const evector_t> ceV = rcp_const_cast<const evector_t>(eV);
573 RCP<Zoltan2::XpetraMultiVectorAdapter<evector_t> > eVInput;
575 bool goodAdapter =
true;
579 IDWeights, IDWeightsStrides));
581 catch (std::exception &e){
582 if (std::is_same<znode_t, Xpetra::EpetraNode>::value) {
585 std::cout << e.what() << std::endl;
590 std::cout <<
"Node type is not supported by Xpetra's Epetra interface;"
591 <<
" Skipping this test." << std::endl;
592 std::cout <<
"FYI: Here's the exception message: " << std::endl
593 << e.what() << std::endl;
600 fail = verifyInputAdapter<evector_t>(*eVInput, *inputMVector, nVec,
601 IDWeights, IDWeightsStrides);
606 evector_t *vMigrate =NULL;
608 eVInput->applyPartitioningSolution(*eV, vMigrate, solution);
610 catch (std::exception &e){
617 RCP<const evector_t> cnewV(vMigrate,
true);
618 RCP<Zoltan2::XpetraMultiVectorAdapter<evector_t> > newInput;
623 catch (std::exception &e){
625 std::cout << e.what() << std::endl;
630 std::cout <<
"Constructed with ";
631 std::cout <<
"Epetra_MultiVector migrated to proc 0" << std::endl;
633 fail = verifyInputAdapter<evector_t>(*newInput, *migratedMVector,
650 std::cout <<
"PASS" << std::endl;