14#ifndef USERINPUTFORTESTS
15#define USERINPUTFORTESTS
17#include "Tpetra_Access.hpp"
22#include <Tpetra_MultiVector.hpp>
23#include <Tpetra_CrsMatrix.hpp>
24#include <Tpetra_Map.hpp>
25#include <Xpetra_Vector.hpp>
26#include <Xpetra_CrsMatrix.hpp>
27#include <Xpetra_CrsGraph.hpp>
29#include <MatrixMarket_Tpetra.hpp>
31#ifdef HAVE_ZOLTAN2_GALERI
32#include <Galeri_XpetraProblemFactory.hpp>
33#include <Galeri_XpetraParameters.hpp>
36#include <Tpetra_KokkosCompat_DefaultNode.hpp>
42#include <TpetraExt_MatrixMatrix_def.hpp>
49using Teuchos::ArrayRCP;
50using Teuchos::ArrayView;
55using Teuchos::rcp_const_cast;
56using Teuchos::ParameterList;
93 typedef Tpetra::Map<zlno_t, zgno_t, znode_t>
map_t;
94 typedef Tpetra::Export<zlno_t, zgno_t, znode_t>
export_t;
95 typedef Tpetra::Import<zlno_t, zgno_t, znode_t>
import_t;
119 const RCP<
const Comm<int> > &c,
bool debugInfo=
false,
120 bool distributeInput=
true);
139 const RCP<
const Comm<int> > &c,
bool debugInfo=
false,
140 bool distributeInput=
true);
158 const RCP<
const Comm<int> > &c);
187#ifdef HAVE_ZOLTAN2_PAMGEN
188 PamgenMesh * getPamGenMesh(){
return this->pamgen_mesh.operator->();}
223 const RCP<const Comm<int> > tcomm_;
226#ifdef HAVE_ZOLTAN2_PAMGEN
227 RCP<PamgenMesh> pamgen_mesh;
230 RCP<tcrsMatrix_t> M_;
231 RCP<xcrsMatrix_t> xM_;
233 RCP<tMVector_t> xyz_;
234 RCP<tMVector_t> vtxWeights_;
235 RCP<tMVector_t> edgWeights_;
242 void readMatrixMarketFile(
string path,
string testData,
bool distributeInput =
true);
248 bool distributeInput);
254 void readZoltanTestData(
string path,
string testData,
255 bool distributeInput);
258 RCP<tcrsMatrix_t> modifyMatrixGIDs(RCP<tcrsMatrix_t> &in);
259 inline zgno_t newID(
const zgno_t id) {
return id * 2 + 10001; }
262 void getUIChacoGraph(FILE *fptr,
bool haveAssign, FILE *assignFile,
263 string name,
bool distributeInput);
266 void getUIChacoCoords(FILE *fptr,
string name);
272 static const int CHACO_LINE_LENGTH=200;
273 char chaco_line[CHACO_LINE_LENGTH];
278 double chaco_read_val(FILE* infile,
int *end_flag);
279 int chaco_read_int(FILE* infile,
int *end_flag);
280 void chaco_flush_line(FILE*);
283 int chaco_input_graph(FILE *fin,
const char *inname,
int **start,
284 int **adjacency,
int *nvtxs,
int *nVwgts,
285 float **vweights,
int *nEwgts,
float **eweights);
288 int chaco_input_geom(FILE *fingeom,
const char *geomname,
int nvtxs,
289 int *igeom,
double **x,
double **y,
double **z);
292 int chaco_input_assign(FILE *finassign,
const char *assignname,
int nvtxs,
300 void readGeometricGenTestData(
string path,
string testData);
303 void readGeoGenParams(
string paramFileName,
304 ParameterList &geoparams);
308 static string trim_right_copy(
const string& s,
309 const string& delimiters =
" \f\n\r\t\v" );
311 static string trim_left_copy(
const string& s,
312 const string& delimiters =
" \f\n\r\t\v" );
314 static string trim_copy(
const string& s,
315 const string& delimiters =
" \f\n\r\t\v" );
319 void readPamgenMeshFile(
string path,
string testData);
320#ifdef HAVE_ZOLTAN2_PAMGEN
321 void setPamgenAdjacencyGraph();
322 void setPamgenCoordinateMV();
327 const RCP<
const Comm<int> > &c,
328 bool debugInfo,
bool distributeInput):
329verbose_(debugInfo), tcomm_(c), havePamgenMesh(false),
330M_(), xM_(), xyz_(), vtxWeights_(), edgWeights_(),
331chaco_offset(0), chaco_break_pnt(CHACO_LINE_LENGTH)
333 bool zoltan1 =
false;
334 string::size_type loc = path.find(
"/zoltan/test/");
335 if (loc != string::npos)
339 readZoltanTestData(path, testData, distributeInput);
341 readMatrixMarketFile(path, testData);
346 const RCP<
const Comm<int> > &c,
348 bool distributeInput):
349verbose_(debugInfo), tcomm_(c), havePamgenMesh(false),
350M_(), xM_(), xyz_(), vtxWeights_(), edgWeights_(),
351chaco_offset(0), chaco_break_pnt(CHACO_LINE_LENGTH)
353 if (matrixType.size() == 0){
359 matrixType = string(
"Laplace1D");
361 matrixType = string(
"Laplace2D");
363 matrixType = string(
"Laplace3D");
365 throw std::runtime_error(
"input");
367 if (verbose_ && tcomm_->getRank() == 0)
368 std::cout <<
"UserInputForTests, Matrix type : " << matrixType << std::endl;
371 buildCrsMatrix(x, y, z, matrixType, distributeInput);
375 const RCP<
const Comm<int> > &c):
376tcomm_(c), havePamgenMesh(false),
377M_(), xM_(), xyz_(), vtxWeights_(), edgWeights_(),
378chaco_offset(0), chaco_break_pnt(CHACO_LINE_LENGTH)
382 bool distributeInput =
true, debugInfo =
true;
384 if(pList.isParameter(
"distribute input"))
385 distributeInput = pList.get<
bool>(
"distribute input");
387 if(pList.isParameter(
"debug"))
388 debugInfo = pList.get<
bool>(
"debug");
389 this->verbose_ = debugInfo;
391 if(pList.isParameter(
"input file"))
396 if(pList.isParameter(
"input path"))
397 path = pList.get<string>(
"input path");
399 string testData = pList.get<string>(
"input file");
402 USERINPUT_FILE_FORMATS file_format = MATRIX_MARKET;
405 if(pList.isParameter(
"file type") && pList.get<string>(
"file type") ==
"Geometric Generator")
406 file_format = GEOMGEN;
407 else if(pList.isParameter(
"file type") && pList.get<string>(
"file type") ==
"Pamgen")
409 file_format = PAMGEN;
411 else if(pList.isParameter(
"file type") && pList.get<
string>(
"file type") ==
"Chaco")
415 switch (file_format) {
416 case GEOMGEN: readGeometricGenTestData(path,testData);
break;
417 case PAMGEN: readPamgenMeshFile(path,testData);
break;
418 case CHACO: readZoltanTestData(path, testData, distributeInput);
break;
419 default: readMatrixMarketFile(path, testData, distributeInput);
break;
422 }
else if(pList.isParameter(
"x") || pList.isParameter(
"y") || pList.isParameter(
"z")){
426 if(pList.isParameter(
"x")) x = pList.get<int>(
"x");
427 if(pList.isParameter(
"y")) y = pList.get<int>(
"y");
428 if(pList.isParameter(
"z")) z = pList.get<int>(
"z");
430 string problemType =
"";
431 if(pList.isParameter(
"equation type")) problemType = pList.get<string>(
"equation type");
433 if (problemType.size() == 0){
439 problemType = string(
"Laplace1D");
441 problemType = string(
"Laplace2D");
443 problemType = string(
"Laplace3D");
445 throw std::runtime_error(
"input");
447 if (verbose_ && tcomm_->getRank() == 0)
448 std::cout <<
"UserInputForTests, Matrix type : " << problemType << std::endl;
455 std::cerr <<
"Input file block undefined!" << std::endl;
464 throw std::runtime_error(
"could not read coord file");
481 throw std::runtime_error(
"could not read mtx file");
488 throw std::runtime_error(
"could not read mtx file");
489 return rcp_const_cast<tcrsGraph_t>(M_->getCrsGraph());
494 RCP<tVector_t> V = rcp(
new tVector_t(M_->getRowMap(), 1));
502 RCP<tMVector_t> mV = rcp(
new tMVector_t(M_->getRowMap(), nvec));
511 throw std::runtime_error(
"could not read mtx file");
518 throw std::runtime_error(
"could not read mtx file");
519 return rcp_const_cast<xcrsGraph_t>(xM_->getCrsGraph());
544 if(input_type ==
"coordinates")
546 else if(input_type ==
"tpetra_vector")
548 else if(input_type ==
"tpetra_multivector")
550 else if(input_type ==
"tpetra_crs_graph")
552 else if(input_type ==
"tpetra_crs_matrix")
554 else if(input_type ==
"xpetra_vector")
556 else if(input_type ==
"xpetra_multivector")
558 else if(input_type ==
"xpetra_crs_graph")
560 else if(input_type ==
"xpetra_crs_matrix")
568 return xyz_.is_null() ? false :
true;
573 return vtxWeights_.is_null() ? false :
true;
578 return edgWeights_.is_null() ? false :
true;
583 return M_.is_null() ? false :
true;
588 return M_.is_null() ? false :
true;
603 return M_.is_null() ? false :
true;
608 return M_.is_null() ? false :
true;
623 return this->havePamgenMesh;
628 ArrayView<ArrayRCP<zscalar_t > > data)
633 size_t dim = data.size();
634 for (
size_t i=0; i < dim; i++){
637 throw (std::bad_alloc());
638 data[i] = Teuchos::arcp(tmp, 0, length,
true);
641 zscalar_t scalingFactor = (max-min) / RAND_MAX;
643 for (
size_t i=0; i < dim; i++){
645 for (
zlno_t j=0; j < length; j++)
646 *x++ = min + (
zscalar_t(rand()) * scalingFactor);
652string UserInputForTests::trim_right_copy(
654 const string& delimiters)
656 return s.substr( 0, s.find_last_not_of( delimiters ) + 1 );
659string UserInputForTests::trim_left_copy(
661 const string& delimiters)
663 return s.substr( s.find_first_not_of( delimiters ) );
666string UserInputForTests::trim_copy(
668 const string& delimiters)
670 return trim_left_copy( trim_right_copy( s, delimiters ), delimiters );
673void UserInputForTests::readGeometricGenTestData(
string path,
677 std::ostringstream
fname;
678 fname << path <<
"/" << testData <<
".txt";
680 if (verbose_ && tcomm_->getRank() == 0)
681 std::cout <<
"UserInputForTests, Read: " <<
fname.str() << std::endl;
683 Teuchos::ParameterList geoparams(
"geo params");
684 readGeoGenParams(
fname.str(),geoparams);
696 for(
int i = 0; i < coord_dim; ++i){
697 coords[i] =
new zscalar_t[numLocalPoints];
705 if (numWeightsPerCoord) {
707 weight =
new zscalar_t * [numWeightsPerCoord];
708 for(
int i = 0; i < numWeightsPerCoord; ++i){
709 weight[i] =
new zscalar_t[numLocalPoints];
720 RCP<Tpetra::Map<zlno_t, zgno_t, znode_t> > mp =
721 rcp(
new Tpetra::Map<zlno_t, zgno_t, znode_t>(numGlobalPoints, numLocalPoints, 0, this->tcomm_));
724 Teuchos::Array<Teuchos::ArrayView<const zscalar_t> > coordView(coord_dim);
725 for (
int i=0; i < coord_dim; i++){
726 if(numLocalPoints > 0){
727 Teuchos::ArrayView<const zscalar_t> a(coords[i], numLocalPoints);
731 Teuchos::ArrayView<const zscalar_t> a;
737 xyz_ = RCP<tMVector_t>(
new
742 if (numWeightsPerCoord) {
744 Teuchos::Array<Teuchos::ArrayView<const zscalar_t> > weightView(numWeightsPerCoord);
745 for (
int i=0; i < numWeightsPerCoord; i++){
746 if(numLocalPoints > 0){
747 Teuchos::ArrayView<const zscalar_t> a(weight[i], numLocalPoints);
751 Teuchos::ArrayView<const zscalar_t> a;
756 vtxWeights_ = RCP<tMVector_t>(
new tMVector_t(mp, weightView.view(0, numWeightsPerCoord),
757 numWeightsPerCoord));
758 for(
int i = 0; i < coord_dim; ++i)
delete [] coords[i];
760 if(numWeightsPerCoord) {
761 for(
int i = 0; i < numWeightsPerCoord; ++i)
delete [] weight[i];
767void UserInputForTests::readGeoGenParams(
string paramFileName,
768 ParameterList &geoparams){
772 std::string input =
"";
774 for(
int i = 0; i < 25000; ++i){
779 if(this->tcomm_->getRank() == 0){
781 std::fstream inParam(paramFileName.c_str());
788 std::string tmp =
"";
789 getline (inParam,tmp);
790 while (!inParam.eof()){
792 tmp = trim_copy(tmp);
797 getline (inParam,tmp);
800 for (
size_t i = 0; i < input.size(); ++i){
808 int size = (int)input.size();
812 this->tcomm_->broadcast(0,
sizeof(
int), (
char*) &size);
814 throw "File " + paramFileName +
" cannot be opened.";
816 this->tcomm_->broadcast(0, size, inp);
817 std::istringstream inParam(inp);
819 getline (inParam,str);
820 while (!inParam.eof()){
822 size_t pos = str.find(
'=');
823 if(pos == string::npos){
824 throw "Invalid Line:" + str +
" in parameter file";
826 string paramname = trim_copy(str.substr(0,pos));
827 string paramvalue = trim_copy(str.substr(pos + 1));
828 geoparams.set(paramname, paramvalue);
830 getline (inParam,str);
835RCP<tcrsMatrix_t> UserInputForTests::modifyMatrixGIDs(
836 RCP<tcrsMatrix_t> &inMatrix
845 RCP<const map_t> inMap = inMatrix->getRowMap();
847 size_t nRows = inMap->getLocalNumElements();
848 auto inRows = inMap->getMyGlobalIndices();
849 Teuchos::Array<zgno_t> outRows(nRows);
850 for (
size_t i = 0; i < nRows; i++) {
851 outRows[i] = newID(inRows[i]);
854 Tpetra::global_size_t nGlobalRows = inMap->getGlobalNumElements();
855 RCP<map_t> outMap = rcp(
new map_t(nGlobalRows, outRows(), 0,
858#ifdef INCLUDE_LENGTHY_OUTPUT
861 std::cout << inMap->getComm()->getRank() <<
" KDDKDD "
862 <<
"nGlobal " << inMap->getGlobalNumElements() <<
" "
863 << outMap->getGlobalNumElements() <<
"; "
864 <<
"nLocal " << inMap->getLocalNumElements() <<
" "
865 << outMap->getLocalNumElements() <<
"; "
867 std::cout << inMap->getComm()->getRank() <<
" KDDKDD ";
868 for (
size_t i = 0; i < nRows; i++)
869 std::cout <<
"(" << inMap->getMyGlobalIndices()[i] <<
", "
870 << outMap->getMyGlobalIndices()[i] <<
") ";
871 std::cout << std::endl;
877 size_t rowLen = inMatrix->getLocalMaxNumRowEntries();
878 RCP<tcrsMatrix_t> outMatrix = rcp(
new tcrsMatrix_t(outMap, rowLen));
880 typename tcrsMatrix_t::nonconst_global_inds_host_view_type indices(
"Indices", rowLen);
881 typename tcrsMatrix_t::nonconst_values_host_view_type values(
"Values", rowLen);
883 for (
size_t i = 0; i < nRows; i++) {
885 zgno_t inGid = inMap->getGlobalElement(i);
886 inMatrix->getGlobalRowCopy(inGid, indices, values, nEntries);
887 for (
size_t j = 0; j < nEntries; j++)
888 indices[j] = newID(indices[j]);
890 zgno_t outGid = outMap->getGlobalElement(i);
891 ArrayView<zgno_t> Indices(indices.data(), nEntries);
892 ArrayView<zscalar_t> Values(values.data(), nEntries);
893 outMatrix->insertGlobalValues(outGid, Indices(0, nEntries),
894 Values(0, nEntries));
896 outMatrix->fillComplete();
898#ifdef INCLUDE_LENGTHY_OUTPUT
901 std::cout << inMap->getComm()->getRank() <<
" KDDKDD Rows "
902 <<
"nGlobal " << inMatrix->getGlobalNumRows() <<
" "
903 << outMatrix->getGlobalNumRows() <<
"; "
904 <<
"nLocal " << inMatrix->getLocalNumRows() <<
" "
905 << outMatrix->getLocalNumRows() << std::endl;
906 std::cout << inMap->getComm()->getRank() <<
" KDDKDD NNZS "
907 <<
"nGlobal " << inMatrix->getGlobalNumEntries() <<
" "
908 << outMatrix->getGlobalNumEntries() <<
"; "
909 <<
"nLocal " << inMatrix->getLocalNumEntries() <<
" "
910 << outMatrix->getLocalNumEntries() << std::endl;
913 Teuchos::Array<zgno_t> in(rowLen), out(rowLen);
914 Teuchos::Array<zscalar_t> inval(rowLen), outval(rowLen);
916 for (
size_t i = 0; i < nRows; i++) {
917 std::cout << inMap->getComm()->getRank() <<
" KDDKDD " << i <<
" nnz(";
918 inMatrix->getGlobalRowCopy(inMap->getGlobalElement(i), in, inval, nIn);
919 outMatrix->getGlobalRowCopy(outMap->getGlobalElement(i), out, outval,
922 std::cout << nIn <<
", " << nOut <<
"): ";
923 for (
size_t j = 0; j < nIn; j++) {
924 std::cout <<
"(" << in[j] <<
" " << inval[j] <<
", "
925 << out[j] <<
" " << outval[j] <<
") ";
927 std::cout << std::endl;
937void UserInputForTests::readMatrixMarketFile(
943 std::ostringstream
fname;
944 fname << path <<
"/" << testData <<
".mtx";
946 if (verbose_ && tcomm_->getRank() == 0)
947 std::cout <<
"UserInputForTests, Read: " <<
fname.str() << std::endl;
952 RCP<tcrsMatrix_t> toMatrix;
953 RCP<tcrsMatrix_t> fromMatrix;
956 typedef Tpetra::MatrixMarket::Reader<tcrsMatrix_t> reader_type;
957 fromMatrix = reader_type::readSparseFile(
fname.str(), tcomm_,
959#ifdef KDD_NOT_READY_YET
962 fromMatrix = modifyMatrixGIDs(fromMatrix);
967 if (verbose_ && tcomm_->getRank() == 0)
968 std::cout <<
"Constructing serial distribution of matrix" << std::endl;
970 RCP<const map_t> fromMap = fromMatrix->getRowMap();
972 size_t numGlobalCoords = fromMap->getGlobalNumElements();
973 size_t numLocalCoords = this->tcomm_->getRank() == 0 ? numGlobalCoords : 0;
974 RCP<const map_t> toMap = rcp(
new map_t(numGlobalCoords,numLocalCoords, 0, tcomm_));
976 RCP<import_t> importer = rcp(
new import_t(fromMap, toMap));
978 toMatrix->doImport(*fromMatrix, *importer, Tpetra::INSERT);
979 toMatrix->fillComplete();
982 toMatrix = fromMatrix;
984 }
catch (std::exception &e) {
985 if (tcomm_->getRank() == 0) {
986 std::cout <<
"UserInputForTests unable to read matrix market file:"
987 <<
fname.str() << std::endl;
988 std::cout << e.what() << std::endl;
993 "UserInputForTests unable to read matrix market file");
996#ifdef INCLUDE_LENGTHY_OUTPUT
997 std::cout << tcomm_->getRank() <<
" KDDKDD " << M_->getLocalNumRows()
998 <<
" " << M_->getGlobalNumRows()
999 <<
" " << M_->getLocalNumEntries()
1000 <<
" " << M_->getGlobalNumEntries() << std::endl;
1008 fname << path <<
"/" << testData <<
"_coord.mtx";
1010 size_t coordDim = 0, numGlobalCoords = 0;
1011 size_t msg[2]={0,0};
1012 ArrayRCP<ArrayRCP<zscalar_t> > xyz;
1013 std::ifstream coordFile;
1015 if (tcomm_->getRank() == 0){
1018 std::cout <<
"UserInputForTests, Read: " <<
1019 fname.str() << std::endl;
1023 coordFile.open(
fname.str().c_str());
1025 catch (std::exception &){
1036 while (!done && !
fail && coordFile.good()){
1037 coordFile.getline(c, 256);
1040 else if (c[0] ==
'%')
1044 std::istringstream s(c);
1045 s >> numGlobalCoords >> coordDim;
1046 if (!s.eof() || numGlobalCoords < 1 || coordDim < 1)
1055 xyz = Teuchos::arcp(
new ArrayRCP<zscalar_t> [coordDim], 0, coordDim);
1057 for (
size_t dim=0; !
fail && dim < coordDim; dim++){
1063 xyz[dim] = Teuchos::arcp(tmp, 0, numGlobalCoords);
1065 for (idx=0; !coordFile.eof() && idx < numGlobalCoords; idx++){
1066 coordFile.getline(c, 256);
1067 std::istringstream s(c);
1071 if (idx < numGlobalCoords)
1077 ArrayRCP<zscalar_t> emptyArray;
1078 for (
size_t dim=0; dim < coordDim; dim++)
1079 xyz[dim] = emptyArray;
1092 msg[1] = numGlobalCoords;
1096 Teuchos::broadcast<int, size_t>(*tcomm_, 0, 2, msg);
1099 numGlobalCoords = msg[1];
1105 RCP<const map_t> toMap;
1108 const RCP<const map_t> &mapM = M_->getRowMap();
1112 if (verbose_ && tcomm_->getRank() == 0)
1114 std::cout <<
"Matrix was null. ";
1115 std::cout <<
"Constructing distribution map for coordinate vector."
1119 if(!distributeInput)
1121 if (verbose_ && tcomm_->getRank() == 0)
1122 std::cout <<
"Constructing serial distribution map for coordinates."
1125 size_t numLocalCoords = this->tcomm_->getRank()==0 ? numGlobalCoords : 0;
1126 toMap = rcp(
new map_t(numGlobalCoords,numLocalCoords, base, tcomm_));
1128 toMap = rcp(
new map_t(numGlobalCoords, base, tcomm_));
1136 ArrayRCP<ArrayView<const zscalar_t> > coordLists(coordDim);
1138 if (tcomm_->getRank() == 0){
1140 for (
size_t dim=0; dim < coordDim; dim++)
1141 coordLists[dim] = xyz[dim].view(0, numGlobalCoords);
1145 throw std::bad_alloc();
1147 ArrayRCP<const zgno_t> rowIds = Teuchos::arcp(tmp, 0, numGlobalCoords);
1149#ifdef KDD_NOT_READY_YET
1158 RCP<const map_t> fromMap = rcp(
new map_t(numGlobalCoords,
1159 rowIds.view(0, numGlobalCoords),
1162 tMVector_t allCoords(fromMap, coordLists.view(0, coordDim), coordDim);
1166 xyz_->doExport(allCoords, exporter, Tpetra::INSERT);
1170 RCP<const map_t> fromMap = rcp(
new map_t(numGlobalCoords,
1171 ArrayView<zgno_t>(), base, tcomm_));
1173 tMVector_t allCoords(fromMap, coordLists.view(0, coordDim), coordDim);
1177 xyz_->doExport(allCoords, exporter, Tpetra::INSERT);
1181void UserInputForTests::buildCrsMatrix(
int xdim,
int ydim,
int zdim,
1182 string problemType,
bool distributeInput)
1184#ifdef HAVE_ZOLTAN2_GALERI
1185 Teuchos::CommandLineProcessor tclp;
1186 Galeri::Xpetra::Parameters<zgno_t> params(tclp,
1187 xdim, ydim, zdim, problemType);
1189 RCP<const Tpetra::Map<zlno_t, zgno_t> > map;
1190 if (distributeInput)
1191 map = rcp(
new Tpetra::Map<zlno_t, zgno_t>(params.GetNumGlobalElements(),
1195 size_t nGlobalElements = params.GetNumGlobalElements();
1196 size_t nLocalElements = ((tcomm_->getRank() == 0) ? nGlobalElements : 0);
1197 map = rcp(
new Tpetra::Map<zlno_t, zgno_t>(nGlobalElements, nLocalElements, 0,
1201 if (verbose_ && tcomm_->getRank() == 0){
1203 std::cout <<
"Matrix is " << (distributeInput ?
"" :
"not");
1204 std::cout <<
"distributed." << std::endl;
1206 std::cout <<
"UserInputForTests, Create matrix with " << problemType;
1207 std::cout <<
" (and " << xdim;
1209 std::cout <<
" x " << ydim <<
" x " << zdim;
1211 std::cout <<
" x" << ydim <<
" x 1";
1213 std::cout <<
"x 1 x 1";
1215 std::cout <<
" mesh)" << std::endl;
1221 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 =
1222 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> >
1223 (params.GetMatrixType(), map, params.GetParameterList());
1224 M_ = Pr->BuildMatrix();
1226 catch (std::exception &) {
1230 "UserInputForTests Galeri::Xpetra::BuildProblem failed");
1236 if (verbose_ && tcomm_->getRank() == 0)
1238 "UserInputForTests, Implied matrix row coordinates computed" <<
1241 ArrayView<const zgno_t> gids = map->getLocalElementList();
1244 size_t pos = problemType.find(
"2D");
1245 if (pos != string::npos)
1247 else if (problemType ==
string(
"Laplace1D") ||
1248 problemType ==
string(
"Identity"))
1254 for (
int i=0; i < dim; i++){
1257 throw(std::bad_alloc());
1258 coordinates[i] = Teuchos::arcp(c, 0, count,
true);
1265 zgno_t xySize = xdim * ydim;
1266 for (
zlno_t i=0; i < count; i++){
1267 zgno_t iz = gids[i] / xySize;
1268 zgno_t xy = gids[i] - iz*xySize;
1277 for (
zlno_t i=0; i < count; i++){
1284 for (
zlno_t i=0; i < count; i++)
1289 Array<ArrayView<const zscalar_t> > coordView(dim);
1291 for (
int i=0; i < dim; i++)
1294 xyz_ = rcp(
new tMVector_t(map, coordView.view(0, dim), dim));
1296 throw std::runtime_error(
"Galeri input requested but Trilinos is "
1297 "not built with Galeri.");
1301void UserInputForTests::readZoltanTestData(
string path,
string testData,
1302 bool distributeInput)
1304 int rank = tcomm_->getRank();
1305 FILE *graphFile = NULL;
1306 FILE *coordFile = NULL;
1307 FILE *assignFile = NULL;
1310 for (
int i = 0; i < CHACO_LINE_LENGTH; i++) chaco_line[i] =
'\0';
1314 std::ostringstream chGraphFileName;
1315 chGraphFileName << path <<
"/" << testData <<
".graph";
1318 std::ostringstream chCoordFileName;
1319 chCoordFileName << path <<
"/" << testData <<
".coords";
1322 std::ostringstream chAssignFileName;
1323 chAssignFileName << path <<
"/" << testData <<
".assign";
1326 graphFile = fopen(chGraphFileName.str().c_str(),
"r");
1330 chGraphFileName.str(
"");
1331 chCoordFileName.str(
"");
1333 chGraphFileName << path <<
"/ch_" << testData <<
"/" << testData <<
".graph";
1334 chCoordFileName << path <<
"/ch_" << testData <<
"/" << testData <<
".coords";
1335 chAssignFileName << path <<
"/ch_" << testData <<
"/" << testData <<
".assign";
1338 graphFile = fopen(chGraphFileName.str().c_str(),
"r");
1341 memset(fileInfo, 0,
sizeof(
int) * 3);
1344 if (verbose_ && tcomm_->getRank() == 0)
1345 std::cout <<
"UserInputForTests, open " <<
1346 chGraphFileName.str () << std::endl;
1348 coordFile = fopen(chCoordFileName.str().c_str(),
"r");
1351 if (verbose_ && tcomm_->getRank() == 0)
1352 std::cout <<
"UserInputForTests, open " <<
1353 chCoordFileName.str () << std::endl;
1356 assignFile = fopen(chAssignFileName.str().c_str(),
"r");
1359 if (verbose_ && tcomm_->getRank() == 0)
1360 std::cout <<
"UserInputForTests, open " <<
1361 chAssignFileName.str () << std::endl;
1364 if (verbose_ && tcomm_->getRank() == 0){
1365 std::cout <<
"UserInputForTests, unable to open file: ";
1366 std::cout << chGraphFileName.str() << std::endl;
1372 Teuchos::broadcast<int, int>(*tcomm_, 0, 3, fileInfo);
1374 bool haveGraph = (fileInfo[0] == 1);
1375 bool haveCoords = (fileInfo[1] == 1);
1376 bool haveAssign = (fileInfo[2] == 1);
1381 getUIChacoGraph(graphFile, haveAssign, assignFile,
1382 testData, distributeInput);
1389 getUIChacoCoords(coordFile, testData);
1398void UserInputForTests::getUIChacoGraph(FILE *fptr,
bool haveAssign,
1399 FILE *assignFile,
string fname,
1400 bool distributeInput)
1402 int rank = tcomm_->getRank();
1404 int nvtxs=0, nedges=0;
1405 int nVwgts=0, nEwgts=0;
1406 int *start = NULL, *adj = NULL;
1407 float *ewgts = NULL, *vwgts = NULL;
1408 size_t *nzPerRow = NULL;
1409 size_t maxRowLen = 0;
1411 ArrayRCP<const size_t> rowSizes;
1413 bool haveEdges =
true;
1417 memset(graphCounts, 0, 5*
sizeof(
int));
1420 fail = chaco_input_graph(fptr,
fname.c_str(), &start, &adj,
1421 &nvtxs, &nVwgts, &vwgts, &nEwgts, &ewgts);
1432 std::cout <<
"UserInputForTests, " << nvtxs <<
" vertices,";
1434 std::cout << start[nvtxs] <<
" edges,";
1436 std::cout <<
"no edges,";
1437 std::cout << nVwgts <<
" vertex weights, ";
1438 std::cout << nEwgts <<
" edge weights" << std::endl;
1445 Teuchos::broadcast<int, int>(*tcomm_, 0, 5, graphCounts);
1446 throw std::runtime_error(
"Unable to read chaco file");
1450 nedges = start[nvtxs];
1452 nzPerRow =
new size_t [nvtxs];
1454 throw std::bad_alloc();
1455 rowSizes = arcp(nzPerRow, 0, nvtxs,
true);
1458 for (
int i=0; i < nvtxs; i++){
1459 nzPerRow[i] = start[i+1] - start[i];
1460 if (nzPerRow[i] > maxRowLen)
1461 maxRowLen = nzPerRow[i];
1465 memset(nzPerRow, 0,
sizeof(
size_t) * nvtxs);
1472 for (
int i=0; i < nedges; i++)
1476 graphCounts[0] = nvtxs;
1477 graphCounts[1] = nedges;
1478 graphCounts[2] = nVwgts;
1479 graphCounts[3] = nEwgts;
1480 graphCounts[4] = (int)maxRowLen;
1483 Teuchos::broadcast<int, int>(*tcomm_, 0, 5, graphCounts);
1485 if (graphCounts[0] == 0)
1486 throw std::runtime_error(
"Unable to read chaco file");
1488 haveEdges = (graphCounts[1] > 0);
1490 RCP<tcrsMatrix_t> fromMatrix;
1491 RCP<const map_t> fromMap;
1495 fromMap = rcp(
new map_t(nvtxs, nvtxs, base, tcomm_));
1503 if (nedges && !edgeIds)
1504 throw std::bad_alloc();
1505 for (
int i=0; i < nedges; i++)
1506 edgeIds[i] = adj[i];
1511 zgno_t *nextId = edgeIds;
1512 Array<zscalar_t> values(nedges, 1.0);
1513 if (nedges > 0 && nEwgts > 0) {
1514 for (
int i=0; i < nedges; i++)
1515 values[i] = ewgts[i];
1520 for (
int i=0; i < nvtxs; i++){
1521 if (nzPerRow[i] > 0){
1522 ArrayView<const zgno_t> rowNz(nextId, nzPerRow[i]);
1523 fromMatrix->insertGlobalValues(i, rowNz, values.view(start[i], start[i+1] - start[i]));
1524 nextId += nzPerRow[i];
1532 fromMatrix->fillComplete();
1535 nvtxs = graphCounts[0];
1536 nedges = graphCounts[1];
1537 nVwgts = graphCounts[2];
1538 nEwgts = graphCounts[3];
1539 maxRowLen = graphCounts[4];
1543 fromMap = rcp(
new map_t(nvtxs, 0, base, tcomm_));
1548 fromMatrix->fillComplete();
1553 size_t sz = fromMatrix->getLocalMaxNumRowEntries();
1554 Teuchos::Array<zgno_t> indices(sz);
1555 Teuchos::Array<zscalar_t> values(sz);
1556 for (
size_t i = 0; i < fromMatrix->getLocalNumRows(); i++) {
1557 zgno_t gid = fromMatrix->getRowMap()->getGlobalElement(i);
1559 fromMatrix->getGlobalRowCopy(gid, indices(), values(), num);
1560 std::cout <<
"ROW " << gid <<
": ";
1561 for (
size_t j = 0; j < num; j++)
1562 std::cout << indices[j] <<
" ";
1563 std::cout << std::endl;
1568 RCP<const map_t> toMap;
1569 RCP<tcrsMatrix_t> toMatrix;
1570 RCP<import_t> importer;
1572 if (distributeInput) {
1575 short *assignments =
new short[nvtxs];
1577 fail = chaco_input_assign(assignFile,
fname.c_str(), nvtxs, assignments);
1580 Teuchos::broadcast<int, short>(*tcomm_, 0, nvtxs, assignments);
1583 Teuchos::Array<zgno_t> mine;
1584 for (
int i = 0; i < nvtxs; i++) {
1585 if (assignments[i] == rank)
1589 Tpetra::global_size_t dummy =
1590 Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid();
1591 toMap = rcp(
new map_t(dummy, mine(), base, tcomm_));
1592 delete [] assignments;
1596 toMap = rcp(
new map_t(nvtxs, base, tcomm_));
1601 importer = rcp(
new import_t(fromMap, toMap));
1602 toMatrix->doImport(*fromMatrix, *importer, Tpetra::INSERT);
1603 toMatrix->fillComplete();
1607 toMatrix = fromMatrix;
1614 typedef ArrayRCP<const ArrayView<const zscalar_t> > arrayArray_t;
1618 ArrayRCP<zscalar_t> weightBuf;
1619 ArrayView<const zscalar_t> *wgts =
new ArrayView<const zscalar_t> [nVwgts];
1622 size_t len = nVwgts * nvtxs;
1624 if (!buf)
throw std::bad_alloc();
1625 weightBuf = arcp(buf, 0, len,
true);
1627 for (
int widx=0; widx < nVwgts; widx++){
1628 wgts[widx] = ArrayView<const zscalar_t>(buf, nvtxs);
1629 float *vw = vwgts + widx;
1630 for (
int i=0; i < nvtxs; i++, vw += nVwgts)
1639 arrayArray_t vweights = arcp(wgts, 0, nVwgts,
true);
1641 RCP<tMVector_t> fromVertexWeights =
1642 rcp(
new tMVector_t(fromMap, vweights.view(0, nVwgts), nVwgts));
1644 RCP<tMVector_t> toVertexWeights;
1645 if (distributeInput) {
1646 toVertexWeights = rcp(
new tMVector_t(toMap, nVwgts));
1647 toVertexWeights->doImport(*fromVertexWeights, *importer, Tpetra::INSERT);
1650 toVertexWeights = fromVertexWeights;
1652 vtxWeights_ = toVertexWeights;
1657 if (haveEdges && nEwgts > 0){
1707 toMap = rcp(
new map_t(nedges, M_->getLocalNumEntries(), base, tcomm_));
1708 edgWeights_ = rcp(
new tMVector_t(toMap, nEwgts));
1710 size_t maxSize = M_->getLocalMaxNumRowEntries();
1711 tcrsMatrix_t::nonconst_local_inds_host_view_type colind(
"colind", maxSize);
1712 tcrsMatrix_t::nonconst_values_host_view_type vals(
"values", maxSize);
1715 for (
size_t i = 0, idx = 0; i < M_->getLocalNumRows(); i++) {
1716 M_->getLocalRowCopy(i, colind, vals, nEntries);
1717 for (
size_t j = 0; j < nEntries; j++) {
1718 edgWeights_->replaceLocalValue(idx, 0, vals[j]);
1730void UserInputForTests::getUIChacoCoords(FILE *fptr,
string fname)
1732 int rank = tcomm_->getRank();
1734 double *x=NULL, *y=NULL, *z=NULL;
1737 size_t globalNumVtx = M_->getGlobalNumRows();
1744 fail = chaco_input_geom(fptr,
fname.c_str(), (
int)globalNumVtx,
1751 std::cout <<
"UserInputForTests, read " << globalNumVtx;
1752 std::cout <<
" " << ndim <<
"-dimensional coordinates." << std::endl;
1756 Teuchos::broadcast<int, int>(*tcomm_, 0, 1, &ndim);
1759 throw std::runtime_error(
"Can't read coordinate file");
1761 ArrayRCP<ArrayRCP<const zscalar_t> > coords(ndim);
1766 for (
int dim=0; dim < ndim; dim++){
1769 throw std::bad_alloc();
1770 coords[dim] = arcp<const zscalar_t>(v, 0, globalNumVtx,
true);
1771 double *val = (dim==0 ? x : (dim==1 ? y : z));
1772 for (
size_t i=0; i < globalNumVtx; i++)
1778 len =
static_cast<zlno_t>(globalNumVtx);
1781 RCP<const map_t> fromMap = rcp(
new map_t(globalNumVtx, len, 0, tcomm_));
1782 RCP<const map_t> toMap = M_->getRowMap();
1783 RCP<import_t> importer = rcp(
new import_t(fromMap, toMap));
1785 Array<ArrayView<const zscalar_t> > coordData;
1786 for (
int dim=0; dim < ndim; dim++)
1787 coordData.push_back(coords[dim].view(0, len));
1789 RCP<tMVector_t> fromCoords =
1790 rcp(
new tMVector_t(fromMap, coordData.view(0, ndim), ndim));
1792 RCP<tMVector_t> toCoords = rcp(
new tMVector_t(toMap, ndim));
1794 toCoords->doImport(*fromCoords, *importer, Tpetra::INSERT);
1803double UserInputForTests::chaco_read_val(
1819 if (chaco_offset == 0 || chaco_offset >= chaco_break_pnt) {
1820 if (chaco_offset >= chaco_break_pnt) {
1821 length_left = CHACO_LINE_LENGTH - chaco_save_pnt - 1;
1823 ptr = &chaco_line[chaco_save_pnt];
1824 for (i=length_left; i; i--) *ptr2++ = *ptr++;
1825 length = chaco_save_pnt + 1;
1828 length = CHACO_LINE_LENGTH;
1833 ptr2 = fgets(&chaco_line[length_left], length, infile);
1835 if (ptr2 == (
char *) NULL) {
1837 return((
double) 0.0);
1840 if ((chaco_line[CHACO_LINE_LENGTH - 2] !=
'\n') && (chaco_line[CHACO_LINE_LENGTH - 2] !=
'\f')
1841 && (strlen(chaco_line) == CHACO_LINE_LENGTH - 1)){
1843 chaco_break_pnt = CHACO_LINE_LENGTH - 1;
1844 chaco_save_pnt = chaco_break_pnt;
1849 if (chaco_line[chaco_break_pnt] !=
'\0') {
1850 if (isspace((
int)(chaco_line[chaco_break_pnt]))) {
1852 chaco_save_pnt = chaco_break_pnt + 1;
1856 else if (white_seen) {
1863 chaco_break_pnt = CHACO_LINE_LENGTH;
1869 while (isspace((
int)(chaco_line[chaco_offset])) && chaco_offset < CHACO_LINE_LENGTH) chaco_offset++;
1870 if (chaco_line[chaco_offset] ==
'%' || chaco_line[chaco_offset] ==
'#') {
1872 if (chaco_break_pnt < CHACO_LINE_LENGTH) {
1873 chaco_flush_line(infile);
1875 return((
double) 0.0);
1878 ptr = &(chaco_line[chaco_offset]);
1879 val = strtod(ptr, &ptr2);
1884 return((
double) 0.0);
1887 chaco_offset = (int) (ptr2 - chaco_line) /
sizeof(char);
1894int UserInputForTests::chaco_read_int(
1910 if (chaco_offset == 0 || chaco_offset >= chaco_break_pnt) {
1911 if (chaco_offset >= chaco_break_pnt) {
1912 length_left = CHACO_LINE_LENGTH - chaco_save_pnt - 1;
1914 ptr = &chaco_line[chaco_save_pnt];
1915 for (i=length_left; i; i--) *ptr2++ = *ptr++;
1916 length = chaco_save_pnt + 1;
1919 length = CHACO_LINE_LENGTH;
1924 ptr2 = fgets(&chaco_line[length_left], length, infile);
1926 if (ptr2 == (
char *) NULL) {
1931 if ((chaco_line[CHACO_LINE_LENGTH - 2] !=
'\n') && (chaco_line[CHACO_LINE_LENGTH - 2] !=
'\f')
1932 && (strlen(chaco_line) == CHACO_LINE_LENGTH - 1)){
1934 chaco_break_pnt = CHACO_LINE_LENGTH - 1;
1935 chaco_save_pnt = chaco_break_pnt;
1940 if (chaco_line[chaco_break_pnt] !=
'\0') {
1941 if (isspace((
int)(chaco_line[chaco_break_pnt]))) {
1943 chaco_save_pnt = chaco_break_pnt + 1;
1947 else if (white_seen) {
1954 chaco_break_pnt = CHACO_LINE_LENGTH;
1960 while (isspace((
int)(chaco_line[chaco_offset])) && chaco_offset < CHACO_LINE_LENGTH) chaco_offset++;
1961 if (chaco_line[chaco_offset] ==
'%' || chaco_line[chaco_offset] ==
'#') {
1963 if (chaco_break_pnt < CHACO_LINE_LENGTH) {
1964 chaco_flush_line(infile);
1969 ptr = &(chaco_line[chaco_offset]);
1970 val = (int) strtol(ptr, &ptr2, 10);
1978 chaco_offset = (int) (ptr2 - chaco_line) /
sizeof(char);
1984void UserInputForTests::chaco_flush_line(
1991 while (c !=
'\n' && c !=
'\f')
1995int UserInputForTests::chaco_input_graph(
2045 while (end_flag == 1) {
2046 *nvtxs = chaco_read_int(fin, &end_flag);
2050 printf(
"ERROR in graph file `%s':", inname);
2051 printf(
" Invalid number of vertices (%d).\n", *nvtxs);
2056 narcs = chaco_read_int(fin, &end_flag);
2058 printf(
"ERROR in graph file `%s':", inname);
2059 printf(
" Invalid number of expected edges (%d).\n", narcs);
2066 option = chaco_read_int(fin, &end_flag);
2068 using_ewgts = option - 10 * (option / 10);
2070 using_vwgts = option - 10 * (option / 10);
2072 vtxnums = option - 10 * (option / 10);
2075 (*nVwgts) = using_vwgts;
2076 (*nEwgts) = using_ewgts;
2079 if (!end_flag && using_vwgts==1){
2080 j = chaco_read_int(fin, &end_flag);
2081 if (!end_flag) (*nVwgts) = j;
2083 if (!end_flag && using_ewgts==1){
2084 j = chaco_read_int(fin, &end_flag);
2085 if (!end_flag) (*nEwgts) = j;
2090 j = chaco_read_int(fin, &end_flag);
2093 *start = (
int *) malloc((
unsigned) (*nvtxs + 1) *
sizeof(
int));
2095 *adjacency = (
int *) malloc((
unsigned) (2 * narcs + 1) *
sizeof(
int));
2100 *vweights = (
float *) malloc((
unsigned) (*nvtxs) * (*nVwgts) *
sizeof(
float));
2105 *eweights = (
float *)
2106 malloc((
unsigned) (2 * narcs + 1) * (*nEwgts) *
sizeof(
float));
2110 adjptr = *adjacency;
2119 while ((using_vwgts || vtxnums || narcs) && end_flag != -1) {
2124 j = chaco_read_int(fin, &end_flag);
2126 if (vertex == *nvtxs)
2128 printf(
"ERROR in graph file `%s':", inname);
2129 printf(
" no vertex number in line %d.\n", line_num);
2133 if (j != vertex && j != vertex + 1) {
2134 printf(
"ERROR in graph file `%s':", inname);
2135 printf(
" out-of-order vertex number in line %d.\n", line_num);
2149 if (vertex > *nvtxs)
2153 if (using_vwgts && new_vertex) {
2154 for (j=0; j<(*nVwgts); j++){
2155 weight = chaco_read_val(fin, &end_flag);
2157 printf(
"ERROR in graph file `%s':", inname);
2158 printf(
" not enough weights for vertex %d.\n", vertex);
2162 (*vweights)[(vertex-1)*(*nVwgts)+j] = weight;
2169 neighbor = chaco_read_int(fin, &end_flag);
2175 for (j=0; j<(*nEwgts); j++){
2176 eweight = chaco_read_val(fin, &end_flag);
2179 printf(
"ERROR in graph file `%s':", inname);
2180 printf(
" not enough weights for edge (%d,%d).\n", vertex, neighbor);
2193 if (++nedges > 2*narcs) {
2194 printf(
"ERROR in graph file `%s':", inname);
2195 printf(
" at least %d adjacencies entered, but nedges = %d\n",
2200 *adjptr++ = neighbor;
2205 neighbor = chaco_read_int(fin, &end_flag);
2209 (*start)[vertex] = sum_edges;
2214 while (!flag && end_flag != -1) {
2215 chaco_read_int(fin, &end_flag);
2220 (*start)[*nvtxs] = sum_edges;
2228 if (*adjacency != NULL)
2231 if (*eweights != NULL)
2240 if (*adjacency != NULL)
2242 if (*vweights != NULL)
2244 if (*eweights != NULL)
2252 return (error_flag);
2256int UserInputForTests::chaco_input_geom(
2258 const char *geomname,
2266 double xc, yc, zc =0;
2274 *x = *y = *z = NULL;
2277 while (end_flag == 1) {
2278 xc = chaco_read_val(fingeom, &end_flag);
2282 if (end_flag == -1) {
2283 printf(
"No values found in geometry file `%s'\n", geomname);
2289 yc = chaco_read_val(fingeom, &end_flag);
2290 if (end_flag == 0) {
2292 zc = chaco_read_val(fingeom, &end_flag);
2293 if (end_flag == 0) {
2295 chaco_read_val(fingeom, &end_flag);
2297 printf(
"Too many values on input line of geometry file `%s'\n",
2300 printf(
" Maximum dimensionality is 3\n");
2309 *x = (
double *) malloc((
unsigned) nvtxs *
sizeof(
double));
2312 *y = (
double *) malloc((
unsigned) nvtxs *
sizeof(
double));
2316 *z = (
double *) malloc((
unsigned) nvtxs *
sizeof(
double));
2320 for (nread = 1; nread < nvtxs; nread++) {
2323 i = fscanf(fingeom,
"%lf", &((*x)[nread]));
2325 else if (ndims == 2) {
2326 i = fscanf(fingeom,
"%lf%lf", &((*x)[nread]), &((*y)[nread]));
2328 else if (ndims == 3) {
2329 i = fscanf(fingeom,
"%lf%lf%lf", &((*x)[nread]), &((*y)[nread]),
2334 printf(
"Too few lines of values in geometry file; nvtxs=%d, but only %d read\n",
2339 else if (i != ndims) {
2340 printf(
"Wrong number of values in line %d of geometry file `%s'\n",
2341 line_num, geomname);
2350 while (!flag && end_flag != -1) {
2351 chaco_read_val(fingeom, &end_flag);
2363int UserInputForTests::chaco_input_assign(
2365 const char *inassignname,
2376 while (end_flag == 1) {
2377 assignment[0] = chaco_read_int(finassign, &end_flag);
2380 if (assignment[0] < 0) {
2381 printf(
"ERROR: Entry %d in assignment file `%s' less than zero (%d)\n",
2382 1, inassignname, assignment[0]);
2387 if (end_flag == -1) {
2388 printf(
"ERROR: No values found in assignment file `%s'\n", inassignname);
2394 int np = this->tcomm_->getSize();
2395 if (assignment[0] >= np) flag = assignment[0];
2396 srand(this->tcomm_->getRank());
2397 for (i = 1; i < nvtxs; i++) {
2398 j = fscanf(finassign,
"%hd", &(assignment[i]));
2400 printf(
"ERROR: Too few values in assignment file `%s'.\n", inassignname);
2404 if (assignment[i] < 0) {
2405 printf(
"ERROR: Entry %d in assignment file `%s' less than zero (%d)\n",
2406 i+1, inassignname, assignment[i]);
2410 if (assignment[i] >= np) {
2412 if (assignment[i] > flag)
2413 flag = assignment[i];
2414 assignment[i] = rand() % np;
2420 printf(
"WARNING: Possible error in assignment file `%s'\n",
2422 printf(
" Max assignment set (%d) greater than "
2423 "max processor rank (%d)\n", flag, np-1);
2424 printf(
" Some vertices given random initial assignments\n");
2430 while (!flag && end_flag != -1) {
2431 chaco_read_int(finassign, &end_flag);
2436 printf(
"WARNING: Possible error in assignment file `%s'\n", inassignname);
2437 printf(
" Numerical data found after expected end of file\n");
2445void UserInputForTests::readPamgenMeshFile(
string path,
string testData)
2447#ifdef HAVE_ZOLTAN2_PAMGEN
2448 int rank = this->tcomm_->getRank();
2449 if (verbose_ && tcomm_->getRank() == 0)
2450 std::cout <<
"UserInputForTestsBD::readPamgenFile, Read: " << testData << std::endl;
2457 std::ostringstream meshFileName;
2458 meshFileName << path <<
"/" << testData <<
".pmgen";
2461 file.open(meshFileName.str(), std::ios::in);
2465 if(verbose_ && tcomm_->getRank() == 0)
2467 std::cout <<
"Unable to open pamgen mesh: ";
2468 std::cout << meshFileName.str();
2469 std::cout <<
"\nPlease check file path and name." << std::endl;
2475 file.seekg (0,file.end);
2482 while(std::getline(file,line))
2484 if( line.find(
"nz") != std::string::npos ||
2485 line.find(
"nphi") != std::string::npos)
2493 file.seekg(0, std::ios::beg);
2498 this->tcomm_->broadcast(0,
sizeof(
int), (
char *)&dimension);
2499 this->tcomm_->broadcast(0,
sizeof(
size_t),(
char *)&len);
2500 this->tcomm_->barrier();
2503 if(verbose_ && tcomm_->getRank() == 0)
2504 std::cout <<
"Pamgen Mesh file size == 0, exiting UserInputForTests early." << std::endl;
2508 char * file_data =
new char[len+1];
2509 file_data[len] =
'\0';
2511 file.read(file_data,len);
2515 this->tcomm_->broadcast(0,(
int)len+1,file_data);
2516 this->tcomm_->barrier();
2520 this->pamgen_mesh = rcp(
new PamgenMesh);
2521 this->havePamgenMesh =
true;
2522 pamgen_mesh->createMesh(file_data,dimension,this->tcomm_);
2525 pamgen_mesh->storeMesh();
2526 this->tcomm_->barrier();
2529 this->setPamgenCoordinateMV();
2532 this->setPamgenAdjacencyGraph();
2534 this->tcomm_->barrier();
2535 if(rank == 0) file.close();
2536 delete [] file_data;
2538 throw std::runtime_error(
"Pamgen requested but Trilinos "
2539 "not built with Pamgen");
2543#ifdef HAVE_ZOLTAN2_PAMGEN
2544void UserInputForTests::setPamgenCoordinateMV()
2546 int dimension = pamgen_mesh->num_dim;
2550 zgno_t numelements = pamgen_mesh->num_elem;
2551 zgno_t numGlobalElements = pamgen_mesh->num_elems_global;
2554 Array<zgno_t> elementList(numelements);
2555 for (Array<zgno_t>::size_type k = 0; k < numelements; ++k) {
2556 elementList[k] = pamgen_mesh->element_order_map[k];
2558 auto mp = rcp (
new map_t (numGlobalElements, elementList, 0, this->tcomm_));
2561 xyz_ = RCP<tMVector_t>(
new tMVector_t(mp, dimension,
false));
2563 auto lclXYZ = xyz_->getLocalViewHost(Tpetra::Access::OverwriteAll);
2564 for(
int i = 0; i < dimension; ++i){
2565 double *tmp = &pamgen_mesh->element_coord[i*numelements];
2566 for (
int j = 0; j < numelements; j++)
2567 lclXYZ(j, i) = tmp[j];
2572void UserInputForTests::setPamgenAdjacencyGraph()
2582 size_t local_nodes = (size_t)this->pamgen_mesh->num_nodes;
2583 size_t local_els = (size_t)this->pamgen_mesh->num_elem;
2585 size_t global_els = (size_t)this->pamgen_mesh->num_elems_global;
2586 size_t global_nodes = (size_t)this->pamgen_mesh->num_nodes_global;
2590 RCP<const map_t> rowMap = rcp(
new map_t(global_els,0,this->tcomm_));
2591 RCP<const map_t> rangeMap = rowMap;
2594 RCP<const map_t> domainMap = rcp(
new map_t(global_nodes,0,this->tcomm_));
2597 int blks = this->pamgen_mesh->num_elem_blk;
2598 int max_nodes_per_el = 0;
2599 for(
int i = 0; i < blks; i++)
2600 if (this->pamgen_mesh->nodes_per_element[i] > max_nodes_per_el)
2601 max_nodes_per_el = this->pamgen_mesh->nodes_per_element[i];
2604 Teuchos::RCP<tcrsMatrix_t> C = rcp(
new tcrsMatrix_t(rowMap,max_nodes_per_el));
2606 Array<zgno_t> g_el_ids(local_els);
2607 for (
size_t k = 0; k < local_els; ++k) {
2608 g_el_ids[k] = pamgen_mesh->global_element_numbers[k]-1;
2611 Array<zgno_t> g_node_ids(local_nodes);
2612 for (
size_t k = 0; k < local_nodes; ++k) {
2613 g_node_ids[k] = pamgen_mesh->global_node_numbers[k]-1;
2620 for(
int i = 0; i < blks; i++)
2622 int el_per_block = this->pamgen_mesh->elements[i];
2623 int nodes_per_el = this->pamgen_mesh->nodes_per_element[i];
2624 int * connect = this->pamgen_mesh->elmt_node_linkage[i];
2626 for(
int j = 0; j < el_per_block; j++)
2628 const zgno_t gid =
static_cast<zgno_t>(g_el_ids[el_no]);
2629 for(
int k = 0; k < nodes_per_el; k++)
2631 int g_node_i = g_node_ids[connect[j*nodes_per_el+k]-1];
2632 C->insertGlobalValues(gid,
2633 Teuchos::tuple<zgno_t>(g_node_i),
2634 Teuchos::tuple<zscalar_t>(one));
2640 C->fillComplete(domainMap, rangeMap);
2646 Tpetra::MatrixMatrix::Multiply(*C,
false, *C,
true, *A);
2651 this->M_ = rcp(
new tcrsMatrix_t(rowMap, A->getGlobalMaxNumRowEntries()));
2654 Teuchos::ArrayView<const zgno_t> rowMapElementList =
2655 rowMap->getLocalElementList();
2656 for (Teuchos_Ordinal ii = 0; ii < rowMapElementList.size(); ii++)
2658 zgno_t gid = rowMapElementList[ii];
2659 size_t numEntriesInRow = A->getNumEntriesInGlobalRow (gid);
2660 typename tcrsMatrix_t::nonconst_global_inds_host_view_type rowinds(
"Indices", numEntriesInRow);
2661 typename tcrsMatrix_t::nonconst_values_host_view_type rowvals(
"Values", numEntriesInRow);
2664 Array<zscalar_t> mod_rowvals;
2665 Array<zgno_t> mod_rowinds;
2666 A->getGlobalRowCopy (gid, rowinds, rowvals, numEntriesInRow);
2667 for (
size_t i = 0; i < numEntriesInRow; i++) {
2670 if (rowvals[i] >= 1)
2672 mod_rowvals.push_back(one);
2673 mod_rowinds.push_back(rowinds[i]);
2676 this->M_->insertGlobalValues(gid, mod_rowinds, mod_rowvals);
2679 this->M_->fillComplete();
#define TEST_FAIL_AND_THROW(comm, ok, s)
int buildCrsMatrix(int xdim, int ydim, int zdim, std::string problemType, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, Teuchos::RCP< Tpetra::CrsMatrix< scalar_t, lno_t, gno_t, nod_t > > &M_)
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
common code used by tests
Tpetra::Map ::local_ordinal_type zlno_t
Tpetra::Map ::global_ordinal_type zgno_t
keep typedefs that commonly appear in many places localized
Traits of Xpetra classes, including migration method.
int getCoordinateDimension()
lno_t getNumLocalCoords()
int getNumWeights()
#######END Predistribution functions######################//
void getLocalWeightsCopy(scalar_t **w)
gno_t getNumGlobalCoords()
void getLocalCoordinatesCopy(scalar_t **c)
static const std::string fail
GeometricGen::GeometricGenerator< zscalar_t, zlno_t, zgno_t, znode_t > geometricgen_t
Tpetra::CrsMatrix< zscalar_t, zlno_t, zgno_t, znode_t > tcrsMatrix_t
Tpetra::MultiVector< zscalar_t, zlno_t, zgno_t, znode_t > tMVector_t
Tpetra::Vector< zscalar_t, zlno_t, zgno_t, znode_t > tVector_t
static RCP< User > convertToXpetra(const RCP< User > &a)
Convert the object to its Xpetra wrapped version.