50 #ifndef USERINPUTFORTESTS
51 #define USERINPUTFORTESTS
56 #include <Tpetra_MultiVector.hpp>
57 #include <Xpetra_Vector.hpp>
58 #include <Xpetra_CrsMatrix.hpp>
59 #include <Xpetra_CrsGraph.hpp>
61 #include <MatrixMarket_Tpetra.hpp>
62 #include <Galeri_XpetraProblemFactory.hpp>
63 #include <Galeri_XpetraParameters.hpp>
65 #include <Kokkos_DefaultNode.hpp>
68 #ifdef HAVE_ZOLTAN2_MPI
69 #include <Epetra_MpiComm.h>
71 #include <Epetra_SerialComm.h>
75 using Teuchos::ArrayRCP;
76 using Teuchos::ArrayView;
81 using Teuchos::rcp_const_cast;
118 typedef Tpetra::CrsMatrix<scalar_t, lno_t, gno_t, node_t>
tcrsMatrix_t;
120 typedef Tpetra::Vector<scalar_t, lno_t, gno_t, node_t>
tVector_t;
121 typedef Tpetra::MultiVector<scalar_t, lno_t, gno_t, node_t>
tMVector_t;
123 typedef Xpetra::CrsMatrix<scalar_t, lno_t, gno_t, node_t>
xcrsMatrix_t;
125 typedef Xpetra::Vector<scalar_t, lno_t, gno_t, node_t>
xVector_t;
126 typedef Xpetra::MultiVector<scalar_t, lno_t, gno_t, node_t>
xMVector_t;
128 typedef Tpetra::Map<lno_t, gno_t, node_t>
map_t;
129 typedef Tpetra::Export<lno_t, gno_t, node_t>
export_t;
130 typedef Tpetra::Import<lno_t, gno_t, node_t>
import_t;
150 const RCP<
const Comm<int> > &c,
bool debugInfo=
false);
169 const RCP<
const Comm<int> > &c,
bool debugInfo=
false);
198 #ifdef HAVE_EPETRA_DATA_TYPES
199 RCP<Epetra_CrsGraph> getEpetraCrsGraph();
201 RCP<Epetra_CrsMatrix> getEpetraCrsMatrix();
203 RCP<Epetra_Vector> getEpetraVector();
205 RCP<Epetra_MultiVector> getEpetraMultiVector(
int nvec);
212 const RCP<const Comm<int> > tcomm_;
214 RCP<tcrsMatrix_t> M_;
215 RCP<xcrsMatrix_t> xM_;
217 RCP<tMVector_t> xyz_;
218 RCP<tMVector_t> vtxWeights_;
219 RCP<tMVector_t> edgWeights_;
221 #ifdef HAVE_EPETRA_DATA_TYPES
222 RCP<const Epetra_Comm> ecomm_;
223 RCP<Epetra_CrsMatrix> eM_;
224 RCP<Epetra_CrsGraph> eG_;
232 void readMatrixMarketFile(
string path,
string testData);
237 void buildCrsMatrix(
int xdim,
int ydim,
int zdim,
string type);
244 void readZoltanTestData(
string path,
string testData);
247 void getChacoGraph(FILE *fptr,
string name);
250 void getChacoCoords(FILE *fptr,
string name);
254 const RCP<
const Comm<int> > &c,
bool debugInfo):
256 tcomm_(c), M_(), xM_(), xyz_(), vtxWeights_(), edgWeights_()
258 ,ecomm_(), eM_(), eG_()
261 bool zoltan1 =
false;
262 string::size_type loc = path.find(
"/zoltan/test/");
263 if (loc != string::npos)
267 readZoltanTestData(path, testData);
269 readMatrixMarketFile(path, testData);
271 #ifdef HAVE_EPETRA_DATA_TYPES
272 ecomm_ = Xpetra::toEpetra(c);
277 string matrixType,
const RCP<
const Comm<int> > &c,
bool debugInfo):
279 tcomm_(c), M_(), xM_(), xyz_(), vtxWeights_(), edgWeights_()
281 ,ecomm_(), eM_(), eG_()
284 if (matrixType.size() == 0){
290 matrixType = string(
"Laplace1D");
292 matrixType = string(
"Laplace2D");
294 matrixType = string(
"Laplace3D");
296 throw std::runtime_error(
"input");
298 if (verbose_ && tcomm_->getRank() == 0)
299 std::cout <<
"UserInputForTests, Matrix type : " << matrixType << std::endl;
302 buildCrsMatrix(x, y, z, matrixType);
304 #ifdef HAVE_EPETRA_DATA_TYPES
305 ecomm_ = Xpetra::toEpetra(c);
312 throw std::runtime_error(
"could not read coord file");
329 throw std::runtime_error(
"could not read mtx file");
336 throw std::runtime_error(
"could not read mtx file");
337 return rcp_const_cast<
tcrsGraph_t>(M_->getCrsGraph());
342 RCP<tVector_t> V = rcp(
new tVector_t(M_->getRowMap(), 1));
350 RCP<tMVector_t> mV = rcp(
new tMVector_t(M_->getRowMap(), nvec));
359 throw std::runtime_error(
"could not read mtx file");
366 throw std::runtime_error(
"could not read mtx file");
367 return rcp_const_cast<
xcrsGraph_t>(xM_->getCrsGraph());
373 RCP<const xVector_t> xV =
381 RCP<const xMVector_t> xMV =
386 #ifdef HAVE_EPETRA_DATA_TYPES
387 RCP<Epetra_CrsGraph> UserInputForTests::getEpetraCrsGraph()
390 throw std::runtime_error(
"could not read mtx file");
391 RCP<const tcrsGraph_t> tgraph = M_->getCrsGraph();
392 RCP<const Tpetra::Map<lno_t, gno_t> > trowMap = tgraph->getRowMap();
393 RCP<const Tpetra::Map<lno_t, gno_t> > tcolMap = tgraph->getColMap();
395 int nElts =
static_cast<int>(trowMap->getGlobalNumElements());
396 int nMyElts =
static_cast<int>(trowMap->getNodeNumElements());
397 int base = trowMap->getIndexBase();
398 ArrayView<const int> gids = trowMap->getNodeElementList();
400 Epetra_BlockMap erowMap(nElts, nMyElts,
401 gids.getRawPtr(), 1, base, *ecomm_);
403 Array<int> rowSize(nMyElts);
404 for (
int i=0; i < nMyElts; i++){
405 rowSize[i] =
static_cast<int>(M_->getNumEntriesInLocalRow(i+base));
408 size_t maxRow = M_->getNodeMaxNumRowEntries();
409 Array<int> colGids(maxRow);
410 ArrayView<const int> colLid;
412 eG_ = rcp(
new Epetra_CrsGraph(Copy, erowMap,
413 rowSize.getRawPtr(),
true));
415 for (
int i=0; i < nMyElts; i++){
416 tgraph->getLocalRowView(i+base, colLid);
417 for (
int j=0; j < colLid.size(); j++)
418 colGids[j] = tcolMap->getGlobalElement(colLid[j]);
419 eG_->InsertGlobalIndices(gids[i], rowSize[i], colGids.getRawPtr());
425 RCP<Epetra_CrsMatrix> UserInputForTests::getEpetraCrsMatrix()
428 throw std::runtime_error(
"could not read mtx file");
429 RCP<Epetra_CrsGraph> egraph = getEpetraCrsGraph();
430 eM_ = rcp(
new Epetra_CrsMatrix(Copy, *egraph));
432 size_t maxRow = M_->getNodeMaxNumRowEntries();
433 int nrows = egraph->NumMyRows();
434 int base = egraph->IndexBase();
435 const Epetra_BlockMap &rowMap = egraph->RowMap();
436 const Epetra_BlockMap &colMap = egraph->ColMap();
437 Array<int> colGid(maxRow);
439 for (
int i=0; i < nrows; i++){
440 ArrayView<const int> colLid;
441 ArrayView<const scalar_t> nz;
442 M_->getLocalRowView(i+base, colLid, nz);
443 size_t rowSize = colLid.size();
444 int rowGid = rowMap.GID(i+base);
445 for (
size_t j=0; j < rowSize; j++){
446 colGid[j] = colMap.GID(colLid[j]);
448 eM_->InsertGlobalValues(
449 rowGid, rowSize, nz.getRawPtr(), colGid.getRawPtr());
455 RCP<Epetra_Vector> UserInputForTests::getEpetraVector()
457 RCP<Epetra_CrsGraph> egraph = getEpetraCrsGraph();
458 RCP<Epetra_Vector> V = rcp(
new Epetra_Vector(egraph->RowMap()));
463 RCP<Epetra_MultiVector> UserInputForTests::getEpetraMultiVector(
int nvec)
465 RCP<Epetra_CrsGraph> egraph = getEpetraCrsGraph();
466 RCP<Epetra_MultiVector> mV =
467 rcp(
new Epetra_MultiVector(egraph->RowMap(), nvec));
475 ArrayView<ArrayRCP<scalar_t > > data)
480 size_t dim = data.size();
481 for (
size_t i=0; i < dim; i++){
484 throw (std::bad_alloc());
485 data[i] = Teuchos::arcp(tmp, 0, length,
true);
488 scalar_t scalingFactor = (max-min) / RAND_MAX;
490 for (
size_t i=0; i < dim; i++){
492 for (
lno_t j=0; j < length; j++)
493 *x++ = min + (
scalar_t(rand()) * scalingFactor);
497 void UserInputForTests::readMatrixMarketFile(
string path,
string testData)
499 std::ostringstream fname;
500 fname << path <<
"/" << testData <<
".mtx";
501 RCP<Kokkos::DefaultNode::DefaultNodeType> dnode
502 = Kokkos::DefaultNode::getDefaultNode();
504 if (verbose_ && tcomm_->getRank() == 0)
505 std::cout <<
"UserInputForTests, Read: " << fname.str() << std::endl;
514 M_ = Tpetra::MatrixMarket::Reader<tcrsMatrix_t>::readSparseFile(
515 fname.str(), tcomm_, dnode,
true,
true,
false);
517 catch (std::exception &e) {
523 RCP<const xcrsMatrix_t> xm =
528 if (tcomm_->getRank() == 0)
529 std::cout <<
"UserInputForTests unable to read matrix." << std::endl;
535 fname << path <<
"/" << testData <<
"_coord.mtx";
537 size_t coordDim = 0, numGlobalCoords = 0;
539 ArrayRCP<ArrayRCP<scalar_t> > xyz;
540 std::ifstream coordFile;
542 if (tcomm_->getRank() == 0){
545 std::cout <<
"UserInputForTests, Read: " <<
546 fname.str() << std::endl;
550 coordFile.open(fname.str().c_str());
552 catch (std::exception &e){
563 while (!done && !fail && coordFile.good()){
564 coordFile.getline(c, 256);
567 else if (c[0] ==
'%')
571 std::istringstream s(c);
572 s >> numGlobalCoords >> coordDim;
573 if (!s.eof() || numGlobalCoords < 1 || coordDim < 1)
582 xyz = Teuchos::arcp(
new ArrayRCP<scalar_t> [coordDim], 0, coordDim);
584 for (
size_t dim=0; !fail && dim < coordDim; dim++){
590 xyz[dim] = Teuchos::arcp(tmp, 0, numGlobalCoords);
592 for (idx=0; !coordFile.eof() && idx < numGlobalCoords; idx++){
593 coordFile.getline(c, 256);
594 std::istringstream s(c);
598 if (idx < numGlobalCoords)
604 ArrayRCP<scalar_t> emptyArray;
605 for (
size_t dim=0; dim < coordDim; dim++)
606 xyz[dim] = emptyArray;
619 msg[1] = numGlobalCoords;
623 Teuchos::broadcast<int, size_t>(*tcomm_, 0, 2, msg);
626 numGlobalCoords= msg[1];
632 RCP<const map_t> toMap;
635 base = M_->getIndexBase();
636 const RCP<const map_t> &mapM = M_->getRowMap();
641 toMap = rcp(
new map_t(numGlobalCoords, base, tcomm_));
648 ArrayRCP<ArrayView<const scalar_t> > coordLists(coordDim);
650 if (tcomm_->getRank() == 0){
652 for (
size_t dim=0; dim < coordDim; dim++)
653 coordLists[dim] = xyz[dim].view(0, numGlobalCoords);
657 throw std::bad_alloc();
659 ArrayRCP<const gno_t> rowIds = Teuchos::arcp(tmp, 0, numGlobalCoords);
661 gno_t basePlusNumGlobalCoords = base+numGlobalCoords;
662 for (
gno_t id=base;
id < basePlusNumGlobalCoords;
id++)
665 RCP<const map_t> fromMap = rcp(
new map_t(numGlobalCoords,
666 rowIds.view(0, numGlobalCoords), base, tcomm_));
668 tMVector_t allCoords(fromMap, coordLists.view(0, coordDim), coordDim);
672 xyz_->doExport(allCoords, exporter, Tpetra::INSERT);
676 RCP<const map_t> fromMap = rcp(
new map_t(numGlobalCoords,
677 ArrayView<gno_t>(), base, tcomm_));
679 tMVector_t allCoords(fromMap, coordLists.view(0, coordDim), coordDim);
683 xyz_->doExport(allCoords, exporter, Tpetra::INSERT);
687 void UserInputForTests::buildCrsMatrix(
int xdim,
int ydim,
int zdim,
690 Teuchos::CommandLineProcessor tclp;
691 Galeri::Xpetra::Parameters<gno_t> params(tclp,
692 xdim, ydim, zdim, problemType);
694 RCP<const Tpetra::Map<lno_t, gno_t> > map =
695 rcp(
new Tpetra::Map<lno_t, gno_t>(
696 params.GetNumGlobalElements(), 0, tcomm_));
698 if (verbose_ && tcomm_->getRank() == 0){
699 std::cout <<
"UserInputForTests, Create matrix with " << problemType;
700 std::cout <<
" (and" << xdim;
702 std::cout <<
" x " << ydim <<
" x " << zdim << std::endl;
704 std::cout <<
" x" << ydim <<
" x 1" << std::endl;
706 std::cout <<
"x 1 x 1" << std::endl;
708 std::cout <<
" mesh)" << std::endl;
712 RCP<Galeri::Xpetra::Problem<Tpetra::Map<lno_t, gno_t>, Tpetra::CrsMatrix<scalar_t, lno_t, gno_t>, Tpetra::MultiVector<scalar_t, lno_t, gno_t> > > Pr =
713 Galeri::Xpetra::BuildProblem<scalar_t, lno_t, gno_t, Tpetra::Map<lno_t, gno_t>, Tpetra::CrsMatrix<scalar_t, lno_t, gno_t>, Tpetra::MultiVector<scalar_t, lno_t, gno_t> >
714 (params.GetMatrixType(), map, params.GetParameterList());
715 M_ = Pr->BuildMatrix();
717 catch (std::exception &e) {
721 RCP<const xcrsMatrix_t> xm =
727 if (verbose_ && tcomm_->getRank() == 0)
729 "UserInputForTests, Implied matrix row coordinates computed" <<
732 ArrayView<const gno_t> gids = map->getNodeElementList();
733 lno_t count = gids.size();
735 size_t pos = problemType.find(
"2D");
736 if (pos != string::npos)
738 else if (problemType ==
string(
"Laplace1D") ||
739 problemType ==
string(
"Identity"))
742 Array<ArrayRCP<scalar_t> > coordinates(dim);
745 for (
int i=0; i < dim; i++){
748 throw(std::bad_alloc());
749 coordinates[i] = Teuchos::arcp(c, 0, count,
true);
753 scalar_t *x = coordinates[0].getRawPtr();
754 scalar_t *y = coordinates[1].getRawPtr();
755 scalar_t *z = coordinates[2].getRawPtr();
756 gno_t xySize = xdim * ydim;
757 for (
lno_t i=0; i < count; i++){
758 gno_t iz = gids[i] / xySize;
759 gno_t xy = gids[i] - iz*xySize;
766 scalar_t *x = coordinates[0].getRawPtr();
767 scalar_t *y = coordinates[1].getRawPtr();
768 for (
lno_t i=0; i < count; i++){
774 scalar_t *x = coordinates[0].getRawPtr();
775 for (
lno_t i=0; i < count; i++)
780 Array<ArrayView<const scalar_t> > coordView(dim);
782 for (
int i=0; i < dim; i++)
783 coordView[i] = coordinates[i].view(0,count);
785 xyz_ = rcp(
new tMVector_t(map, coordView.view(0, dim), dim));
788 void UserInputForTests::readZoltanTestData(
string path,
string testData)
790 int rank = tcomm_->getRank();
791 FILE *graphFile = NULL;
792 FILE *coordFile = NULL;
796 std::ostringstream chGraphFileName;
797 chGraphFileName << path <<
"/ch_" << testData <<
"/" << testData <<
".graph";
798 std::ostringstream chCoordFileName;
799 chCoordFileName << path <<
"/ch_" << testData <<
"/" << testData <<
".coords";
800 memset(fileInfo, 0,
sizeof(
int) * 2);
802 graphFile = fopen(chGraphFileName.str().c_str(),
"r");
805 if (verbose_ && tcomm_->getRank() == 0)
806 std::cout <<
"UserInputForTests, open " <<
807 chGraphFileName << std::endl;
809 coordFile = fopen(chCoordFileName.str().c_str(),
"r");
812 if (verbose_ && tcomm_->getRank() == 0)
813 std::cout <<
"UserInputForTests, open " <<
814 chCoordFileName << std::endl;
819 Teuchos::broadcast<int, int>(*tcomm_, 0, 2, fileInfo);
821 bool haveGraph = (fileInfo[0] == 1);
822 bool haveCoords = (fileInfo[1] == 1);
827 getChacoGraph(graphFile, testData);
834 getChacoCoords(coordFile, testData);
840 RCP<const xcrsMatrix_t> xm =
845 void UserInputForTests::getChacoGraph(FILE *fptr,
string fname)
847 int rank = tcomm_->getRank();
849 int nvtxs=0, nedges=0;
850 int vwgt_dim=0, ewgt_dim=0;
851 int *start = NULL, *adj = NULL;
852 float *ewgts = NULL, *vwgts = NULL;
853 size_t *nzPerRow = NULL;
854 size_t maxRowLen = 0;
856 ArrayRCP<const size_t> rowSizes;
858 bool haveEdges =
true;
862 memset(graphCounts, 0, 5*
sizeof(
int));
867 char *nonConstName =
new char [fname.size() + 1];
868 strcpy(nonConstName, fname.c_str());
871 &start, &adj, &nvtxs, &vwgt_dim, &vwgts, &ewgt_dim, &ewgts);
872 delete [] nonConstName;
880 std::cout <<
"UserInputForTests, " << nvtxs <<
" vertices,";
882 std::cout << start[nvtxs] <<
" edges,";
884 std::cout <<
"no edges,";
885 std::cout << vwgt_dim <<
" vertex weights, ";
886 std::cout << ewgt_dim <<
" edge weights" << std::endl;
893 Teuchos::broadcast<int, int>(*tcomm_, 0, 5, graphCounts);
894 throw std::runtime_error(
"Unable to read chaco file");
898 nedges = start[nvtxs];
900 nzPerRow =
new size_t [nvtxs];
902 throw std::bad_alloc();
903 rowSizes = arcp(nzPerRow, 0, nvtxs,
true);
906 for (
int i=0; i < nvtxs; i++){
907 nzPerRow[i] = start[i+1] - start[i];
908 if (nzPerRow[i] > maxRowLen)
909 maxRowLen = nzPerRow[i];
913 memset(nzPerRow, 0,
sizeof(
size_t) * nvtxs);
925 for (
int i=1; i < nedges; i++)
930 for (
int i=0; i < nedges; i++)
935 graphCounts[0] = nvtxs;
936 graphCounts[1] = nedges;
937 graphCounts[2] = vwgt_dim;
938 graphCounts[3] = ewgt_dim;
939 graphCounts[4] = maxRowLen;
942 Teuchos::broadcast<int, int>(*tcomm_, 0, 5, graphCounts);
944 if (graphCounts[0] == 0)
945 throw std::runtime_error(
"Unable to read chaco file");
947 haveEdges = (graphCounts[1] > 0);
949 RCP<tcrsMatrix_t> fromMatrix;
950 RCP<const map_t> fromMap;
955 fromMap = rcp(
new map_t(nvtxs, nvtxs, base, tcomm_));
958 rcp(
new tcrsMatrix_t(fromMap, rowSizes, Tpetra::StaticProfile));
963 if (nedges && !edgeIds)
964 throw std::bad_alloc();
965 for (
int i=0; i < nedges; i++)
971 gno_t *nextId = edgeIds;
972 Array<scalar_t> values(maxRowLen, 1.0);
974 for (
gno_t i=0; i < nvtxs; i++){
975 if (nzPerRow[i] > 0){
976 ArrayView<const gno_t> rowNz(nextId, nzPerRow[i]);
977 fromMatrix->insertGlobalValues(i, rowNz, values.view(0,nzPerRow[i]));
978 nextId += nzPerRow[i];
986 fromMatrix->fillComplete();
989 nvtxs = graphCounts[0];
990 nedges = graphCounts[1];
991 vwgt_dim = graphCounts[2];
992 ewgt_dim = graphCounts[3];
993 maxRowLen = graphCounts[4];
997 fromMap = rcp(
new map_t(nvtxs, 0, base, tcomm_));
1000 rcp(
new tcrsMatrix_t(fromMap, rowSizes, Tpetra::StaticProfile));
1002 fromMatrix->fillComplete();
1007 RCP<const map_t> toMap = rcp(
new map_t(nvtxs, base, tcomm_));
1008 RCP<tcrsMatrix_t> toMatrix = rcp(
new tcrsMatrix_t(toMap, maxRowLen));
1012 RCP<import_t> importer = rcp(
new import_t(fromMap, toMap));
1013 toMatrix->doImport(*fromMatrix, *importer, Tpetra::INSERT);
1014 toMatrix->fillComplete();
1020 typedef ArrayRCP<const ArrayView<const scalar_t> > arrayArray_t;
1024 ArrayRCP<scalar_t> weightBuf;
1025 ArrayView<const scalar_t> *wgts =
new ArrayView<const scalar_t> [vwgt_dim];
1028 size_t len = vwgt_dim * nvtxs;
1030 if (!buf)
throw std::bad_alloc();
1031 weightBuf = arcp(buf, 0, len,
true);
1033 for (
int wdim=0; wdim < vwgt_dim; wdim++){
1034 wgts[wdim] = ArrayView<const scalar_t>(buf, nvtxs);
1035 float *vw = vwgts + wdim;
1036 for (
int i=0; i < nvtxs; i++, vw += vwgt_dim)
1045 arrayArray_t vweights = arcp(wgts, 0, vwgt_dim,
true);
1047 RCP<tMVector_t> fromVertexWeights =
1048 rcp(
new tMVector_t(fromMap, vweights.view(0, vwgt_dim), vwgt_dim));
1050 RCP<tMVector_t> toVertexWeights = rcp(
new tMVector_t(toMap, vwgt_dim));
1052 toVertexWeights->doImport(*fromVertexWeights, *importer, Tpetra::INSERT);
1054 vtxWeights_ = toVertexWeights;
1059 if (haveEdges && ewgt_dim > 0){
1061 ArrayRCP<scalar_t> weightBuf;
1062 ArrayView<const scalar_t> *wgts =
new ArrayView<const scalar_t> [ewgt_dim];
1064 toMap = rcp(
new map_t(nedges, M_->getNodeNumEntries(), base, tcomm_));
1067 size_t len = ewgt_dim * nedges;
1069 if (!buf)
throw std::bad_alloc();
1070 weightBuf = arcp(buf, 0, len,
true);
1072 for (
int wdim=0; wdim < ewgt_dim; wdim++){
1073 wgts[wdim] = ArrayView<const scalar_t>(buf, nedges);
1074 float *ew = ewgts + wdim;
1075 for (
int i=0; i < nedges; i++, ew += ewgt_dim)
1082 fromMap = rcp(
new map_t(nedges, nedges, base, tcomm_));
1085 fromMap = rcp(
new map_t(nedges, 0, base, tcomm_));
1088 arrayArray_t eweights = arcp(wgts, 0, ewgt_dim,
true);
1090 RCP<tMVector_t> fromEdgeWeights =
1091 rcp(
new tMVector_t(fromMap, eweights.view(0, ewgt_dim), ewgt_dim));
1093 RCP<tMVector_t> toEdgeWeights = rcp(
new tMVector_t(toMap, ewgt_dim));
1095 RCP<import_t> edgeImporter = rcp(
new import_t(fromMap, toMap));
1097 toEdgeWeights->doImport(*fromEdgeWeights, *edgeImporter, Tpetra::INSERT);
1099 edgWeights_ = toEdgeWeights;
1103 void UserInputForTests::getChacoCoords(FILE *fptr,
string fname)
1105 int rank = tcomm_->getRank();
1107 float *x=NULL, *y=NULL, *z=NULL;
1110 size_t localNumVtx = M_->getNodeNumRows();
1111 size_t globalNumVtx = M_->getGlobalNumRows();
1118 char *nonConstName =
new char [fname.size() + 1];
1119 strcpy(nonConstName, fname.c_str());
1122 delete [] nonConstName;
1128 std::cout <<
"UserInputForTests, read " << globalNumVtx;
1129 std::cout <<
" " << ndim <<
"-dimensional coordinates." << std::endl;
1133 Teuchos::broadcast<int, int>(*tcomm_, 0, 1, &ndim);
1136 throw std::runtime_error(
"Can't read coordinate file");
1138 ArrayRCP<ArrayRCP<const scalar_t> > coords(ndim);
1143 for (
int dim=0; dim < ndim; dim++){
1146 throw std::bad_alloc();
1147 coords[dim] = arcp<const scalar_t>(v, 0, globalNumVtx,
true);
1148 float *val = (dim==0 ? x : (dim==1 ? y : z));
1149 for (
size_t i=0; i < globalNumVtx; i++)
1155 len = globalNumVtx;;
1158 RCP<const map_t> fromMap = rcp(
new map_t(globalNumVtx, len, 0, tcomm_));
1159 RCP<const map_t> toMap = rcp(
new map_t(globalNumVtx, localNumVtx, 0, tcomm_));
1160 RCP<import_t> importer = rcp(
new import_t(fromMap, toMap));
1162 Array<ArrayView<const scalar_t> > coordData;
1163 for (
int dim=0; dim < ndim; dim++)
1164 coordData.push_back(coords[dim].view(0, len));
1166 RCP<tMVector_t> fromCoords =
1167 rcp(
new tMVector_t(fromMap, coordData.view(0, ndim), ndim));
1169 RCP<tMVector_t> toCoords = rcp(
new tMVector_t(toMap, ndim));
1171 toCoords->doImport(*fromCoords, *importer, Tpetra::INSERT);
#define TEST_FAIL_AND_THROW(comm, ok, s)
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
Traits of Xpetra classes, including migration method.
#define HAVE_EPETRA_DATA_TYPES
static RCP< const User > convertToXpetra(const RCP< const User > &a)
Convert the object to its Xpetra wrapped version.
int chaco_input_graph(FILE *fin, char *inname, int **start, int **adjacency, int *nvtxs, int *vwgt_dim, float **vweights, int *ewgt_dim, float **eweights)
read a Chaco graph file Reader code was copied from zoltan1 test driver code. File is closed when rea...
int chaco_input_geom(FILE *fingeom, char *geomname, int nvtxs, int *igeom, float **x, float **y, float **z)
read a Chaco coordinates file Reader code was copied from zoltan1 test driver code. File is closed when read is completed.