50 #ifndef USERINPUTFORTESTS 51 #define USERINPUTFORTESTS 56 #include <Tpetra_MultiVector.hpp> 57 #include <Tpetra_CrsMatrix.hpp> 58 #include <Tpetra_Map.hpp> 59 #include <Xpetra_Vector.hpp> 60 #include <Xpetra_CrsMatrix.hpp> 61 #include <Xpetra_CrsGraph.hpp> 63 #include <MatrixMarket_Tpetra.hpp> 64 #include <Galeri_XpetraProblemFactory.hpp> 65 #include <Galeri_XpetraParameters.hpp> 67 #include <Kokkos_DefaultNode.hpp> 73 #include <TpetraExt_MatrixMatrix_def.hpp> 76 #ifdef HAVE_ZOLTAN2_MPI 77 #include <Epetra_MpiComm.h> 79 #include <Epetra_SerialComm.h> 87 using Teuchos::ArrayRCP;
88 using Teuchos::ArrayView;
93 using Teuchos::rcp_const_cast;
94 using Teuchos::ParameterList;
133 typedef Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>
tcrsMatrix_t;
135 typedef Tpetra::Vector<zscalar_t, zlno_t, zgno_t, znode_t>
tVector_t;
136 typedef Tpetra::MultiVector<zscalar_t, zlno_t, zgno_t, znode_t>
tMVector_t;
138 typedef Xpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>
xcrsMatrix_t;
140 typedef Xpetra::Vector<zscalar_t, zlno_t, zgno_t, znode_t>
xVector_t;
141 typedef Xpetra::MultiVector<zscalar_t, zlno_t, zgno_t, znode_t>
xMVector_t;
143 typedef Tpetra::Map<zlno_t, zgno_t, znode_t>
map_t;
144 typedef Tpetra::Export<zlno_t, zgno_t, znode_t>
export_t;
145 typedef Tpetra::Import<zlno_t, zgno_t, znode_t>
import_t;
171 const RCP<
const Comm<int> > &c,
bool debugInfo=
false,
172 bool distributeInput=
true);
191 const RCP<
const Comm<int> > &c,
bool debugInfo=
false,
192 bool distributeInput=
true);
210 const RCP<
const Comm<int> > &c);
214 static void getUIRandomData(
unsigned int seed,
zlno_t length,
217 RCP<tMVector_t> getUICoordinates();
219 RCP<tMVector_t> getUIWeights();
221 RCP<tMVector_t> getUIEdgeWeights();
223 RCP<tcrsMatrix_t> getUITpetraCrsMatrix();
225 RCP<tcrsGraph_t> getUITpetraCrsGraph();
227 RCP<tVector_t> getUITpetraVector();
229 RCP<tMVector_t> getUITpetraMultiVector(
int nvec);
231 RCP<xcrsMatrix_t> getUIXpetraCrsMatrix();
233 RCP<xcrsGraph_t> getUIXpetraCrsGraph();
235 RCP<xVector_t> getUIXpetraVector();
237 RCP<xMVector_t> getUIXpetraMultiVector(
int nvec);
241 #ifdef HAVE_EPETRA_DATA_TYPES 242 RCP<Epetra_CrsGraph> getUIEpetraCrsGraph();
244 RCP<Epetra_CrsMatrix> getUIEpetraCrsMatrix();
246 RCP<Epetra_Vector> getUIEpetraVector();
248 RCP<Epetra_MultiVector> getUIEpetraMultiVector(
int nvec);
252 bool hasInputDataType(
const string &input_type);
254 bool hasUICoordinates();
258 bool hasUIEdgeWeights();
260 bool hasUITpetraCrsMatrix();
262 bool hasUITpetraCrsGraph();
264 bool hasUITpetraVector();
266 bool hasUITpetraMultiVector();
268 bool hasUIXpetraCrsMatrix();
270 bool hasUIXpetraCrsGraph();
272 bool hasUIXpetraVector();
274 bool hasUIXpetraMultiVector();
276 bool hasPamgenMesh();
277 #ifdef HAVE_EPETRA_DATA_TYPES 278 bool hasUIEpetraCrsGraph();
280 bool hasUIEpetraCrsMatrix();
282 bool hasUIEpetraVector();
284 bool hasUIEpetraMultiVector();
292 const RCP<const Comm<int> > tcomm_;
295 RCP<PamgenMesh> pamgen_mesh;
297 RCP<tcrsMatrix_t> M_;
298 RCP<xcrsMatrix_t> xM_;
300 RCP<tMVector_t> xyz_;
301 RCP<tMVector_t> vtxWeights_;
302 RCP<tMVector_t> edgWeights_;
304 #ifdef HAVE_EPETRA_DATA_TYPES 305 RCP<const Epetra_Comm> ecomm_;
306 RCP<Epetra_CrsMatrix> eM_;
307 RCP<Epetra_CrsGraph> eG_;
315 void readMatrixMarketFile(
string path,
string testData,
bool distributeInput =
true);
320 void buildCrsMatrix(
int xdim,
int ydim,
int zdim,
string type,
321 bool distributeInput);
327 void readZoltanTestData(
string path,
string testData,
328 bool distributeInput);
331 void getUIChacoGraph(FILE *fptr,
string name,
bool distributeInput);
334 void getUIChacoCoords(FILE *fptr,
string name);
340 static const int CHACO_LINE_LENGTH=200;
341 char chaco_line[CHACO_LINE_LENGTH];
346 double chaco_read_val(FILE* infile,
int *end_flag);
347 int chaco_read_int(FILE* infile,
int *end_flag);
348 void chaco_flush_line(FILE*);
351 int chaco_input_graph(FILE *fin,
char *inname,
int **start,
352 int **adjacency,
int *nvtxs,
int *nVwgts,
353 float **vweights,
int *nEwgts,
float **eweights);
356 int chaco_input_geom(FILE *fingeom,
char *geomname,
int nvtxs,
357 int *igeom,
float **x,
float **y,
float **z);
364 void readGeometricGenTestData(
string path,
string testData);
368 ParameterList &geoparams);
373 const string& delimiters =
" \f\n\r\t\v" );
376 const string& delimiters =
" \f\n\r\t\v" );
379 const string& delimiters =
" \f\n\r\t\v" );
383 void readPamgenMeshFile(
string path,
string testData);
384 void setPamgenAdjacencyGraph();
385 void setPamgenCoordinateMV();
389 const RCP<
const Comm<int> > &c,
390 bool debugInfo,
bool distributeInput):
391 verbose_(debugInfo), tcomm_(c), havePamgenMesh(false),
392 M_(), xM_(), xyz_(), vtxWeights_(), edgWeights_(),
394 ecomm_(), eM_(), eG_(),
396 chaco_offset(0), chaco_break_pnt(CHACO_LINE_LENGTH)
398 bool zoltan1 =
false;
399 string::size_type loc = path.find(
"/zoltan/test/");
400 if (loc != string::npos)
404 readZoltanTestData(path, testData, distributeInput);
406 readMatrixMarketFile(path, testData);
408 #ifdef HAVE_EPETRA_DATA_TYPES 409 ecomm_ = Xpetra::toEpetra(c);
415 const RCP<
const Comm<int> > &c,
417 bool distributeInput):
418 verbose_(debugInfo), tcomm_(c), havePamgenMesh(false),
419 M_(), xM_(), xyz_(), vtxWeights_(), edgWeights_(),
421 ecomm_(), eM_(), eG_(),
423 chaco_offset(0), chaco_break_pnt(CHACO_LINE_LENGTH)
425 if (matrixType.size() == 0){
431 matrixType = string(
"Laplace1D");
433 matrixType = string(
"Laplace2D");
435 matrixType = string(
"Laplace3D");
437 throw std::runtime_error(
"input");
439 if (verbose_ && tcomm_->getRank() == 0)
440 std::cout <<
"UserInputForTests, Matrix type : " << matrixType << std::endl;
443 buildCrsMatrix(x, y, z, matrixType, distributeInput);
445 #ifdef HAVE_EPETRA_DATA_TYPES 446 ecomm_ = Xpetra::toEpetra(c);
451 const RCP<
const Comm<int> > &c):
452 tcomm_(c), havePamgenMesh(false),
453 M_(), xM_(), xyz_(), vtxWeights_(), edgWeights_(),
455 ecomm_(), eM_(), eG_(),
457 chaco_offset(0), chaco_break_pnt(CHACO_LINE_LENGTH)
461 bool distributeInput =
true, debugInfo =
true;
463 if(pList.isParameter(
"distribute input"))
464 distributeInput = pList.get<
bool>(
"distribute input");
466 if(pList.isParameter(
"debug"))
467 debugInfo = pList.get<
bool>(
"debug");
468 this->verbose_ = debugInfo;
470 if(pList.isParameter(
"input file"))
475 if(pList.isParameter(
"input path"))
476 path = pList.get<
string>(
"input path");
478 string testData = pList.get<
string>(
"input file");
484 if(pList.isParameter(
"file type") && pList.get<
string>(
"file type") ==
"Geometric Generator")
486 else if(pList.isParameter(
"file type") && pList.get<
string>(
"file type") ==
"Pamgen")
490 else if(pList.isParameter(
"file type") && pList.get<
string>(
"file type") ==
"Chaco")
494 switch (file_format) {
495 case GEOMGEN: readGeometricGenTestData(path,testData);
break;
496 case PAMGEN: readPamgenMeshFile(path,testData);
break;
497 case CHACO: readZoltanTestData(path, testData, distributeInput);
break;
498 default: readMatrixMarketFile(path, testData, distributeInput);
break;
501 }
else if(pList.isParameter(
"x") || pList.isParameter(
"y") || pList.isParameter(
"z")){
505 if(pList.isParameter(
"x")) x = pList.get<
int>(
"x");
506 if(pList.isParameter(
"y")) y = pList.get<
int>(
"y");
507 if(pList.isParameter(
"z")) z = pList.get<
int>(
"z");
509 string problemType =
"";
510 if(pList.isParameter(
"equation type")) problemType = pList.get<
string>(
"equation type");
512 if (problemType.size() == 0){
518 problemType = string(
"Laplace1D");
520 problemType = string(
"Laplace2D");
522 problemType = string(
"Laplace3D");
524 throw std::runtime_error(
"input");
526 if (verbose_ && tcomm_->getRank() == 0)
527 std::cout <<
"UserInputForTests, Matrix type : " << problemType << std::endl;
531 buildCrsMatrix(x, y, z, problemType, distributeInput);
534 std::cerr <<
"Input file block undefined!" << std::endl;
537 #ifdef HAVE_EPETRA_DATA_TYPES 538 ecomm_ = Xpetra::toEpetra(c);
547 throw std::runtime_error(
"could not read coord file");
564 throw std::runtime_error(
"could not read mtx file");
571 throw std::runtime_error(
"could not read mtx file");
572 return rcp_const_cast<
tcrsGraph_t>(M_->getCrsGraph());
577 RCP<tVector_t> V = rcp(
new tVector_t(M_->getRowMap(), 1));
585 RCP<tMVector_t> mV = rcp(
new tMVector_t(M_->getRowMap(), nvec));
594 throw std::runtime_error(
"could not read mtx file");
601 throw std::runtime_error(
"could not read mtx file");
602 return rcp_const_cast<
xcrsGraph_t>(xM_->getCrsGraph());
616 #ifdef HAVE_EPETRA_DATA_TYPES 620 throw std::runtime_error(
"could not read mtx file");
621 RCP<const tcrsGraph_t> tgraph = M_->getCrsGraph();
622 RCP<const Tpetra::Map<zlno_t, zgno_t> > trowMap = tgraph->getRowMap();
623 RCP<const Tpetra::Map<zlno_t, zgno_t> > tcolMap = tgraph->getColMap();
625 int nElts =
static_cast<int>(trowMap->getGlobalNumElements());
626 int nMyElts =
static_cast<int>(trowMap->getNodeNumElements());
627 int base = trowMap->getIndexBase();
628 ArrayView<const int> gids = trowMap->getNodeElementList();
630 Epetra_BlockMap erowMap(nElts, nMyElts,
631 gids.getRawPtr(), 1, base, *ecomm_);
633 Array<int> rowSize(nMyElts);
634 for (
int i=0; i < nMyElts; i++){
635 rowSize[i] =
static_cast<int>(M_->getNumEntriesInLocalRow(i+base));
638 size_t maxRow = M_->getNodeMaxNumRowEntries();
639 Array<int> colGids(maxRow);
640 ArrayView<const int> colLid;
642 eG_ = rcp(
new Epetra_CrsGraph(Copy, erowMap,
643 rowSize.getRawPtr(),
true));
645 for (
int i=0; i < nMyElts; i++){
646 tgraph->getLocalRowView(i+base, colLid);
647 for (
int j=0; j < colLid.size(); j++)
648 colGids[j] = tcolMap->getGlobalElement(colLid[j]);
649 eG_->InsertGlobalIndices(gids[i], rowSize[i], colGids.getRawPtr());
658 throw std::runtime_error(
"could not read mtx file");
660 eM_ = rcp(
new Epetra_CrsMatrix(Copy, *egraph));
662 size_t maxRow = M_->getNodeMaxNumRowEntries();
663 int nrows = egraph->NumMyRows();
664 int base = egraph->IndexBase();
665 const Epetra_BlockMap &rowMap = egraph->RowMap();
666 const Epetra_BlockMap &colMap = egraph->ColMap();
667 Array<int> colGid(maxRow);
669 for (
int i=0; i < nrows; i++){
670 ArrayView<const int> colLid;
671 ArrayView<const zscalar_t> nz;
672 M_->getLocalRowView(i+base, colLid, nz);
673 size_t rowSize = colLid.size();
674 int rowGid = rowMap.GID(i+base);
675 for (
size_t j=0; j < rowSize; j++){
676 colGid[j] = colMap.GID(colLid[j]);
678 eM_->InsertGlobalValues(rowGid, (
int)rowSize, nz.getRawPtr(), colGid.getRawPtr());
687 RCP<Epetra_Vector> V = rcp(
new Epetra_Vector(egraph->RowMap()));
695 RCP<Epetra_MultiVector> mV =
696 rcp(
new Epetra_MultiVector(egraph->RowMap(), nvec));
706 this->hasUITpetraCrsMatrix() || \
707 this->hasUITpetraCrsGraph() || \
708 this->hasPamgenMesh();
713 if(input_type ==
"coordinates")
715 else if(input_type ==
"tpetra_vector")
717 else if(input_type ==
"tpetra_multivector")
719 else if(input_type ==
"tpetra_crs_graph")
721 else if(input_type ==
"tpetra_crs_matrix")
723 else if(input_type ==
"xpetra_vector")
725 else if(input_type ==
"xpetra_multivector")
727 else if(input_type ==
"xpetra_crs_graph")
729 else if(input_type ==
"xpetra_crs_matrix")
731 #ifdef HAVE_EPETRA_DATA_TYPES 732 else if(input_type ==
"epetra_vector")
734 else if(input_type ==
"epetra_multivector")
736 else if(input_type ==
"epetra_crs_graph")
738 else if(input_type ==
"epetra_crs_matrix")
747 return xyz_.is_null() ?
false :
true;
752 return vtxWeights_.is_null() ?
false :
true;
757 return edgWeights_.is_null() ?
false :
true;
762 return M_.is_null() ?
false :
true;
767 return M_.is_null() ?
false :
true;
782 return M_.is_null() ?
false :
true;
787 return M_.is_null() ?
false :
true;
802 return this->havePamgenMesh;
805 #ifdef HAVE_EPETRA_DATA_TYPES 808 return M_.is_null() ?
false :
true;
829 ArrayView<ArrayRCP<zscalar_t > > data)
834 size_t dim = data.size();
835 for (
size_t i=0; i < dim; i++){
838 throw (std::bad_alloc());
839 data[i] = Teuchos::arcp(tmp, 0, length,
true);
842 zscalar_t scalingFactor = (max-min) / RAND_MAX;
844 for (
size_t i=0; i < dim; i++){
846 for (
zlno_t j=0; j < length; j++)
847 *x++ = min + (
zscalar_t(rand()) * scalingFactor);
853 string UserInputForTests::trim_right_copy(
855 const string& delimiters)
857 return s.substr( 0, s.find_last_not_of( delimiters ) + 1 );
860 string UserInputForTests::trim_left_copy(
862 const string& delimiters)
864 return s.substr( s.find_first_not_of( delimiters ) );
867 string UserInputForTests::trim_copy(
869 const string& delimiters)
871 return trim_left_copy( trim_right_copy( s, delimiters ), delimiters );
874 void UserInputForTests::readGeometricGenTestData(
string path,
878 std::ostringstream fname;
879 fname << path <<
"/" << testData <<
".txt";
882 if (verbose_ && tcomm_->getRank() == 0)
883 std::cout <<
"UserInputForTests, Read: " << fname.str() << std::endl;
885 Teuchos::ParameterList geoparams(
"geo params");
886 readGeoGenParams(fname.str(),geoparams);
891 int coord_dim = gg->getCoordinateDimension();
892 int numWeightsPerCoord = gg->getNumWeights();
893 zlno_t numLocalPoints = gg->getNumLocalCoords();
894 zgno_t numGlobalPoints = gg->getNumGlobalCoords();
898 for(
int i = 0; i < coord_dim; ++i){
899 coords[i] =
new zscalar_t[numLocalPoints];
903 gg->getLocalCoordinatesCopy(coords);
907 if (numWeightsPerCoord) {
909 weight =
new zscalar_t * [numWeightsPerCoord];
910 for(
int i = 0; i < numWeightsPerCoord; ++i){
911 weight[i] =
new zscalar_t[numLocalPoints];
915 gg->getLocalWeightsCopy(weight);
922 RCP<Tpetra::Map<zlno_t, zgno_t, znode_t> > mp =
923 rcp(
new Tpetra::Map<zlno_t, zgno_t, znode_t>(numGlobalPoints, numLocalPoints, 0, this->tcomm_));
926 Teuchos::Array<Teuchos::ArrayView<const zscalar_t> > coordView(coord_dim);
927 for (
int i=0; i < coord_dim; i++){
928 if(numLocalPoints > 0){
929 Teuchos::ArrayView<const zscalar_t> a(coords[i], numLocalPoints);
933 Teuchos::ArrayView<const zscalar_t> a;
939 xyz_ = RCP<tMVector_t>(
new 944 if (numWeightsPerCoord) {
946 Teuchos::Array<Teuchos::ArrayView<const zscalar_t> > weightView(numWeightsPerCoord);
947 for (
int i=0; i < numWeightsPerCoord; i++){
948 if(numLocalPoints > 0){
949 Teuchos::ArrayView<const zscalar_t> a(weight[i], numLocalPoints);
953 Teuchos::ArrayView<const zscalar_t> a;
958 vtxWeights_ = RCP<tMVector_t>(
new tMVector_t(mp, weightView.view(0, numWeightsPerCoord),
959 numWeightsPerCoord));
963 void UserInputForTests::readGeoGenParams(
string paramFileName,
964 ParameterList &geoparams){
968 std::string input =
"";
970 for(
int i = 0; i < 25000; ++i){
975 if(this->tcomm_->getRank() == 0){
977 fstream inParam(paramFileName.c_str());
984 std::string tmp =
"";
985 getline (inParam,tmp);
986 while (!inParam.eof()){
988 tmp = trim_copy(tmp);
993 getline (inParam,tmp);
996 for (
size_t i = 0; i < input.size(); ++i){
1004 int size = (int)input.size();
1008 this->tcomm_->broadcast(0,
sizeof(
int), (
char*) &size);
1010 throw "File " + paramFileName +
" cannot be opened.";
1012 this->tcomm_->broadcast(0, size, inp);
1013 istringstream inParam(inp);
1015 getline (inParam,str);
1016 while (!inParam.eof()){
1017 if(str[0] != param_comment){
1018 size_t pos = str.find(
'=');
1019 if(pos == string::npos){
1020 throw "Invalid Line:" + str +
" in parameter file";
1022 string paramname = trim_copy(str.substr(0,pos));
1023 string paramvalue = trim_copy(str.substr(pos + 1));
1024 geoparams.set(paramname, paramvalue);
1026 getline (inParam,str);
1030 void UserInputForTests::readMatrixMarketFile(
string path,
string testData,
bool distributeInput)
1032 std::ostringstream fname;
1033 fname << path <<
"/" << testData <<
".mtx";
1036 if (verbose_ && tcomm_->getRank() == 0)
1037 std::cout <<
"UserInputForTests, Read: " << fname.str() << std::endl;
1044 RCP<tcrsMatrix_t> toMatrix;
1045 RCP<tcrsMatrix_t> fromMatrix;
1048 fromMatrix = Tpetra::MatrixMarket::Reader<tcrsMatrix_t>::readSparseFile(
1049 fname.str(), tcomm_, dnode,
true,
true,
false);
1050 if(!distributeInput)
1052 if (verbose_ && tcomm_->getRank() == 0)
1053 std::cout <<
"Constructing serial distribution of matrix" << std::endl;
1055 RCP<const map_t> fromMap = fromMatrix->getRowMap();
1057 size_t numGlobalCoords = fromMap->getGlobalNumElements();
1058 size_t numLocalCoords = this->tcomm_->getRank() == 0 ? numGlobalCoords : 0;
1059 RCP<const map_t> toMap = rcp(
new map_t(numGlobalCoords,numLocalCoords, 0, tcomm_));
1061 RCP<import_t> importer = rcp(
new import_t(fromMap, toMap));
1063 toMatrix->doImport(*fromMatrix, *importer, Tpetra::INSERT);
1064 toMatrix->fillComplete();
1067 toMatrix = fromMatrix;
1069 }
catch (std::exception &e) {
1080 if (tcomm_->getRank() == 0)
1081 std::cout <<
"UserInputForTests unable to read matrix market file:" << fname.str() << std::endl;
1087 fname << path <<
"/" << testData <<
"_coord.mtx";
1089 size_t coordDim = 0, numGlobalCoords = 0;
1090 size_t msg[2]={0,0};
1091 ArrayRCP<ArrayRCP<zscalar_t> > xyz;
1092 std::ifstream coordFile;
1094 if (tcomm_->getRank() == 0){
1097 std::cout <<
"UserInputForTests, Read: " <<
1098 fname.str() << std::endl;
1102 coordFile.open(fname.str().c_str());
1104 catch (std::exception &e){
1115 while (!done && !fail && coordFile.good()){
1116 coordFile.getline(c, 256);
1119 else if (c[0] ==
'%')
1123 std::istringstream s(c);
1124 s >> numGlobalCoords >> coordDim;
1125 if (!s.eof() || numGlobalCoords < 1 || coordDim < 1)
1134 xyz = Teuchos::arcp(
new ArrayRCP<zscalar_t> [coordDim], 0, coordDim);
1136 for (
size_t dim=0; !fail && dim < coordDim; dim++){
1142 xyz[dim] = Teuchos::arcp(tmp, 0, numGlobalCoords);
1144 for (idx=0; !coordFile.eof() && idx < numGlobalCoords; idx++){
1145 coordFile.getline(c, 256);
1146 std::istringstream s(c);
1150 if (idx < numGlobalCoords)
1156 ArrayRCP<zscalar_t> emptyArray;
1157 for (
size_t dim=0; dim < coordDim; dim++)
1158 xyz[dim] = emptyArray;
1171 msg[1] = numGlobalCoords;
1175 Teuchos::broadcast<int, size_t>(*tcomm_, 0, 2, msg);
1178 numGlobalCoords = msg[1];
1184 RCP<const map_t> toMap;
1187 base = M_->getIndexBase();
1188 const RCP<const map_t> &mapM = M_->getRowMap();
1192 if (verbose_ && tcomm_->getRank() == 0)
1194 std::cout <<
"Matrix was null. ";
1195 std::cout <<
"Constructing distribution map for coordinate vector." << std::endl;
1199 if(!distributeInput)
1201 if (verbose_ && tcomm_->getRank() == 0)
1202 std::cout <<
"Constructing serial distribution map for coordinates." << std::endl;
1204 size_t numLocalCoords = this->tcomm_->getRank() == 0 ? numGlobalCoords : 0;
1205 toMap = rcp(
new map_t(numGlobalCoords,numLocalCoords, base, tcomm_));
1207 toMap = rcp(
new map_t(numGlobalCoords, base, tcomm_));
1215 ArrayRCP<ArrayView<const zscalar_t> > coordLists(coordDim);
1217 if (tcomm_->getRank() == 0){
1219 for (
size_t dim=0; dim < coordDim; dim++)
1220 coordLists[dim] = xyz[dim].view(0, numGlobalCoords);
1224 throw std::bad_alloc();
1226 ArrayRCP<const zgno_t> rowIds = Teuchos::arcp(tmp, 0, numGlobalCoords);
1228 zgno_t basePlusNumGlobalCoords = base +
static_cast<zgno_t>(numGlobalCoords);
1229 for (
zgno_t id=base;
id < basePlusNumGlobalCoords;
id++)
1232 RCP<const map_t> fromMap = rcp(
new map_t(numGlobalCoords,
1233 rowIds.view(0, numGlobalCoords), base, tcomm_));
1235 tMVector_t allCoords(fromMap, coordLists.view(0, coordDim), coordDim);
1239 xyz_->doExport(allCoords, exporter, Tpetra::INSERT);
1243 RCP<const map_t> fromMap = rcp(
new map_t(numGlobalCoords,
1244 ArrayView<zgno_t>(), base, tcomm_));
1246 tMVector_t allCoords(fromMap, coordLists.view(0, coordDim), coordDim);
1250 xyz_->doExport(allCoords, exporter, Tpetra::INSERT);
1254 void UserInputForTests::buildCrsMatrix(
int xdim,
int ydim,
int zdim,
1255 string problemType,
bool distributeInput)
1257 Teuchos::CommandLineProcessor tclp;
1258 Galeri::Xpetra::Parameters<zgno_t> params(tclp,
1259 xdim, ydim, zdim, problemType);
1261 RCP<const Tpetra::Map<zlno_t, zgno_t> > map;
1262 if (distributeInput)
1263 map = rcp(
new Tpetra::Map<zlno_t, zgno_t>(params.GetNumGlobalElements(),
1267 size_t nGlobalElements = params.GetNumGlobalElements();
1268 size_t nLocalElements = ((tcomm_->getRank() == 0) ? nGlobalElements : 0);
1269 map = rcp(
new Tpetra::Map<zlno_t, zgno_t>(nGlobalElements, nLocalElements, 0,
1273 if (verbose_ && tcomm_->getRank() == 0){
1275 std::cout <<
"Matrix is " << (distributeInput ?
"" :
"not");
1276 std::cout <<
"distributed." << endl;
1278 std::cout <<
"UserInputForTests, Create matrix with " << problemType;
1279 std::cout <<
" (and " << xdim;
1281 std::cout <<
" x " << ydim <<
" x " << zdim;
1283 std::cout <<
" x" << ydim <<
" x 1";
1285 std::cout <<
"x 1 x 1";
1287 std::cout <<
" mesh)" << std::endl;
1292 RCP<Galeri::Xpetra::Problem<Tpetra::Map<zlno_t, zgno_t>, Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t>, Tpetra::MultiVector<zscalar_t, zlno_t, zgno_t> > > Pr =
1293 Galeri::Xpetra::BuildProblem<zscalar_t, zlno_t, zgno_t, Tpetra::Map<zlno_t, zgno_t>, Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t>, Tpetra::MultiVector<zscalar_t, zlno_t, zgno_t> >
1294 (params.GetMatrixType(), map, params.GetParameterList());
1295 M_ = Pr->BuildMatrix();
1297 catch (std::exception &e) {
1305 if (verbose_ && tcomm_->getRank() == 0)
1307 "UserInputForTests, Implied matrix row coordinates computed" <<
1310 ArrayView<const zgno_t> gids = map->getNodeElementList();
1313 size_t pos = problemType.find(
"2D");
1314 if (pos != string::npos)
1316 else if (problemType ==
string(
"Laplace1D") ||
1317 problemType ==
string(
"Identity"))
1320 Array<ArrayRCP<zscalar_t> > coordinates(dim);
1323 for (
int i=0; i < dim; i++){
1326 throw(std::bad_alloc());
1327 coordinates[i] = Teuchos::arcp(c, 0, count,
true);
1331 zscalar_t *x = coordinates[0].getRawPtr();
1332 zscalar_t *y = coordinates[1].getRawPtr();
1333 zscalar_t *z = coordinates[2].getRawPtr();
1334 zgno_t xySize = xdim * ydim;
1335 for (
zlno_t i=0; i < count; i++){
1336 zgno_t iz = gids[i] / xySize;
1337 zgno_t xy = gids[i] - iz*xySize;
1344 zscalar_t *x = coordinates[0].getRawPtr();
1345 zscalar_t *y = coordinates[1].getRawPtr();
1346 for (
zlno_t i=0; i < count; i++){
1352 zscalar_t *x = coordinates[0].getRawPtr();
1353 for (
zlno_t i=0; i < count; i++)
1358 Array<ArrayView<const zscalar_t> > coordView(dim);
1360 for (
int i=0; i < dim; i++)
1361 coordView[i] = coordinates[i].view(0,count);
1363 xyz_ = rcp(
new tMVector_t(map, coordView.view(0, dim), dim));
1366 void UserInputForTests::readZoltanTestData(
string path,
string testData,
1367 bool distributeInput)
1370 int rank = tcomm_->getRank();
1371 FILE *graphFile = NULL;
1372 FILE *coordFile = NULL;
1377 std::ostringstream chGraphFileName;
1378 chGraphFileName << path <<
"/" << testData <<
".graph";
1381 std::ostringstream chCoordFileName;
1382 chCoordFileName << path <<
"/" << testData <<
".coords";
1385 graphFile = fopen(chGraphFileName.str().c_str(),
"r");
1389 chGraphFileName.str(
"");
1390 chCoordFileName.str(
"");
1392 chGraphFileName << path <<
"/ch_" << testData <<
"/" << testData <<
".graph";
1393 chCoordFileName << path <<
"/ch_" << testData <<
"/" << testData <<
".coords";
1396 graphFile = fopen(chGraphFileName.str().c_str(),
"r");
1399 memset(fileInfo, 0,
sizeof(
int) * 2);
1402 if (verbose_ && tcomm_->getRank() == 0)
1403 std::cout <<
"UserInputForTests, open " <<
1404 chGraphFileName.str () << std::endl;
1406 coordFile = fopen(chCoordFileName.str().c_str(),
"r");
1409 if (verbose_ && tcomm_->getRank() == 0)
1410 std::cout <<
"UserInputForTests, open " <<
1411 chCoordFileName.str () << std::endl;
1414 if (verbose_ && tcomm_->getRank() == 0){
1415 std::cout <<
"UserInputForTests, unable to open file: ";
1416 std::cout << chGraphFileName.str() << std::endl;
1422 Teuchos::broadcast<int, int>(*tcomm_, 0, 2, fileInfo);
1424 bool haveGraph = (fileInfo[0] == 1);
1425 bool haveCoords = (fileInfo[1] == 1);
1430 getUIChacoGraph(graphFile, testData, distributeInput);
1437 getUIChacoCoords(coordFile, testData);
1446 void UserInputForTests::getUIChacoGraph(FILE *fptr,
string fname,
1447 bool distributeInput)
1449 int rank = tcomm_->getRank();
1451 int nvtxs=0, nedges=0;
1452 int nVwgts=0, nEwgts=0;
1453 int *start = NULL, *adj = NULL;
1454 float *ewgts = NULL, *vwgts = NULL;
1455 size_t *nzPerRow = NULL;
1456 size_t maxRowLen = 0;
1458 ArrayRCP<const size_t> rowSizes;
1460 bool haveEdges =
true;
1464 memset(graphCounts, 0, 5*
sizeof(
int));
1469 char *nonConstName =
new char [fname.size() + 1];
1470 strcpy(nonConstName, fname.c_str());
1472 fail = chaco_input_graph(fptr, nonConstName,
1473 &start, &adj, &nvtxs, &nVwgts, &vwgts, &nEwgts, &ewgts);
1474 delete [] nonConstName;
1482 std::cout <<
"UserInputForTests, " << nvtxs <<
" vertices,";
1484 std::cout << start[nvtxs] <<
" edges,";
1486 std::cout <<
"no edges,";
1487 std::cout << nVwgts <<
" vertex weights, ";
1488 std::cout << nEwgts <<
" edge weights" << std::endl;
1495 Teuchos::broadcast<int, int>(*tcomm_, 0, 5, graphCounts);
1496 throw std::runtime_error(
"Unable to read chaco file");
1500 nedges = start[nvtxs];
1502 nzPerRow =
new size_t [nvtxs];
1504 throw std::bad_alloc();
1505 rowSizes = arcp(nzPerRow, 0, nvtxs,
true);
1508 for (
int i=0; i < nvtxs; i++){
1509 nzPerRow[i] = start[i+1] - start[i];
1510 if (nzPerRow[i] > maxRowLen)
1511 maxRowLen = nzPerRow[i];
1515 memset(nzPerRow, 0,
sizeof(
size_t) * nvtxs);
1526 int chbase = adj[0];
1527 for (
int i=1; i < nedges; i++)
1528 if (adj[i] < chbase)
1532 for (
int i=0; i < nedges; i++)
1537 graphCounts[0] = nvtxs;
1538 graphCounts[1] = nedges;
1539 graphCounts[2] = nVwgts;
1540 graphCounts[3] = nEwgts;
1541 graphCounts[4] = (int)maxRowLen;
1544 Teuchos::broadcast<int, int>(*tcomm_, 0, 5, graphCounts);
1546 if (graphCounts[0] == 0)
1547 throw std::runtime_error(
"Unable to read chaco file");
1549 haveEdges = (graphCounts[1] > 0);
1551 RCP<tcrsMatrix_t> fromMatrix;
1552 RCP<const map_t> fromMap;
1557 fromMap = rcp(
new map_t(nvtxs, nvtxs, base, tcomm_));
1560 rcp(
new tcrsMatrix_t(fromMap, rowSizes, Tpetra::StaticProfile));
1565 if (nedges && !edgeIds)
1566 throw std::bad_alloc();
1567 for (
int i=0; i < nedges; i++)
1568 edgeIds[i] = adj[i];
1573 zgno_t *nextId = edgeIds;
1574 Array<zscalar_t> values(maxRowLen, 1.0);
1576 for (
int i=0; i < nvtxs; i++){
1577 if (nzPerRow[i] > 0){
1578 ArrayView<const zgno_t> rowNz(nextId, nzPerRow[i]);
1579 fromMatrix->insertGlobalValues(i, rowNz, values.view(0,nzPerRow[i]));
1580 nextId += nzPerRow[i];
1588 fromMatrix->fillComplete();
1591 nvtxs = graphCounts[0];
1592 nedges = graphCounts[1];
1593 nVwgts = graphCounts[2];
1594 nEwgts = graphCounts[3];
1595 maxRowLen = graphCounts[4];
1599 fromMap = rcp(
new map_t(nvtxs, 0, base, tcomm_));
1602 rcp(
new tcrsMatrix_t(fromMap, rowSizes, Tpetra::StaticProfile));
1604 fromMatrix->fillComplete();
1608 RCP<const map_t> toMap;
1609 RCP<tcrsMatrix_t> toMatrix;
1610 RCP<import_t> importer;
1612 if (distributeInput) {
1614 toMap = rcp(
new map_t(nvtxs, base, tcomm_));
1618 importer = rcp(
new import_t(fromMap, toMap));
1619 toMatrix->doImport(*fromMatrix, *importer, Tpetra::INSERT);
1620 toMatrix->fillComplete();
1624 toMatrix = fromMatrix;
1631 typedef ArrayRCP<const ArrayView<const zscalar_t> > arrayArray_t;
1635 ArrayRCP<zscalar_t> weightBuf;
1636 ArrayView<const zscalar_t> *wgts =
new ArrayView<const zscalar_t> [nVwgts];
1639 size_t len = nVwgts * nvtxs;
1641 if (!buf)
throw std::bad_alloc();
1642 weightBuf = arcp(buf, 0, len,
true);
1644 for (
int widx=0; widx < nVwgts; widx++){
1645 wgts[widx] = ArrayView<const zscalar_t>(buf, nvtxs);
1646 float *vw = vwgts + widx;
1647 for (
int i=0; i < nvtxs; i++, vw += nVwgts)
1656 arrayArray_t vweights = arcp(wgts, 0, nVwgts,
true);
1658 RCP<tMVector_t> fromVertexWeights =
1659 rcp(
new tMVector_t(fromMap, vweights.view(0, nVwgts), nVwgts));
1661 RCP<tMVector_t> toVertexWeights;
1662 if (distributeInput) {
1663 toVertexWeights = rcp(
new tMVector_t(toMap, nVwgts));
1664 toVertexWeights->doImport(*fromVertexWeights, *importer, Tpetra::INSERT);
1667 toVertexWeights = fromVertexWeights;
1669 vtxWeights_ = toVertexWeights;
1674 if (haveEdges && nEwgts > 0){
1676 ArrayRCP<zscalar_t> weightBuf;
1677 ArrayView<const zscalar_t> *wgts =
new ArrayView<const zscalar_t> [nEwgts];
1679 toMap = rcp(
new map_t(nedges, M_->getNodeNumEntries(), base, tcomm_));
1682 size_t len = nEwgts * nedges;
1684 if (!buf)
throw std::bad_alloc();
1685 weightBuf = arcp(buf, 0, len,
true);
1687 for (
int widx=0; widx < nEwgts; widx++){
1688 wgts[widx] = ArrayView<const zscalar_t>(buf, nedges);
1689 float *ew = ewgts + widx;
1690 for (
int i=0; i < nedges; i++, ew += nEwgts)
1697 fromMap = rcp(
new map_t(nedges, nedges, base, tcomm_));
1700 fromMap = rcp(
new map_t(nedges, 0, base, tcomm_));
1703 arrayArray_t eweights = arcp(wgts, 0, nEwgts,
true);
1705 RCP<tMVector_t> fromEdgeWeights;
1706 RCP<tMVector_t> toEdgeWeights;
1707 RCP<import_t> edgeImporter;
1708 if (distributeInput) {
1710 rcp(
new tMVector_t(fromMap, eweights.view(0, nEwgts), nEwgts));
1711 toEdgeWeights = rcp(
new tMVector_t(toMap, nEwgts));
1712 edgeImporter = rcp(
new import_t(fromMap, toMap));
1713 toEdgeWeights->doImport(*fromEdgeWeights, *edgeImporter, Tpetra::INSERT);
1716 toEdgeWeights = fromEdgeWeights;
1718 edgWeights_ = toEdgeWeights;
1722 void UserInputForTests::getUIChacoCoords(FILE *fptr,
string fname)
1724 int rank = tcomm_->getRank();
1726 float *x=NULL, *y=NULL, *z=NULL;
1729 size_t localNumVtx = M_->getNodeNumRows();
1730 size_t globalNumVtx = M_->getGlobalNumRows();
1737 char *nonConstName =
new char [fname.size() + 1];
1738 strcpy(nonConstName, fname.c_str());
1739 fail = chaco_input_geom(fptr, nonConstName, (
int)globalNumVtx,
1741 delete [] nonConstName;
1747 std::cout <<
"UserInputForTests, read " << globalNumVtx;
1748 std::cout <<
" " << ndim <<
"-dimensional coordinates." << std::endl;
1752 Teuchos::broadcast<int, int>(*tcomm_, 0, 1, &ndim);
1755 throw std::runtime_error(
"Can't read coordinate file");
1757 ArrayRCP<ArrayRCP<const zscalar_t> > coords(ndim);
1762 for (
int dim=0; dim < ndim; dim++){
1765 throw std::bad_alloc();
1766 coords[dim] = arcp<const zscalar_t>(v, 0, globalNumVtx,
true);
1767 float *val = (dim==0 ? x : (dim==1 ? y : z));
1768 for (
size_t i=0; i < globalNumVtx; i++)
1774 len =
static_cast<zlno_t>(globalNumVtx);
1777 RCP<const map_t> fromMap = rcp(
new map_t(globalNumVtx, len, 0, tcomm_));
1778 RCP<const map_t> toMap = rcp(
new map_t(globalNumVtx, localNumVtx, 0, tcomm_));
1779 RCP<import_t> importer = rcp(
new import_t(fromMap, toMap));
1781 Array<ArrayView<const zscalar_t> > coordData;
1782 for (
int dim=0; dim < ndim; dim++)
1783 coordData.push_back(coords[dim].view(0, len));
1785 RCP<tMVector_t> fromCoords =
1786 rcp(
new tMVector_t(fromMap, coordData.view(0, ndim), ndim));
1788 RCP<tMVector_t> toCoords = rcp(
new tMVector_t(toMap, ndim));
1790 toCoords->doImport(*fromCoords, *importer, Tpetra::INSERT);
1799 double UserInputForTests::chaco_read_val(
1815 if (chaco_offset == 0 || chaco_offset >= chaco_break_pnt) {
1816 if (chaco_offset >= chaco_break_pnt) {
1817 length_left = CHACO_LINE_LENGTH - chaco_save_pnt - 1;
1819 ptr = &chaco_line[chaco_save_pnt];
1820 for (i=length_left; i; i--) *ptr2++ = *ptr++;
1821 length = chaco_save_pnt + 1;
1824 length = CHACO_LINE_LENGTH;
1829 ptr2 = fgets(&chaco_line[length_left], length, infile);
1831 if (ptr2 == (
char *) NULL) {
1833 return((
double) 0.0);
1836 if ((chaco_line[CHACO_LINE_LENGTH - 2] !=
'\n') && (chaco_line[CHACO_LINE_LENGTH - 2] !=
'\f')
1837 && (strlen(chaco_line) == CHACO_LINE_LENGTH - 1)){
1839 chaco_break_pnt = CHACO_LINE_LENGTH - 1;
1840 chaco_save_pnt = chaco_break_pnt;
1845 if (chaco_line[chaco_break_pnt] !=
'\0') {
1846 if (isspace((
int)(chaco_line[chaco_break_pnt]))) {
1848 chaco_save_pnt = chaco_break_pnt + 1;
1852 else if (white_seen) {
1859 chaco_break_pnt = CHACO_LINE_LENGTH;
1865 while (isspace((
int)(chaco_line[chaco_offset])) && chaco_offset < CHACO_LINE_LENGTH) chaco_offset++;
1866 if (chaco_line[chaco_offset] ==
'%' || chaco_line[chaco_offset] ==
'#') {
1868 if (chaco_break_pnt < CHACO_LINE_LENGTH) {
1869 chaco_flush_line(infile);
1871 return((
double) 0.0);
1874 ptr = &(chaco_line[chaco_offset]);
1875 val = strtod(ptr, &ptr2);
1880 return((
double) 0.0);
1883 chaco_offset = (int) (ptr2 - chaco_line) /
sizeof(char);
1890 int UserInputForTests::chaco_read_int(
1906 if (chaco_offset == 0 || chaco_offset >= chaco_break_pnt) {
1907 if (chaco_offset >= chaco_break_pnt) {
1908 length_left = CHACO_LINE_LENGTH - chaco_save_pnt - 1;
1910 ptr = &chaco_line[chaco_save_pnt];
1911 for (i=length_left; i; i--) *ptr2++ = *ptr++;
1912 length = chaco_save_pnt + 1;
1915 length = CHACO_LINE_LENGTH;
1920 ptr2 = fgets(&chaco_line[length_left], length, infile);
1922 if (ptr2 == (
char *) NULL) {
1927 if ((chaco_line[CHACO_LINE_LENGTH - 2] !=
'\n') && (chaco_line[CHACO_LINE_LENGTH - 2] !=
'\f')
1928 && (strlen(chaco_line) == CHACO_LINE_LENGTH - 1)){
1930 chaco_break_pnt = CHACO_LINE_LENGTH - 1;
1931 chaco_save_pnt = chaco_break_pnt;
1936 if (chaco_line[chaco_break_pnt] !=
'\0') {
1937 if (isspace((
int)(chaco_line[chaco_break_pnt]))) {
1939 chaco_save_pnt = chaco_break_pnt + 1;
1943 else if (white_seen) {
1950 chaco_break_pnt = CHACO_LINE_LENGTH;
1956 while (isspace((
int)(chaco_line[chaco_offset])) && chaco_offset < CHACO_LINE_LENGTH) chaco_offset++;
1957 if (chaco_line[chaco_offset] ==
'%' || chaco_line[chaco_offset] ==
'#') {
1959 if (chaco_break_pnt < CHACO_LINE_LENGTH) {
1960 chaco_flush_line(infile);
1965 ptr = &(chaco_line[chaco_offset]);
1966 val = (int) strtol(ptr, &ptr2, 10);
1974 chaco_offset = (int) (ptr2 - chaco_line) /
sizeof(char);
1980 void UserInputForTests::chaco_flush_line(
1987 while (c !=
'\n' && c !=
'\f')
1991 int UserInputForTests::chaco_input_graph(
2041 while (end_flag == 1) {
2042 *nvtxs = chaco_read_int(fin, &end_flag);
2046 printf(
"ERROR in graph file `%s':", inname);
2047 printf(
" Invalid number of vertices (%d).\n", *nvtxs);
2052 narcs = chaco_read_int(fin, &end_flag);
2054 printf(
"ERROR in graph file `%s':", inname);
2055 printf(
" Invalid number of expected edges (%d).\n", narcs);
2062 option = chaco_read_int(fin, &end_flag);
2064 using_ewgts = option - 10 * (option / 10);
2066 using_vwgts = option - 10 * (option / 10);
2068 vtxnums = option - 10 * (option / 10);
2071 (*nVwgts) = using_vwgts;
2072 (*nEwgts) = using_ewgts;
2075 if (!end_flag && using_vwgts==1){
2076 j = chaco_read_int(fin, &end_flag);
2077 if (!end_flag) (*nVwgts) = j;
2079 if (!end_flag && using_ewgts==1){
2080 j = chaco_read_int(fin, &end_flag);
2081 if (!end_flag) (*nEwgts) = j;
2086 j = chaco_read_int(fin, &end_flag);
2089 *start = (
int *) malloc((
unsigned) (*nvtxs + 1) *
sizeof(
int));
2091 *adjacency = (
int *) malloc((
unsigned) (2 * narcs + 1) *
sizeof(
int));
2096 *vweights = (
float *) malloc((
unsigned) (*nvtxs) * (*nVwgts) *
sizeof(float));
2101 *eweights = (
float *)
2102 malloc((
unsigned) (2 * narcs + 1) * (*nEwgts) *
sizeof(float));
2106 adjptr = *adjacency;
2115 while ((using_vwgts || vtxnums || narcs) && end_flag != -1) {
2120 j = chaco_read_int(fin, &end_flag);
2122 if (vertex == *nvtxs)
2124 printf(
"ERROR in graph file `%s':", inname);
2125 printf(
" no vertex number in line %d.\n", line_num);
2129 if (j != vertex && j != vertex + 1) {
2130 printf(
"ERROR in graph file `%s':", inname);
2131 printf(
" out-of-order vertex number in line %d.\n", line_num);
2145 if (vertex > *nvtxs)
2149 if (using_vwgts && new_vertex) {
2150 for (j=0; j<(*nVwgts); j++){
2151 weight = chaco_read_val(fin, &end_flag);
2153 printf(
"ERROR in graph file `%s':", inname);
2154 printf(
" not enough weights for vertex %d.\n", vertex);
2158 (*vweights)[(vertex-1)*(*nVwgts)+j] = weight;
2165 neighbor = chaco_read_int(fin, &end_flag);
2171 for (j=0; j<(*nEwgts); j++){
2172 eweight = chaco_read_val(fin, &end_flag);
2175 printf(
"ERROR in graph file `%s':", inname);
2176 printf(
" not enough weights for edge (%d,%d).\n", vertex, neighbor);
2189 if (++nedges > 2*narcs) {
2190 printf(
"ERROR in graph file `%s':", inname);
2191 printf(
" at least %d adjacencies entered, but nedges = %d\n",
2196 *adjptr++ = neighbor;
2201 neighbor = chaco_read_int(fin, &end_flag);
2205 (*start)[vertex] = sum_edges;
2210 while (!flag && end_flag != -1) {
2211 chaco_read_int(fin, &end_flag);
2216 (*start)[*nvtxs] = sum_edges;
2224 if (*adjacency != NULL)
2227 if (*eweights != NULL)
2236 if (*adjacency != NULL)
2238 if (*vweights != NULL)
2240 if (*eweights != NULL)
2248 return (error_flag);
2252 int UserInputForTests::chaco_input_geom(
2262 float xc, yc, zc =0;
2270 *x = *y = *z = NULL;
2273 while (end_flag == 1) {
2274 xc = chaco_read_val(fingeom, &end_flag);
2278 if (end_flag == -1) {
2279 printf(
"No values found in geometry file `%s'\n", geomname);
2285 yc = chaco_read_val(fingeom, &end_flag);
2286 if (end_flag == 0) {
2288 zc = chaco_read_val(fingeom, &end_flag);
2289 if (end_flag == 0) {
2291 chaco_read_val(fingeom, &end_flag);
2293 printf(
"Too many values on input line of geometry file `%s'\n",
2296 printf(
" Maximum dimensionality is 3\n");
2305 *x = (
float *) malloc((
unsigned) nvtxs *
sizeof(float));
2308 *y = (
float *) malloc((
unsigned) nvtxs *
sizeof(float));
2312 *z = (
float *) malloc((
unsigned) nvtxs *
sizeof(float));
2316 for (nread = 1; nread < nvtxs; nread++) {
2319 i = fscanf(fingeom,
"%f", &((*x)[nread]));
2321 else if (ndims == 2) {
2322 i = fscanf(fingeom,
"%f%f", &((*x)[nread]), &((*y)[nread]));
2324 else if (ndims == 3) {
2325 i = fscanf(fingeom,
"%f%f%f", &((*x)[nread]), &((*y)[nread]),
2330 printf(
"Too few lines of values in geometry file; nvtxs=%d, but only %d read\n",
2335 else if (i != ndims) {
2336 printf(
"Wrong number of values in line %d of geometry file `%s'\n",
2337 line_num, geomname);
2346 while (!flag && end_flag != -1) {
2347 chaco_read_val(fingeom, &end_flag);
2358 void UserInputForTests::readPamgenMeshFile(
string path,
string testData)
2360 int rank = this->tcomm_->getRank();
2361 if (verbose_ && tcomm_->getRank() == 0)
2362 std::cout <<
"UserInputForTestsBD::readPamgenFile, Read: " << testData << std::endl;
2369 std::ostringstream meshFileName;
2370 meshFileName << path <<
"/" << testData <<
".pmgen";
2373 file.open(meshFileName.str(), ios::in);
2377 if(verbose_ && tcomm_->getRank() == 0)
2379 std::cout <<
"Unable to open pamgen mesh: ";
2380 std::cout << meshFileName.str();
2381 std::cout <<
"\nPlease check file path and name." << std::endl;
2387 file.seekg (0,file.end);
2394 while(std::getline(file,line))
2396 if( line.find(
"nz") != std::string::npos ||
2397 line.find(
"nphi") != std::string::npos)
2405 file.seekg(0, ios::beg);
2410 this->tcomm_->broadcast(0,
sizeof(
int), (
char *)&dimension);
2411 this->tcomm_->broadcast(0,
sizeof(
size_t),(
char *)&len);
2412 this->tcomm_->barrier();
2415 if(verbose_ && tcomm_->getRank() == 0)
2416 std::cout <<
"Pamgen Mesh file size == 0, exiting UserInputForTests early." << endl;
2420 char * file_data =
new char[len];
2421 file_data[len] =
'\0';
2423 file.read(file_data,len);
2427 this->tcomm_->broadcast(0,(
int)len,file_data);
2428 this->tcomm_->barrier();
2433 this->havePamgenMesh =
true;
2434 pamgen_mesh->createMesh(file_data,dimension,this->tcomm_);
2437 pamgen_mesh->storeMesh();
2438 this->tcomm_->barrier();
2441 this->setPamgenCoordinateMV();
2444 this->setPamgenAdjacencyGraph();
2446 this->tcomm_->barrier();
2447 if(rank == 0) file.close();
2448 delete [] file_data;
2451 void UserInputForTests::setPamgenCoordinateMV()
2453 int dimension = pamgen_mesh->num_dim;
2457 zgno_t numelements = pamgen_mesh->num_elem;
2458 zgno_t numGlobalElements = pamgen_mesh->num_elems_global;
2461 for(
int i = 0; i < dimension; ++i){
2462 elem_coords[i] =
new zscalar_t[numelements];
2463 memcpy(elem_coords[i],&pamgen_mesh->element_coord[i*numelements],
sizeof(
double) * numelements);
2467 typedef Tpetra::Map<zlno_t, zgno_t, znode_t>
map_t;
2468 RCP<Tpetra::Map<zlno_t, zgno_t, znode_t> > mp;
2472 Array<zgno_t> elementList(numelements);
2473 for (Array<zgno_t>::size_type k = 0; k < numelements; ++k) {
2474 elementList[k] = pamgen_mesh->element_order_map[k];
2477 mp = rcp (
new map_t (numGlobalElements, elementList, 0, this->tcomm_));
2481 Teuchos::Array<Teuchos::ArrayView<const zscalar_t> > coordView(dimension);
2482 for (
int i = 0; i < dimension; i++){
2483 if(numelements > 0){
2484 Teuchos::ArrayView<const zscalar_t> a(elem_coords[i], numelements);
2488 Teuchos::ArrayView<const zscalar_t> a;
2494 xyz_ = RCP<tMVector_t>(
new 2500 void UserInputForTests::setPamgenAdjacencyGraph()
2508 typedef Tpetra::Map<zlno_t, zgno_t, znode_t>
map_t;
2511 size_t local_nodes = (size_t)this->pamgen_mesh->num_nodes;
2512 size_t local_els = (
size_t)this->pamgen_mesh->num_elem;
2514 size_t global_els = (size_t)this->pamgen_mesh->num_elems_global;
2515 size_t global_nodes = (
size_t)this->pamgen_mesh->num_nodes_global;
2519 RCP<const map_t> rowMap = rcp(
new map_t(global_els,0,this->tcomm_));
2520 RCP<const map_t> rangeMap = rowMap;
2523 RCP<const map_t> domainMap = rcp(
new map_t(global_nodes,0,this->tcomm_));
2526 Teuchos::RCP<tcrsMatrix_t> C = rcp(
new tcrsMatrix_t(rowMap,0));
2529 Array<zgno_t> g_el_ids(local_els);
2530 for (
size_t k = 0; k < local_els; ++k) {
2531 g_el_ids[k] = pamgen_mesh->global_element_numbers[k]-1;
2534 Array<zgno_t> g_node_ids(local_nodes);
2535 for (
size_t k = 0; k < local_nodes; ++k) {
2536 g_node_ids[k] = pamgen_mesh->global_node_numbers[k]-1;
2539 int blks = this->pamgen_mesh->num_elem_blk;
2545 for(
int i = 0; i < blks; i++)
2547 int el_per_block = this->pamgen_mesh->elements[i];
2548 int nodes_per_el = this->pamgen_mesh->nodes_per_element[i];
2549 int * connect = this->pamgen_mesh->elmt_node_linkage[i];
2551 for(
int j = 0; j < el_per_block; j++)
2553 const zgno_t gid =
static_cast<zgno_t>(g_el_ids[el_no]);
2554 for(
int k = 0; k < nodes_per_el; k++)
2556 int g_node_i = g_node_ids[connect[j*nodes_per_el+k]-1];
2557 C->insertGlobalValues(gid,
2558 Teuchos::tuple<zgno_t>(g_node_i),
2559 Teuchos::tuple<zscalar_t>(one));
2565 C->fillComplete(domainMap, rangeMap);
2571 Tpetra::MatrixMatrix::Multiply(*C,
false, *C,
true, *A);
2579 for(
zgno_t gid : rowMap->getNodeElementList())
2581 size_t numEntriesInRow = A->getNumEntriesInGlobalRow (gid);
2582 Array<zscalar_t> rowvals (numEntriesInRow);
2583 Array<zgno_t> rowinds (numEntriesInRow);
2586 Array<zscalar_t> mod_rowvals;
2587 Array<zgno_t> mod_rowinds;
2588 A->getGlobalRowCopy (gid, rowinds (), rowvals (), numEntriesInRow);
2589 for (
size_t i = 0; i < numEntriesInRow; i++) {
2592 if (rowvals[i] >= 1)
2594 mod_rowvals.push_back(one);
2595 mod_rowinds.push_back(rowinds[i]);
2598 this->M_->insertGlobalValues(gid, mod_rowinds, mod_rowvals);
2601 this->M_->fillComplete();
#define TEST_FAIL_AND_THROW(comm, ok, s)
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
string trim_right_copy(const string &s, const string &delimiters=" \f\n\r\t\v")
void readGeoGenParams(string paramFileName, Teuchos::ParameterList &geoparams, const RCP< const Teuchos::Comm< int > > &comm)
Traits of Xpetra classes, including migration method.
common code used by tests
#define HAVE_EPETRA_DATA_TYPES
static RCP< User > convertToXpetra(const RCP< User > &a)
Convert the object to its Xpetra wrapped version.
string trim_copy(const string &s, const string &delimiters=" \f\n\r\t\v")
string trim_left_copy(const string &s, const string &delimiters=" \f\n\r\t\v")