153 const char *fileprefixInp,
154 const Teuchos::Comm<int> &comm
160 int fail = 0, gfail=0;
162 std::string tmp(fileprefixInp);
163 tmp = tmp +
"_generated";
164 const char *fileprefixGen = tmp.c_str();
169 if (comm.getRank() == 0) {
171 size_t nIDsGen, nIDsInp;
172 size_t nEdgesGen, nEdgesInp;
173 int nWgtsGen = 0, nWgtsInp = 0;
174 std::string lineGen, lineInp;
176 std::ifstream fpGen, fpInp;
177 std::string graphFilenameGen = fileprefixGen;
178 graphFilenameGen = graphFilenameGen +
".graph";
179 std::string graphFilenameInp = fileprefixInp;
180 graphFilenameInp = graphFilenameInp +
".graph";
183 fpGen.open(graphFilenameGen.c_str(), std::ios::in);
187 fpInp.open(graphFilenameInp.c_str(), std::ios::in);
191 if (nIDsGen != nIDsInp) {
192 std::cout <<
"GenerateFiles: nIDsGen " << nIDsGen
193 <<
" != nIDsInp " << nIDsInp << std::endl;
198 if (!
fail && nEdgesGen != 0) {
199 std::cout <<
"GenerateFiles: nEdgesGen " << nEdgesGen <<
" != 0"
205 if (!
fail && nWgtsGen) {
209 for (cntWgtLines = 0; cntWgtLines < nIDsGen &&
210 std::getline(fpGen, lineGen) &&
211 std::getline(fpInp, lineInp); cntWgtLines++) {
213 std::istringstream issGen(lineGen);
214 std::istringstream issInp(lineInp);
217 double wgtGen, wgtInp;
219 while (issGen >> wgtGen) {
223 if (wgtGen != wgtInp)
fail = 2224;
228 if (nw != nWgtsGen)
fail = 2225;
230 if (cntWgtLines != nIDsGen)
fail = 2226;
235 size_t cntWgtLines = 0;
236 for (cntWgtLines = 0; cntWgtLines < nIDsGen &&
237 std::getline(fpGen, lineGen); cntWgtLines++) {
238 std::istringstream issGen(lineGen);
241 while (issGen) { issGen >> wgtGen; nw++; }
242 if (nw != nWgtsGen)
fail = 2227;
244 if (cntWgtLines != nIDsGen)
fail = 2228;
253 std::string coordsFilenameGen = fileprefixGen;
254 coordsFilenameGen = coordsFilenameGen +
".coords";
255 std::string coordsFilenameInp = fileprefixInp;
256 coordsFilenameInp = coordsFilenameInp +
".coords";
258 fpGen.open(coordsFilenameGen.c_str(), std::ios::in);
259 fpInp.open(coordsFilenameInp.c_str(), std::ios::in);
262 for (cnt = 0; std::getline(fpGen,lineGen) &&
263 std::getline(fpInp,lineInp); cnt++) {
266 std::istringstream issGen(lineGen);
267 std::istringstream issInp(lineInp);
272 while (issGen && issInp) {
275 std::cout <<
"Coordinates " << xGen <<
" != " << xInp
284 if (issGen || issInp) {
285 std::cout <<
"Dimension of generated file != dimension of input file"
292 if (!
fail && cnt != nIDsGen) {
293 std::cout <<
"Number of coordinates read " << cnt
294 <<
" != number of IDs " << nIDsGen << std::endl;
311 Tpetra::ScopeGuard tscope(&narg, &arg);
312 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
314 int rank = comm->getRank();
315 int fail = 0, gfail=0;
319 std::string inputFilePrefix(
"simple");
320 Teuchos::CommandLineProcessor cmdp (
false,
false);
321 cmdp.setOption(
"file", &inputFilePrefix,
322 "chaco file (prefix) to be used in test");
323 cmdp.parse(narg, arg);
328 RCP<UserInputForTests> uinput;
329 Teuchos::ParameterList params;
330 params.set(
"input file", inputFilePrefix);
331 params.set(
"file type",
"Chaco");
336 catch(std::exception &e){
338 std::cout << e.what() << std::endl;
342 RCP<tvector_t> inputMVector;
343 RCP<tvector_t> migratedMVector;
347 inputMVector = uinput->getUICoordinates();
348 size_t vlen = inputMVector->getLocalLength();
351 std::vector<const zscalar_t *> IDWeights;
352 std::vector<int> IDWeightsStrides;
355 if (uinput->hasUIWeights()) {
357 auto uiweights = uinput->getUIWeights();
359 nWeights = uiweights->getNumVectors();
360 IDWeights.resize(nWeights);
361 IDWeightsStrides.resize(nWeights);
363 for (
int w = 0; w < nWeights; w++) {
364 IDWeights[w] = uiweights->getData(w).getRawPtr();
365 IDWeightsStrides[w] = 1;
375 typedef ia_t::part_t
part_t;
378 memset(p, 0,
sizeof(
part_t) * vlen);
379 ArrayRCP<part_t> solnParts(p, 0, vlen,
true);
381 soln_t solution(env, comm, nWeights);
382 solution.setParts(solnParts);
389 std::cout <<
"Constructed with Tpetra::MultiVector" << std::endl;
391 RCP<const tvector_t> ctV = rcp_const_cast<const tvector_t>(inputMVector);
392 RCP<Zoltan2::XpetraMultiVectorAdapter<tvector_t> > tVInput;
397 IDWeights, IDWeightsStrides));
399 catch (std::exception &e){
401 std::cout << e.what() << std::endl;
405 fail = verifyInputAdapter<tvector_t>(*tVInput, *inputMVector, nVec,
406 IDWeights, IDWeightsStrides);
414 tVInput->applyPartitioningSolution(*inputMVector, vMigrate, solution);
415 migratedMVector = rcp(vMigrate);
417 catch (std::exception &e){
424 RCP<const tvector_t> cnewV =
425 rcp_const_cast<const tvector_t>(migratedMVector);
426 RCP<Zoltan2::XpetraMultiVectorAdapter<tvector_t> > newInput;
431 catch (std::exception &e){
433 std::cout << e.what() << std::endl;
438 std::cout <<
"Constructed with ";
439 std::cout <<
"Tpetra::MultiVector migrated to proc 0" << std::endl;
443 fail = verifyInputAdapter<tvector_t>(*newInput, *migratedMVector, nVec);
457 std::cout <<
"Constructed with Xpetra::MultiVector" << std::endl;
461 RCP<const xvector_t> cxV = rcp_const_cast<const xvector_t>(xV);
462 RCP<Zoltan2::XpetraMultiVectorAdapter<xvector_t> > xVInput;
470 catch (std::exception &e){
472 std::cout << e.what() << std::endl;
476 fail = verifyInputAdapter<xvector_t>(*xVInput, *inputMVector, nVec,
477 IDWeights, IDWeightsStrides);
484 xVInput->applyPartitioningSolution(*xV, vMigrate, solution);
486 catch (std::exception &e){
493 RCP<const xvector_t> cnewV(vMigrate);
494 RCP<Zoltan2::XpetraMultiVectorAdapter<xvector_t> > newInput;
499 catch (std::exception &e){
501 std::cout << e.what() << std::endl;
506 std::cout <<
"Constructed with ";
507 std::cout <<
"Xpetra::MultiVector migrated to proc 0" << std::endl;
509 fail = verifyInputAdapter<xvector_t>(*newInput, *migratedMVector, nVec);
519#ifdef HAVE_EPETRA_DATA_TYPES
522 typedef Epetra_MultiVector evector_t;
525 std::cout <<
"Constructed with Epetra_MultiVector" << std::endl;
528 rcp(
new Epetra_MultiVector(uinput->getUIEpetraCrsGraph()->RowMap(),
530 for (
int v = 0; v < nVec; v++) {
531 auto inV = inputMVector->getData(v);
532 for (
int i = 0; i < eV->MyLength(); i++)
533 eV->ReplaceMyValue(i, v, inV[i]);
536 RCP<const evector_t> ceV = rcp_const_cast<const evector_t>(eV);
537 RCP<Zoltan2::XpetraMultiVectorAdapter<evector_t> > eVInput;
539 bool goodAdapter =
true;
543 IDWeights, IDWeightsStrides));
545 catch (std::exception &e){
546 if (std::is_same<znode_t, Xpetra::EpetraNode>::value) {
549 std::cout << e.what() << std::endl;
554 std::cout <<
"Node type is not supported by Xpetra's Epetra interface;"
555 <<
" Skipping this test." << std::endl;
556 std::cout <<
"FYI: Here's the exception message: " << std::endl
557 << e.what() << std::endl;
564 fail = verifyInputAdapter<evector_t>(*eVInput, *inputMVector, nVec,
565 IDWeights, IDWeightsStrides);
570 evector_t *vMigrate =NULL;
572 eVInput->applyPartitioningSolution(*eV, vMigrate, solution);
574 catch (std::exception &e){
581 RCP<const evector_t> cnewV(vMigrate,
true);
582 RCP<Zoltan2::XpetraMultiVectorAdapter<evector_t> > newInput;
587 catch (std::exception &e){
589 std::cout << e.what() << std::endl;
594 std::cout <<
"Constructed with ";
595 std::cout <<
"Epetra_MultiVector migrated to proc 0" << std::endl;
597 fail = verifyInputAdapter<evector_t>(*newInput, *migratedMVector,
614 std::cout <<
"PASS" << std::endl;