Zoltan2
UserInputForTests.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Zoltan2: A package of combinatorial algorithms for scientific computing
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Karen Devine (kddevin@sandia.gov)
39 // Erik Boman (egboman@sandia.gov)
40 // Siva Rajamanickam (srajama@sandia.gov)
41 //
42 // ***********************************************************************
43 //
44 // @HEADER
45 
50 #ifndef USERINPUTFORTESTS
51 #define USERINPUTFORTESTS
52 
53 #include "Zoltan2_TestHelpers.hpp"
54 #include <Zoltan2_XpetraTraits.hpp>
55 
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>
62 
63 #include <MatrixMarket_Tpetra.hpp>
64 
65 #ifdef HAVE_ZOLTAN2_GALERI
66 #include <Galeri_XpetraProblemFactory.hpp>
67 #include <Galeri_XpetraParameters.hpp>
68 #endif
69 
70 #include <Kokkos_DefaultNode.hpp>
71 
72 #include "GeometricGenerator.hpp"
73 #include <fstream>
74 #include <string>
75 
76 #include <TpetraExt_MatrixMatrix_def.hpp>
77 
78 // pamgen required includes
80 
81 
82 using Teuchos::RCP;
83 using Teuchos::ArrayRCP;
84 using Teuchos::ArrayView;
85 using Teuchos::Array;
86 using Teuchos::Comm;
87 using Teuchos::rcp;
88 using Teuchos::arcp;
89 using Teuchos::rcp_const_cast;
90 using Teuchos::ParameterList;
91 using namespace std;
92 
124 
126 {
127 public:
128 
129  typedef Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t> tcrsMatrix_t;
130  typedef Tpetra::CrsGraph<zlno_t, zgno_t, znode_t> tcrsGraph_t;
131  typedef Tpetra::Vector<zscalar_t, zlno_t, zgno_t, znode_t> tVector_t;
132  typedef Tpetra::MultiVector<zscalar_t, zlno_t, zgno_t, znode_t> tMVector_t;
133 
134  typedef Xpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t> xcrsMatrix_t;
135  typedef Xpetra::CrsGraph<zlno_t, zgno_t, znode_t> xcrsGraph_t;
136  typedef Xpetra::Vector<zscalar_t, zlno_t, zgno_t, znode_t> xVector_t;
137  typedef Xpetra::MultiVector<zscalar_t, zlno_t, zgno_t, znode_t> xMVector_t;
138 
139  typedef Tpetra::Map<zlno_t, zgno_t, znode_t> map_t;
140  typedef Tpetra::Export<zlno_t, zgno_t, znode_t> export_t;
141  typedef Tpetra::Import<zlno_t, zgno_t, znode_t> import_t;
142  typedef map_t::node_type default_znode_t;
145 
146 
166  UserInputForTests(string path, string testData,
167  const RCP<const Comm<int> > &c, bool debugInfo=false,
168  bool distributeInput=true);
169 
186  UserInputForTests(int x, int y, int z, string matrixType,
187  const RCP<const Comm<int> > &c, bool debugInfo=false,
188  bool distributeInput=true);
189 
205  UserInputForTests(const ParameterList &pList,
206  const RCP<const Comm<int> > &c);
207 
210  static void getUIRandomData(unsigned int seed, zlno_t length,
211  zscalar_t min, zscalar_t max, ArrayView<ArrayRCP<zscalar_t > > data);
212 
213  RCP<tMVector_t> getUICoordinates();
214 
215  RCP<tMVector_t> getUIWeights();
216 
217  RCP<tMVector_t> getUIEdgeWeights();
218 
219  RCP<tcrsMatrix_t> getUITpetraCrsMatrix();
220 
221  RCP<tcrsGraph_t> getUITpetraCrsGraph();
222 
223  RCP<tVector_t> getUITpetraVector();
224 
225  RCP<tMVector_t> getUITpetraMultiVector(int nvec);
226 
227  RCP<xcrsMatrix_t> getUIXpetraCrsMatrix();
228 
229  RCP<xcrsGraph_t> getUIXpetraCrsGraph();
230 
231  RCP<xVector_t> getUIXpetraVector();
232 
233  RCP<xMVector_t> getUIXpetraMultiVector(int nvec);
234 
235 #ifdef HAVE_ZOLTAN2_PAMGEN
236  PamgenMesh * getPamGenMesh(){return this->pamgen_mesh.operator->();}
237 #endif
238 
239 #ifdef HAVE_EPETRA_DATA_TYPES
240  RCP<Epetra_CrsGraph> getUIEpetraCrsGraph();
241 
242  RCP<Epetra_CrsMatrix> getUIEpetraCrsMatrix();
243 
244  RCP<Epetra_Vector> getUIEpetraVector();
245 
246  RCP<Epetra_MultiVector> getUIEpetraMultiVector(int nvec);
247 #endif
248  bool hasInput();
249 
250  bool hasInputDataType(const string &input_type);
251 
252  bool hasUICoordinates();
253 
254  bool hasUIWeights();
255 
256  bool hasUIEdgeWeights();
257 
258  bool hasUITpetraCrsMatrix();
259 
260  bool hasUITpetraCrsGraph();
261 
262  bool hasUITpetraVector();
263 
264  bool hasUITpetraMultiVector();
265 
266  bool hasUIXpetraCrsMatrix();
267 
268  bool hasUIXpetraCrsGraph();
269 
270  bool hasUIXpetraVector();
271 
272  bool hasUIXpetraMultiVector();
273 
274  bool hasPamgenMesh();
275 #ifdef HAVE_EPETRA_DATA_TYPES
276  bool hasUIEpetraCrsGraph();
277 
278  bool hasUIEpetraCrsMatrix();
279 
280  bool hasUIEpetraVector();
281 
282  bool hasUIEpetraMultiVector();
283 
284 #endif
285 
286 private:
287 
288  bool verbose_;
289 
290  const RCP<const Comm<int> > tcomm_;
291 
292  bool havePamgenMesh;
293 #ifdef HAVE_ZOLTAN2_PAMGEN
294  RCP<PamgenMesh> pamgen_mesh;
295 #endif
296 
297  RCP<tcrsMatrix_t> M_;
298  RCP<xcrsMatrix_t> xM_;
299 
300  RCP<tMVector_t> xyz_;
301  RCP<tMVector_t> vtxWeights_;
302  RCP<tMVector_t> edgWeights_;
303 
304 #ifdef HAVE_EPETRA_DATA_TYPES
305  RCP<const Epetra_Comm> ecomm_;
306  RCP<Epetra_CrsMatrix> eM_;
307  RCP<Epetra_CrsGraph> eG_;
308 #endif
309 
310  // Read a Matrix Market file into M_
311  // using Tpetra::MatrixMarket::Reader.
312  // If there are "Tim Davis" style coordinates
313  // that go with the file, read those into xyz_.
314 
315  void readMatrixMarketFile(string path, string testData,bool distributeInput = true);
316 
317  // Build matrix M_ from a mesh and a problem type
318  // with Galeri::Xpetra.
319 
320  void buildCrsMatrix(int xdim, int ydim, int zdim, string type,
321  bool distributeInput);
322 
323  // Read a Zoltan1 Chaco or Matrix Market file
324  // into M_. If it has geometric coordinates,
325  // read them into xyz_. If it has weights,
326  // read those into vtxWeights_ and edgWeights_.
327  void readZoltanTestData(string path, string testData,
328  bool distributeInput);
329 
330  // Read Zoltan data that is in a .graph file.
331  void getUIChacoGraph(FILE *fptr, bool haveAssign, FILE *assignFile,
332  string name, bool distributeInput);
333 
334  // Read Zoltan data that is in a .coords file.
335  void getUIChacoCoords(FILE *fptr, string name);
336 
337  // Chaco reader code: This code is copied from zoltan/ch.
338  // It might benefit from a rewrite and simplification.
339 
340  // Chaco reader helper functions: copied from zoltan/ch
341  static const int CHACO_LINE_LENGTH=200;
342  char chaco_line[CHACO_LINE_LENGTH]; /* space to hold values */
343  int chaco_offset; /* offset into line for next data */
344  int chaco_break_pnt; /* place in sequence to pause */
345  int chaco_save_pnt; /* place in sequence to save */
346 
347  double chaco_read_val(FILE* infile, int *end_flag);
348  int chaco_read_int(FILE* infile, int *end_flag);
349  void chaco_flush_line(FILE*);
350 
351  // Chaco graph reader: copied from zoltan/ch
352  int chaco_input_graph(FILE *fin, const char *inname, int **start,
353  int **adjacency, int *nvtxs, int *nVwgts,
354  float **vweights, int *nEwgts, float **eweights);
355 
356  // Chaco coordinate reader: copied from zoltan/ch
357  int chaco_input_geom(FILE *fingeom, const char *geomname, int nvtxs,
358  int *igeom, double **x, double **y, double **z);
359 
360  // Chaco coordinate reader: copied from zoltan/ch
361  int chaco_input_assign(FILE *finassign, const char *assignname, int nvtxs,
362  short *assignments);
363 
364 
365  // Read a GeomGen.txt file into M_
366  // Read coordinates into xyz_.
367  // If iti has weights read those to vtxWeights_
368  // and edgeWeights_
369  void readGeometricGenTestData(string path, string testData);
370 
371  // Geometry Gnearatory helper function
372  void readGeoGenParams(string paramFileName,
373  ParameterList &geoparams);
374 
375  // utility methods used when reading geom gen files
376 
377  static string trim_right_copy(const string& s,
378  const string& delimiters = " \f\n\r\t\v" );
379 
380  static string trim_left_copy(const string& s,
381  const string& delimiters = " \f\n\r\t\v" );
382 
383  static string trim_copy(const string& s,
384  const string& delimiters = " \f\n\r\t\v" );
385 
386 
387  // Read a pamgen mesh
388  void readPamgenMeshFile(string path, string testData);
389 #ifdef HAVE_ZOLTAN2_PAMGEN
390  void setPamgenAdjacencyGraph();
391  void setPamgenCoordinateMV();
392 #endif
393 };
394 
395 UserInputForTests::UserInputForTests(string path, string testData,
396  const RCP<const Comm<int> > &c,
397  bool debugInfo, bool distributeInput):
398 verbose_(debugInfo), tcomm_(c), havePamgenMesh(false),
399 M_(), xM_(), xyz_(), vtxWeights_(), edgWeights_(),
401 ecomm_(), eM_(), eG_(),
402 #endif
403 chaco_offset(0), chaco_break_pnt(CHACO_LINE_LENGTH)
404 {
405  bool zoltan1 = false;
406  string::size_type loc = path.find("/zoltan/test/"); // Zoltan1 data
407  if (loc != string::npos)
408  zoltan1 = true;
409 
410  if (zoltan1)
411  readZoltanTestData(path, testData, distributeInput);
412  else
413  readMatrixMarketFile(path, testData);
414 
415 #ifdef HAVE_EPETRA_DATA_TYPES
416  ecomm_ = Xpetra::toEpetra(c);
417 #endif
418 }
419 
421  string matrixType,
422  const RCP<const Comm<int> > &c,
423  bool debugInfo,
424  bool distributeInput):
425 verbose_(debugInfo), tcomm_(c), havePamgenMesh(false),
426 M_(), xM_(), xyz_(), vtxWeights_(), edgWeights_(),
428 ecomm_(), eM_(), eG_(),
429 #endif
430 chaco_offset(0), chaco_break_pnt(CHACO_LINE_LENGTH)
431 {
432  if (matrixType.size() == 0){
433  int dim = 0;
434  if (x > 0) dim++;
435  if (y > 0) dim++;
436  if (z > 0) dim++;
437  if (dim == 1)
438  matrixType = string("Laplace1D");
439  else if (dim == 2)
440  matrixType = string("Laplace2D");
441  else if (dim == 3)
442  matrixType = string("Laplace3D");
443  else
444  throw std::runtime_error("input");
445 
446  if (verbose_ && tcomm_->getRank() == 0)
447  std::cout << "UserInputForTests, Matrix type : " << matrixType << std::endl;
448  }
449 
450  buildCrsMatrix(x, y, z, matrixType, distributeInput);
451 
452 #ifdef HAVE_EPETRA_DATA_TYPES
453  ecomm_ = Xpetra::toEpetra(c);
454 #endif
455 }
456 
457 UserInputForTests::UserInputForTests(const ParameterList &pList,
458  const RCP<const Comm<int> > &c):
459 tcomm_(c), havePamgenMesh(false),
460 M_(), xM_(), xyz_(), vtxWeights_(), edgWeights_(),
462 ecomm_(), eM_(), eG_(),
463 #endif
464 chaco_offset(0), chaco_break_pnt(CHACO_LINE_LENGTH)
465 {
466 
467  // get options
468  bool distributeInput = true, debugInfo = true;
469 
470  if(pList.isParameter("distribute input"))
471  distributeInput = pList.get<bool>("distribute input");
472 
473  if(pList.isParameter("debug"))
474  debugInfo = pList.get<bool>("debug");
475  this->verbose_ = debugInfo;
476 
477  if(pList.isParameter("input file"))
478  {
479 
480  // get input path
481  string path(".");
482  if(pList.isParameter("input path"))
483  path = pList.get<string>("input path");
484 
485  string testData = pList.get<string>("input file");
486 
487  // find out if we are working from the zoltan1 test diretory
489 
490  // find out if we are using the geometric generator
491  if(pList.isParameter("file type") && pList.get<string>("file type") == "Geometric Generator")
492  file_format = GEOMGEN;
493  else if(pList.isParameter("file type") && pList.get<string>("file type") == "Pamgen")
494  {
495  file_format = PAMGEN;
496  }
497  else if(pList.isParameter("file type") && pList.get<string>("file type") == "Chaco")
498  file_format = CHACO; // this flag calls read ZoltanTestData, which calls the chaco readers...
499 
500  // read the input file
501  switch (file_format) {
502  case GEOMGEN: readGeometricGenTestData(path,testData); break;
503  case PAMGEN: readPamgenMeshFile(path,testData); break;
504  case CHACO: readZoltanTestData(path, testData, distributeInput); break;
505  default: readMatrixMarketFile(path, testData, distributeInput); break;
506  }
507 
508  }else if(pList.isParameter("x") || pList.isParameter("y") || pList.isParameter("z")){
509 
510  int x,y,z;
511  x = y = z = 0;
512  if(pList.isParameter("x")) x = pList.get<int>("x");
513  if(pList.isParameter("y")) y = pList.get<int>("y");
514  if(pList.isParameter("z")) z = pList.get<int>("z");
515 
516  string problemType = "";
517  if(pList.isParameter("equation type")) problemType = pList.get<string>("equation type");
518 
519  if (problemType.size() == 0){
520  int dim = 0;
521  if (x > 0) dim++;
522  if (y > 0) dim++;
523  if (z > 0) dim++;
524  if (dim == 1)
525  problemType = string("Laplace1D");
526  else if (dim == 2)
527  problemType = string("Laplace2D");
528  else if (dim == 3)
529  problemType = string("Laplace3D");
530  else
531  throw std::runtime_error("input");
532 
533  if (verbose_ && tcomm_->getRank() == 0)
534  std::cout << "UserInputForTests, Matrix type : " << problemType << std::endl;
535  }
536 
537 
538  buildCrsMatrix(x, y, z, problemType, distributeInput);
539 
540  }else{
541  std::cerr << "Input file block undefined!" << std::endl;
542  }
543 
544 #ifdef HAVE_EPETRA_DATA_TYPES
545  ecomm_ = Xpetra::toEpetra(c);
546 #endif
547 
548 }
549 
550 
551 RCP<UserInputForTests::tMVector_t> UserInputForTests::getUICoordinates()
552 {
553  if (xyz_.is_null())
554  throw std::runtime_error("could not read coord file");
555  return xyz_;
556 }
557 
558 RCP<UserInputForTests::tMVector_t> UserInputForTests::getUIWeights()
559 {
560  return vtxWeights_;
561 }
562 
563 RCP<UserInputForTests::tMVector_t> UserInputForTests::getUIEdgeWeights()
564 {
565  return edgWeights_;
566 }
567 
568 RCP<UserInputForTests::tcrsMatrix_t> UserInputForTests::getUITpetraCrsMatrix()
569 {
570  if (M_.is_null())
571  throw std::runtime_error("could not read mtx file");
572  return M_;
573 }
574 
575 RCP<UserInputForTests::tcrsGraph_t> UserInputForTests::getUITpetraCrsGraph()
576 {
577  if (M_.is_null())
578  throw std::runtime_error("could not read mtx file");
579  return rcp_const_cast<tcrsGraph_t>(M_->getCrsGraph());
580 }
581 
582 RCP<UserInputForTests::tVector_t> UserInputForTests::getUITpetraVector()
583 {
584  RCP<tVector_t> V = rcp(new tVector_t(M_->getRowMap(), 1));
585  V->randomize();
586 
587  return V;
588 }
589 
590 RCP<UserInputForTests::tMVector_t> UserInputForTests::getUITpetraMultiVector(int nvec)
591 {
592  RCP<tMVector_t> mV = rcp(new tMVector_t(M_->getRowMap(), nvec));
593  mV->randomize();
594 
595  return mV;
596 }
597 
598 RCP<UserInputForTests::xcrsMatrix_t> UserInputForTests::getUIXpetraCrsMatrix()
599 {
600  if (M_.is_null())
601  throw std::runtime_error("could not read mtx file");
602  return xM_;
603 }
604 
605 RCP<UserInputForTests::xcrsGraph_t> UserInputForTests::getUIXpetraCrsGraph()
606 {
607  if (M_.is_null())
608  throw std::runtime_error("could not read mtx file");
609  return rcp_const_cast<xcrsGraph_t>(xM_->getCrsGraph());
610 }
611 
612 RCP<UserInputForTests::xVector_t> UserInputForTests::getUIXpetraVector()
613 {
615 }
616 
617 RCP<UserInputForTests::xMVector_t> UserInputForTests::getUIXpetraMultiVector(int nvec)
618 {
619  RCP<tMVector_t> tMV = getUITpetraMultiVector(nvec);
621 }
622 
623 #ifdef HAVE_EPETRA_DATA_TYPES
624 RCP<Epetra_CrsGraph> UserInputForTests::getUIEpetraCrsGraph()
625 {
626  if (M_.is_null())
627  throw std::runtime_error("could not read mtx file");
628  RCP<const tcrsGraph_t> tgraph = M_->getCrsGraph();
629  RCP<const Tpetra::Map<zlno_t, zgno_t> > trowMap = tgraph->getRowMap();
630  RCP<const Tpetra::Map<zlno_t, zgno_t> > tcolMap = tgraph->getColMap();
631 
632  int nElts = static_cast<int>(trowMap->getGlobalNumElements());
633  int nMyElts = static_cast<int>(trowMap->getNodeNumElements());
634  int base = trowMap->getIndexBase();
635  ArrayView<const int> gids = trowMap->getNodeElementList();
636 
637  Epetra_BlockMap erowMap(nElts, nMyElts,
638  gids.getRawPtr(), 1, base, *ecomm_);
639 
640  Array<int> rowSize(nMyElts);
641  for (int i=0; i < nMyElts; i++){
642  rowSize[i] = static_cast<int>(M_->getNumEntriesInLocalRow(i+base));
643  }
644 
645  size_t maxRow = M_->getNodeMaxNumRowEntries();
646  Array<int> colGids(maxRow);
647  ArrayView<const int> colLid;
648 
649  eG_ = rcp(new Epetra_CrsGraph(Copy, erowMap,
650  rowSize.getRawPtr(), true));
651 
652  for (int i=0; i < nMyElts; i++){
653  tgraph->getLocalRowView(i+base, colLid);
654  for (int j=0; j < colLid.size(); j++)
655  colGids[j] = tcolMap->getGlobalElement(colLid[j]);
656  eG_->InsertGlobalIndices(gids[i], rowSize[i], colGids.getRawPtr());
657  }
658  eG_->FillComplete();
659  return eG_;
660 }
661 
662 RCP<Epetra_CrsMatrix> UserInputForTests::getUIEpetraCrsMatrix()
663 {
664  if (M_.is_null())
665  throw std::runtime_error("could not read mtx file");
666  RCP<Epetra_CrsGraph> egraph = getUIEpetraCrsGraph();
667  eM_ = rcp(new Epetra_CrsMatrix(Copy, *egraph));
668 
669  size_t maxRow = M_->getNodeMaxNumRowEntries();
670  int nrows = egraph->NumMyRows();
671  int base = egraph->IndexBase();
672  const Epetra_BlockMap &rowMap = egraph->RowMap();
673  const Epetra_BlockMap &colMap = egraph->ColMap();
674  Array<int> colGid(maxRow);
675 
676  for (int i=0; i < nrows; i++){
677  ArrayView<const int> colLid;
678  ArrayView<const zscalar_t> nz;
679  M_->getLocalRowView(i+base, colLid, nz);
680  size_t rowSize = colLid.size();
681  int rowGid = rowMap.GID(i+base);
682  for (size_t j=0; j < rowSize; j++){
683  colGid[j] = colMap.GID(colLid[j]);
684  }
685  eM_->InsertGlobalValues(rowGid, (int)rowSize, nz.getRawPtr(), colGid.getRawPtr());
686  }
687  eM_->FillComplete();
688  return eM_;
689 }
690 
691 RCP<Epetra_Vector> UserInputForTests::getUIEpetraVector()
692 {
693  RCP<Epetra_CrsGraph> egraph = getUIEpetraCrsGraph();
694  RCP<Epetra_Vector> V = rcp(new Epetra_Vector(egraph->RowMap()));
695  V->Random();
696  return V;
697 }
698 
699 RCP<Epetra_MultiVector> UserInputForTests::getUIEpetraMultiVector(int nvec)
700 {
701  RCP<Epetra_CrsGraph> egraph = getUIEpetraCrsGraph();
702  RCP<Epetra_MultiVector> mV =
703  rcp(new Epetra_MultiVector(egraph->RowMap(), nvec));
704  mV->Random();
705  return mV;
706 }
707 #endif
708 
710 {
711  // find out if an input source has been loaded
712  return this->hasUICoordinates() || \
713  this->hasUITpetraCrsMatrix() || \
714  this->hasUITpetraCrsGraph() || \
715  this->hasPamgenMesh();
716 }
717 
718 bool UserInputForTests::hasInputDataType(const string &input_type)
719 {
720  if(input_type == "coordinates")
721  return this->hasUICoordinates();
722  else if(input_type == "tpetra_vector")
723  return this->hasUITpetraVector();
724  else if(input_type == "tpetra_multivector")
725  return this->hasUITpetraMultiVector();
726  else if(input_type == "tpetra_crs_graph")
727  return this->hasUITpetraCrsGraph();
728  else if(input_type == "tpetra_crs_matrix")
729  return this->hasUITpetraCrsMatrix();
730  else if(input_type == "xpetra_vector")
731  return this->hasUIXpetraVector();
732  else if(input_type == "xpetra_multivector")
733  return this->hasUIXpetraMultiVector();
734  else if(input_type == "xpetra_crs_graph")
735  return this->hasUIXpetraCrsGraph();
736  else if(input_type == "xpetra_crs_matrix")
737  return this->hasUIXpetraCrsMatrix();
738 #ifdef HAVE_EPETRA_DATA_TYPES
739  else if(input_type == "epetra_vector")
740  return this->hasUIEpetraVector();
741  else if(input_type == "epetra_multivector")
742  return this->hasUIEpetraMultiVector();
743  else if(input_type == "epetra_crs_graph")
744  return this->hasUIEpetraCrsGraph();
745  else if(input_type == "epetra_crs_matrix")
746  return this->hasUIEpetraCrsMatrix();
747 #endif
748 
749  return false;
750 }
751 
753 {
754  return xyz_.is_null() ? false : true;
755 }
756 
758 {
759  return vtxWeights_.is_null() ? false : true;
760 }
761 
763 {
764  return edgWeights_.is_null() ? false : true;
765 }
766 
768 {
769  return M_.is_null() ? false : true;
770 }
771 
773 {
774  return M_.is_null() ? false : true;
775 }
776 
778 {
779  return true;
780 }
781 
783 {
784  return true;
785 }
786 
788 {
789  return M_.is_null() ? false : true;
790 }
791 
793 {
794  return M_.is_null() ? false : true;
795 }
796 
798 {
799  return true;
800 }
801 
803 {
804  return true;
805 }
806 
808 {
809  return this->havePamgenMesh;
810 }
811 
812 #ifdef HAVE_EPETRA_DATA_TYPES
813 bool UserInputForTests::hasUIEpetraCrsGraph()
814 {
815  return M_.is_null() ? false : true;
816 }
817 
818 bool UserInputForTests::hasUIEpetraCrsMatrix()
819 {
820  return hasUIEpetraCrsGraph();
821 }
822 
823 bool UserInputForTests::hasUIEpetraVector()
824 {
825  return hasUIEpetraCrsGraph();
826 }
827 
828 bool UserInputForTests::hasUIEpetraMultiVector()
829 {
830  return hasUIEpetraCrsGraph();
831 }
832 #endif
833 
834 void UserInputForTests::getUIRandomData(unsigned int seed, zlno_t length,
835  zscalar_t min, zscalar_t max,
836  ArrayView<ArrayRCP<zscalar_t > > data)
837 {
838  if (length < 1)
839  return;
840 
841  size_t dim = data.size();
842  for (size_t i=0; i < dim; i++){
843  zscalar_t *tmp = new zscalar_t [length];
844  if (!tmp)
845  throw (std::bad_alloc());
846  data[i] = Teuchos::arcp(tmp, 0, length, true);
847  }
848 
849  zscalar_t scalingFactor = (max-min) / RAND_MAX;
850  srand(seed);
851  for (size_t i=0; i < dim; i++){
852  zscalar_t *x = data[i].getRawPtr();
853  for (zlno_t j=0; j < length; j++)
854  *x++ = min + (zscalar_t(rand()) * scalingFactor);
855  }
856 }
857 
858 // utility methods used when reading geom gen files
859 
860 string UserInputForTests::trim_right_copy(
861  const string& s,
862  const string& delimiters)
863 {
864  return s.substr( 0, s.find_last_not_of( delimiters ) + 1 );
865 }
866 
867 string UserInputForTests::trim_left_copy(
868  const string& s,
869  const string& delimiters)
870 {
871  return s.substr( s.find_first_not_of( delimiters ) );
872 }
873 
874 string UserInputForTests::trim_copy(
875  const string& s,
876  const string& delimiters)
877 {
878  return trim_left_copy( trim_right_copy( s, delimiters ), delimiters );
879 }
880 
881 void UserInputForTests::readGeometricGenTestData(string path,
882  string testData)
883 {
884 
885  std::ostringstream fname;
886  fname << path << "/" << testData << ".txt";
887 
888  RCP<default_znode_t> dnode = rcp (new default_znode_t ());
889  if (verbose_ && tcomm_->getRank() == 0)
890  std::cout << "UserInputForTests, Read: " << fname.str() << std::endl;
891 
892  Teuchos::ParameterList geoparams("geo params");
893  readGeoGenParams(fname.str(),geoparams);
894 
895  geometricgen_t * gg = new geometricgen_t(geoparams, this->tcomm_);
896 
897  // get coordinate and point info
898  int coord_dim = gg->getCoordinateDimension();
899  int numWeightsPerCoord = gg->getNumWeights();
900  zlno_t numLocalPoints = gg->getNumLocalCoords();
901  zgno_t numGlobalPoints = gg->getNumGlobalCoords();
902 
903  // allocate an array of coordinate arrays
904  zscalar_t **coords = new zscalar_t * [coord_dim];
905  for(int i = 0; i < coord_dim; ++i){
906  coords[i] = new zscalar_t[numLocalPoints];
907  }
908 
909  // get a copy of the data
910  gg->getLocalCoordinatesCopy(coords);
911 
912  // get an array of arrays of weight data (if any)
913  zscalar_t **weight = NULL;
914  if (numWeightsPerCoord) {
915  // memory allocation
916  weight = new zscalar_t * [numWeightsPerCoord];
917  for(int i = 0; i < numWeightsPerCoord; ++i){
918  weight[i] = new zscalar_t[numLocalPoints];
919  }
920 
921  // get a copy of the weight data
922  gg->getLocalWeightsCopy(weight);
923  }
924 
925  delete gg; // free up memory from geom gen
926 
927 
928  // make a Tpetra map
929  RCP<Tpetra::Map<zlno_t, zgno_t, znode_t> > mp =
930  rcp(new Tpetra::Map<zlno_t, zgno_t, znode_t>(numGlobalPoints, numLocalPoints, 0, this->tcomm_));
931 
932  // make an array of array views containing the coordinate data
933  Teuchos::Array<Teuchos::ArrayView<const zscalar_t> > coordView(coord_dim);
934  for (int i=0; i < coord_dim; i++){
935  if(numLocalPoints > 0){
936  Teuchos::ArrayView<const zscalar_t> a(coords[i], numLocalPoints);
937  coordView[i] = a;
938  }
939  else {
940  Teuchos::ArrayView<const zscalar_t> a;
941  coordView[i] = a;
942  }
943  }
944 
945  // set the xyz_ multivector
946  xyz_ = RCP<tMVector_t>(new
947  tMVector_t(mp, coordView.view(0, coord_dim),
948  coord_dim));
949 
950  // set the vtx weights
951  if (numWeightsPerCoord) {
952  // make an array of array views containing the weight data
953  Teuchos::Array<Teuchos::ArrayView<const zscalar_t> > weightView(numWeightsPerCoord);
954  for (int i=0; i < numWeightsPerCoord; i++){
955  if(numLocalPoints > 0){
956  Teuchos::ArrayView<const zscalar_t> a(weight[i], numLocalPoints);
957  weightView[i] = a;
958  }
959  else {
960  Teuchos::ArrayView<const zscalar_t> a;
961  weightView[i] = a;
962  }
963  }
964 
965  vtxWeights_ = RCP<tMVector_t>(new tMVector_t(mp, weightView.view(0, numWeightsPerCoord),
966  numWeightsPerCoord));
967  }
968 }
969 
970 void UserInputForTests::readGeoGenParams(string paramFileName,
971  ParameterList &geoparams){
972 
973  const char param_comment = '#';
974 
975  std::string input = "";
976  char inp[25000];
977  for(int i = 0; i < 25000; ++i){
978  inp[i] = 0;
979  }
980 
981  bool fail = false;
982  if(this->tcomm_->getRank() == 0){
983 
984  fstream inParam(paramFileName.c_str());
985  if (inParam.fail())
986  {
987  fail = true;
988  }
989  if(!fail)
990  {
991  std::string tmp = "";
992  getline (inParam,tmp);
993  while (!inParam.eof()){
994  if(tmp != ""){
995  tmp = trim_copy(tmp);
996  if(tmp != ""){
997  input += tmp + "\n";
998  }
999  }
1000  getline (inParam,tmp);
1001  }
1002  inParam.close();
1003  for (size_t i = 0; i < input.size(); ++i){
1004  inp[i] = input[i];
1005  }
1006  }
1007  }
1008 
1009 
1010 
1011  int size = (int)input.size();
1012  if(fail){
1013  size = -1;
1014  }
1015  this->tcomm_->broadcast(0, sizeof(int), (char*) &size);
1016  if(size == -1){
1017  throw "File " + paramFileName + " cannot be opened.";
1018  }
1019  this->tcomm_->broadcast(0, size, inp);
1020  istringstream inParam(inp);
1021  string str;
1022  getline (inParam,str);
1023  while (!inParam.eof()){
1024  if(str[0] != param_comment){
1025  size_t pos = str.find('=');
1026  if(pos == string::npos){
1027  throw "Invalid Line:" + str + " in parameter file";
1028  }
1029  string paramname = trim_copy(str.substr(0,pos));
1030  string paramvalue = trim_copy(str.substr(pos + 1));
1031  geoparams.set(paramname, paramvalue);
1032  }
1033  getline (inParam,str);
1034  }
1035 }
1036 
1037 void UserInputForTests::readMatrixMarketFile(string path, string testData, bool distributeInput)
1038 {
1039  std::ostringstream fname;
1040  fname << path << "/" << testData << ".mtx";
1041 
1042  RCP<default_znode_t> dnode = rcp (new default_znode_t ());
1043  if (verbose_ && tcomm_->getRank() == 0)
1044  std::cout << "UserInputForTests, Read: " << fname.str() << std::endl;
1045 
1046  // This reader has some problems. "Pattern" matrices
1047  // cannot be read. Until the
1048  // reader is fixed, we'll have to get inputs that are consistent with
1049  // the reader. (Tpetra bug 5611 and 5624)
1050 
1051  RCP<tcrsMatrix_t> toMatrix;
1052  RCP<tcrsMatrix_t> fromMatrix;
1053  bool aok = true;
1054  try{
1055  fromMatrix = Tpetra::MatrixMarket::Reader<tcrsMatrix_t>::readSparseFile(
1056  fname.str(), tcomm_, dnode, true, true, false);
1057  if(!distributeInput)
1058  {
1059  if (verbose_ && tcomm_->getRank() == 0)
1060  std::cout << "Constructing serial distribution of matrix" << std::endl;
1061  // need to make a serial map and then import the data to redistribute it
1062  RCP<const map_t> fromMap = fromMatrix->getRowMap();
1063 
1064  size_t numGlobalCoords = fromMap->getGlobalNumElements();
1065  size_t numLocalCoords = this->tcomm_->getRank() == 0 ? numGlobalCoords : 0;
1066  RCP<const map_t> toMap = rcp(new map_t(numGlobalCoords,numLocalCoords, 0, tcomm_));
1067 
1068  RCP<import_t> importer = rcp(new import_t(fromMap, toMap));
1069  toMatrix = rcp(new tcrsMatrix_t(toMap,0));
1070  toMatrix->doImport(*fromMatrix, *importer, Tpetra::INSERT);
1071  toMatrix->fillComplete();
1072 
1073  }else{
1074  toMatrix = fromMatrix;
1075  }
1076  }catch (std::exception &e) {
1077  if (tcomm_->getRank() == 0)
1078  std::cout << "UserInputForTests unable to read matrix market file:"
1079  << fname.str() << std::endl;
1080  aok = false;
1081  }
1082  TEST_FAIL_AND_THROW(*tcomm_, aok,
1083  "UserInputForTests unable to read matrix market file");
1084 
1085  M_ = toMatrix;
1086 
1088 
1089  // Open the coordinate file.
1090 
1091  fname.str("");
1092  fname << path << "/" << testData << "_coord.mtx";
1093 
1094  size_t coordDim = 0, numGlobalCoords = 0;
1095  size_t msg[2]={0,0};
1096  ArrayRCP<ArrayRCP<zscalar_t> > xyz;
1097  std::ifstream coordFile;
1098 
1099  if (tcomm_->getRank() == 0){
1100 
1101  if (verbose_)
1102  std::cout << "UserInputForTests, Read: " <<
1103  fname.str() << std::endl;
1104 
1105  int fail = 0;
1106  try{
1107  coordFile.open(fname.str().c_str());
1108  }
1109  catch (std::exception &e){ // there is no coordinate file
1110  fail = 1;
1111  }
1112 
1113  if (!fail){
1114 
1115  // Read past banner to number and dimension of coordinates.
1116 
1117  char c[256];
1118  bool done=false;
1119 
1120  while (!done && !fail && coordFile.good()){
1121  coordFile.getline(c, 256);
1122  if (!c[0])
1123  fail = 1;
1124  else if (c[0] == '%')
1125  continue;
1126  else {
1127  done=true;
1128  std::istringstream s(c);
1129  s >> numGlobalCoords >> coordDim;
1130  if (!s.eof() || numGlobalCoords < 1 || coordDim < 1)
1131  fail=1;
1132  }
1133  }
1134 
1135  if (done){
1136 
1137  // Read in the coordinates.
1138 
1139  xyz = Teuchos::arcp(new ArrayRCP<zscalar_t> [coordDim], 0, coordDim);
1140 
1141  for (size_t dim=0; !fail && dim < coordDim; dim++){
1142  size_t idx;
1143  zscalar_t *tmp = new zscalar_t [numGlobalCoords];
1144  if (!tmp)
1145  fail = 1;
1146  else{
1147  xyz[dim] = Teuchos::arcp(tmp, 0, numGlobalCoords);
1148 
1149  for (idx=0; !coordFile.eof() && idx < numGlobalCoords; idx++){
1150  coordFile.getline(c, 256);
1151  std::istringstream s(c);
1152  s >> tmp[idx];
1153  }
1154 
1155  if (idx < numGlobalCoords)
1156  fail = 1;
1157  }
1158  }
1159 
1160  if (fail){
1161  ArrayRCP<zscalar_t> emptyArray;
1162  for (size_t dim=0; dim < coordDim; dim++)
1163  xyz[dim] = emptyArray; // free the memory
1164 
1165  coordDim = 0;
1166  }
1167  }
1168  else{
1169  fail = 1;
1170  }
1171 
1172  coordFile.close();
1173  }
1174 
1175  msg[0] = coordDim;
1176  msg[1] = numGlobalCoords;
1177  }
1178 
1179  // Broadcast coordinate dimension
1180  Teuchos::broadcast<int, size_t>(*tcomm_, 0, 2, msg);
1181 
1182  coordDim = msg[0];
1183  numGlobalCoords = msg[1];
1184 
1185  if (coordDim == 0)
1186  return;
1187 
1188  zgno_t base;
1189  RCP<const map_t> toMap;
1190 
1191  if (!M_.is_null()){
1192  base = M_->getIndexBase();
1193  const RCP<const map_t> &mapM = M_->getRowMap();
1194  toMap = mapM;
1195  }
1196  else{
1197  if (verbose_ && tcomm_->getRank() == 0)
1198  {
1199  std::cout << "Matrix was null. ";
1200  std::cout << "Constructing distribution map for coordinate vector." << std::endl;
1201  }
1202 
1203  base = 0;
1204  if(!distributeInput)
1205  {
1206  if (verbose_ && tcomm_->getRank() == 0)
1207  std::cout << "Constructing serial distribution map for coordinates." << std::endl;
1208 
1209  size_t numLocalCoords = this->tcomm_->getRank() == 0 ? numGlobalCoords : 0;
1210  toMap = rcp(new map_t(numGlobalCoords,numLocalCoords, base, tcomm_));
1211  }else{
1212  toMap = rcp(new map_t(numGlobalCoords, base, tcomm_));
1213  }
1214  }
1215 
1216  // Export coordinates to their owners
1217 
1218  xyz_ = rcp(new tMVector_t(toMap, coordDim));
1219 
1220  ArrayRCP<ArrayView<const zscalar_t> > coordLists(coordDim);
1221 
1222  if (tcomm_->getRank() == 0){
1223 
1224  for (size_t dim=0; dim < coordDim; dim++)
1225  coordLists[dim] = xyz[dim].view(0, numGlobalCoords);
1226 
1227  zgno_t *tmp = new zgno_t [numGlobalCoords];
1228  if (!tmp)
1229  throw std::bad_alloc();
1230 
1231  ArrayRCP<const zgno_t> rowIds = Teuchos::arcp(tmp, 0, numGlobalCoords);
1232 
1233  zgno_t basePlusNumGlobalCoords = base + static_cast<zgno_t>(numGlobalCoords);
1234  for (zgno_t id=base; id < basePlusNumGlobalCoords; id++)
1235  *tmp++ = id;
1236 
1237  RCP<const map_t> fromMap = rcp(new map_t(numGlobalCoords,
1238  rowIds.view(0, numGlobalCoords), base, tcomm_));
1239 
1240  tMVector_t allCoords(fromMap, coordLists.view(0, coordDim), coordDim);
1241 
1242  export_t exporter(fromMap, toMap);
1243 
1244  xyz_->doExport(allCoords, exporter, Tpetra::INSERT);
1245  }
1246  else{
1247 
1248  RCP<const map_t> fromMap = rcp(new map_t(numGlobalCoords,
1249  ArrayView<zgno_t>(), base, tcomm_));
1250 
1251  tMVector_t allCoords(fromMap, coordLists.view(0, coordDim), coordDim);
1252 
1253  export_t exporter(fromMap, toMap);
1254 
1255  xyz_->doExport(allCoords, exporter, Tpetra::INSERT);
1256  }
1257 }
1258 
1259 void UserInputForTests::buildCrsMatrix(int xdim, int ydim, int zdim,
1260  string problemType, bool distributeInput)
1261 {
1262 #ifdef HAVE_ZOLTAN2_GALERI
1263  Teuchos::CommandLineProcessor tclp;
1264  Galeri::Xpetra::Parameters<zgno_t> params(tclp,
1265  xdim, ydim, zdim, problemType);
1266 
1267  RCP<const Tpetra::Map<zlno_t, zgno_t> > map;
1268  if (distributeInput)
1269  map = rcp(new Tpetra::Map<zlno_t, zgno_t>(params.GetNumGlobalElements(),
1270  0, tcomm_));
1271  else {
1272  // All data initially on rank 0
1273  size_t nGlobalElements = params.GetNumGlobalElements();
1274  size_t nLocalElements = ((tcomm_->getRank() == 0) ? nGlobalElements : 0);
1275  map = rcp(new Tpetra::Map<zlno_t, zgno_t>(nGlobalElements, nLocalElements, 0,
1276  tcomm_));
1277  }
1278 
1279  if (verbose_ && tcomm_->getRank() == 0){
1280 
1281  std::cout << "Matrix is " << (distributeInput ? "" : "not");
1282  std::cout << "distributed." << endl;
1283 
1284  std::cout << "UserInputForTests, Create matrix with " << problemType;
1285  std::cout << " (and " << xdim;
1286  if (zdim > 0)
1287  std::cout << " x " << ydim << " x " << zdim;
1288  else if (ydim > 0)
1289  std::cout << " x" << ydim << " x 1";
1290  else
1291  std::cout << "x 1 x 1";
1292 
1293  std::cout << " mesh)" << std::endl;
1294 
1295  }
1296 
1297  bool aok = true;
1298  try{
1299  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 =
1300  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> >
1301  (params.GetMatrixType(), map, params.GetParameterList());
1302  M_ = Pr->BuildMatrix();
1303  }
1304  catch (std::exception &e) { // Probably not enough memory
1305  aok = false;
1306  }
1307  TEST_FAIL_AND_THROW(*tcomm_, aok,
1308  "UserInputForTests Galeri::Xpetra::BuildProblem failed");
1309 
1311 
1312  // Compute the coordinates for the matrix rows.
1313 
1314  if (verbose_ && tcomm_->getRank() == 0)
1315  std::cout <<
1316  "UserInputForTests, Implied matrix row coordinates computed" <<
1317  std::endl;
1318 
1319  ArrayView<const zgno_t> gids = map->getNodeElementList();
1320  zlno_t count = static_cast<zlno_t>(gids.size());
1321  int dim = 3;
1322  size_t pos = problemType.find("2D");
1323  if (pos != string::npos)
1324  dim = 2;
1325  else if (problemType == string("Laplace1D") ||
1326  problemType == string("Identity"))
1327  dim = 1;
1328 
1329  Array<ArrayRCP<zscalar_t> > coordinates(dim);
1330 
1331  if (count > 0){
1332  for (int i=0; i < dim; i++){
1333  zscalar_t *c = new zscalar_t [count];
1334  if (!c)
1335  throw(std::bad_alloc());
1336  coordinates[i] = Teuchos::arcp(c, 0, count, true);
1337  }
1338 
1339  if (dim==3){
1340  zscalar_t *x = coordinates[0].getRawPtr();
1341  zscalar_t *y = coordinates[1].getRawPtr();
1342  zscalar_t *z = coordinates[2].getRawPtr();
1343  zgno_t xySize = xdim * ydim;
1344  for (zlno_t i=0; i < count; i++){
1345  zgno_t iz = gids[i] / xySize;
1346  zgno_t xy = gids[i] - iz*xySize;
1347  z[i] = zscalar_t(iz);
1348  y[i] = zscalar_t(xy / xdim);
1349  x[i] = zscalar_t(xy % xdim);
1350  }
1351  }
1352  else if (dim==2){
1353  zscalar_t *x = coordinates[0].getRawPtr();
1354  zscalar_t *y = coordinates[1].getRawPtr();
1355  for (zlno_t i=0; i < count; i++){
1356  y[i] = zscalar_t(gids[i] / xdim);
1357  x[i] = zscalar_t(gids[i] % xdim);
1358  }
1359  }
1360  else{
1361  zscalar_t *x = coordinates[0].getRawPtr();
1362  for (zlno_t i=0; i < count; i++)
1363  x[i] = zscalar_t(gids[i]);
1364  }
1365  }
1366 
1367  Array<ArrayView<const zscalar_t> > coordView(dim);
1368  if (count > 0)
1369  for (int i=0; i < dim; i++)
1370  coordView[i] = coordinates[i].view(0,count);
1371 
1372  xyz_ = rcp(new tMVector_t(map, coordView.view(0, dim), dim));
1373 #else
1374  throw std::runtime_error("Galeri input requested but Trilinos is "
1375  "not built with Galeri.");
1376 #endif
1377 }
1378 
1379 void UserInputForTests::readZoltanTestData(string path, string testData,
1380  bool distributeInput)
1381 {
1382 
1383  int rank = tcomm_->getRank();
1384  FILE *graphFile = NULL;
1385  FILE *coordFile = NULL;
1386  FILE *assignFile = NULL;
1387  int fileInfo[3];
1388 
1389  if (rank == 0){
1390  // set chacho graph file name
1391  std::ostringstream chGraphFileName;
1392  chGraphFileName << path << "/" << testData << ".graph";
1393 
1394  // set chaco graph
1395  std::ostringstream chCoordFileName;
1396  chCoordFileName << path << "/" << testData << ".coords";
1397 
1398  // set chaco graph
1399  std::ostringstream chAssignFileName;
1400  chAssignFileName << path << "/" << testData << ".assign";
1401 
1402  // open file
1403  graphFile = fopen(chGraphFileName.str().c_str(), "r");
1404 
1405  if(!graphFile) // maybe the user is using the default zoltan1 path convention
1406  {
1407  chGraphFileName.str("");
1408  chCoordFileName.str("");
1409  // try constructing zoltan1 paths
1410  chGraphFileName << path << "/ch_" << testData << "/" << testData << ".graph";
1411  chCoordFileName << path << "/ch_" << testData << "/" << testData << ".coords";
1412  chAssignFileName << path << "/ch_" << testData << "/" << testData << ".assign";
1413  // try to open the graph file again, if this doesn't open
1414  // the user has not provided a valid path to the file
1415  graphFile = fopen(chGraphFileName.str().c_str(), "r");
1416  }
1417 
1418  memset(fileInfo, 0, sizeof(int) * 3); // set fileinfo to 0's
1419  if (graphFile){
1420  fileInfo[0] = 1;
1421  if (verbose_ && tcomm_->getRank() == 0)
1422  std::cout << "UserInputForTests, open " <<
1423  chGraphFileName.str () << std::endl;
1424 
1425  coordFile = fopen(chCoordFileName.str().c_str(), "r");
1426  if (coordFile){
1427  fileInfo[1] = 1;
1428  if (verbose_ && tcomm_->getRank() == 0)
1429  std::cout << "UserInputForTests, open " <<
1430  chCoordFileName.str () << std::endl;
1431  }
1432 
1433  assignFile = fopen(chAssignFileName.str().c_str(), "r");
1434  if (assignFile){
1435  fileInfo[2] = 1;
1436  if (verbose_ && tcomm_->getRank() == 0)
1437  std::cout << "UserInputForTests, open " <<
1438  chAssignFileName.str () << std::endl;
1439  }
1440  }else{
1441  if (verbose_ && tcomm_->getRank() == 0){
1442  std::cout << "UserInputForTests, unable to open file: ";
1443  std::cout << chGraphFileName.str() << std::endl;
1444  }
1445  }
1446  }
1447 
1448  // broadcast whether we have graphs and coords to all processes
1449  Teuchos::broadcast<int, int>(*tcomm_, 0, 3, fileInfo);
1450 
1451  bool haveGraph = (fileInfo[0] == 1);
1452  bool haveCoords = (fileInfo[1] == 1);
1453  bool haveAssign = (fileInfo[2] == 1);
1454 
1455  if (haveGraph){
1456  // builds M_, vtxWeights_, and edgWeights_ and closes file.
1457  try{
1458  getUIChacoGraph(graphFile, haveAssign, assignFile,
1459  testData, distributeInput);
1460  }
1462 
1463  if (haveCoords){
1464  // builds xyz_ and closes the file.
1465  try{
1466  getUIChacoCoords(coordFile, testData);
1467  }
1469  }
1470  }
1471 
1473 }
1474 
1475 void UserInputForTests::getUIChacoGraph(FILE *fptr, bool haveAssign,
1476  FILE *assignFile, string fname,
1477  bool distributeInput)
1478 {
1479  int rank = tcomm_->getRank();
1480  int graphCounts[5];
1481  int nvtxs=0, nedges=0;
1482  int nVwgts=0, nEwgts=0;
1483  int *start = NULL, *adj = NULL;
1484  float *ewgts = NULL, *vwgts = NULL;
1485  size_t *nzPerRow = NULL;
1486  size_t maxRowLen = 0;
1487  zgno_t base = 0;
1488  ArrayRCP<const size_t> rowSizes;
1489  int fail = 0;
1490  bool haveEdges = true;
1491 
1492  if (rank == 0){
1493 
1494  memset(graphCounts, 0, 5*sizeof(int));
1495 
1496  // This function is in the Zoltan C-library.
1497 
1498  // Reads in the file and closes it when done.
1499  fail = chaco_input_graph(fptr, fname.c_str(), &start, &adj,
1500  &nvtxs, &nVwgts, &vwgts, &nEwgts, &ewgts);
1501 
1502  // There are Zoltan2 test graphs that have no edges.
1503 
1504  if (start == NULL)
1505  haveEdges = false;
1506 
1507  if (verbose_){
1508  std::cout << "UserInputForTests, " << nvtxs << " vertices,";
1509  if (haveEdges)
1510  std::cout << start[nvtxs] << " edges,";
1511  else
1512  std::cout << "no edges,";
1513  std::cout << nVwgts << " vertex weights, ";
1514  std::cout << nEwgts << " edge weights" << std::endl;
1515  }
1516 
1517  if (nvtxs==0)
1518  fail = true;
1519 
1520  if (fail){
1521  Teuchos::broadcast<int, int>(*tcomm_, 0, 5, graphCounts);
1522  throw std::runtime_error("Unable to read chaco file");
1523  }
1524 
1525  if (haveEdges)
1526  nedges = start[nvtxs];
1527 
1528  nzPerRow = new size_t [nvtxs];
1529  if (!nzPerRow)
1530  throw std::bad_alloc();
1531  rowSizes = arcp(nzPerRow, 0, nvtxs, true);
1532 
1533  if (haveEdges){
1534  for (int i=0; i < nvtxs; i++){
1535  nzPerRow[i] = start[i+1] - start[i];
1536  if (nzPerRow[i] > maxRowLen)
1537  maxRowLen = nzPerRow[i];
1538  }
1539  }
1540  else{
1541  memset(nzPerRow, 0, sizeof(size_t) * nvtxs);
1542  }
1543 
1544  if (haveEdges){
1545  free(start);
1546  start = NULL;
1547  }
1548 
1549  // Make sure base gid is zero.
1550 
1551  if (nedges){
1552  int chbase = adj[0];
1553  for (int i=1; i < nedges; i++)
1554  if (adj[i] < chbase)
1555  chbase = adj[i];
1556 
1557  if (chbase > 0){
1558  for (int i=0; i < nedges; i++)
1559  adj[i] -= chbase;
1560  }
1561  }
1562 
1563  graphCounts[0] = nvtxs;
1564  graphCounts[1] = nedges;
1565  graphCounts[2] = nVwgts;
1566  graphCounts[3] = nEwgts;
1567  graphCounts[4] = (int)maxRowLen; // size_t maxRowLen will fit; it is <= (int-int)
1568  }
1569 
1570  Teuchos::broadcast<int, int>(*tcomm_, 0, 5, graphCounts);
1571 
1572  if (graphCounts[0] == 0)
1573  throw std::runtime_error("Unable to read chaco file");
1574 
1575  haveEdges = (graphCounts[1] > 0);
1576 
1577  RCP<tcrsMatrix_t> fromMatrix;
1578  RCP<const map_t> fromMap;
1579 
1580  // Create a Tpetra::CrsMatrix where rank 0 has entire matrix.
1581 
1582  if (rank == 0){
1583  fromMap = rcp(new map_t(nvtxs, nvtxs, base, tcomm_));
1584 
1585  fromMatrix =
1586  rcp(new tcrsMatrix_t(fromMap, rowSizes, Tpetra::StaticProfile));
1587 
1588  if (haveEdges){
1589 
1590  zgno_t *edgeIds = new zgno_t [nedges];
1591  if (nedges && !edgeIds)
1592  throw std::bad_alloc();
1593  for (int i=0; i < nedges; i++)
1594  edgeIds[i] = adj[i];
1595 
1596  free(adj);
1597  adj = NULL;
1598 
1599  zgno_t *nextId = edgeIds;
1600  Array<zscalar_t> values(maxRowLen, 1.0);
1601 
1602  for (int i=0; i < nvtxs; i++){
1603  if (nzPerRow[i] > 0){
1604  ArrayView<const zgno_t> rowNz(nextId, nzPerRow[i]);
1605  fromMatrix->insertGlobalValues(i, rowNz, values.view(0,nzPerRow[i]));
1606  nextId += nzPerRow[i];
1607  }
1608  }
1609 
1610  delete [] edgeIds;
1611  edgeIds = NULL;
1612  }
1613 
1614  fromMatrix->fillComplete();
1615  }
1616  else{
1617  nvtxs = graphCounts[0];
1618  nedges = graphCounts[1];
1619  nVwgts = graphCounts[2];
1620  nEwgts = graphCounts[3];
1621  maxRowLen = graphCounts[4];
1622 
1623  // Create a Tpetra::CrsMatrix where rank 0 has entire matrix.
1624 
1625  fromMap = rcp(new map_t(nvtxs, 0, base, tcomm_));
1626 
1627  fromMatrix =
1628  rcp(new tcrsMatrix_t(fromMap, rowSizes, Tpetra::StaticProfile));
1629 
1630  fromMatrix->fillComplete();
1631  }
1632 
1633 
1634  RCP<const map_t> toMap;
1635  RCP<tcrsMatrix_t> toMatrix;
1636  RCP<import_t> importer;
1637 
1638  if (distributeInput) {
1639  if (haveAssign) {
1640  // Read assignments from Chaco assignment file
1641  short *assignments = new short[nvtxs];
1642  if (rank == 0) {
1643  fail = chaco_input_assign(assignFile, fname.c_str(), nvtxs, assignments);
1644  }
1645  // Broadcast coordinate dimension
1646  Teuchos::broadcast<int, short>(*tcomm_, 0, nvtxs, assignments);
1647 
1648  // Build map with my vertices
1649  Teuchos::Array<zgno_t> mine;
1650  for (int i = 0; i < nvtxs; i++) {
1651  if (assignments[i] == rank)
1652  mine.push_back(i);
1653  }
1654 
1655  Tpetra::global_size_t dummy =
1656  Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid();
1657  toMap = rcp(new map_t(dummy, mine(), base, tcomm_));
1658  delete [] assignments;
1659  }
1660  else {
1661  // Create a Tpetra::Map with default row distribution.
1662  toMap = rcp(new map_t(nvtxs, base, tcomm_));
1663  }
1664  toMatrix = rcp(new tcrsMatrix_t(toMap, maxRowLen));
1665 
1666  // Import the data.
1667  importer = rcp(new import_t(fromMap, toMap));
1668  toMatrix->doImport(*fromMatrix, *importer, Tpetra::INSERT);
1669  toMatrix->fillComplete();
1670  }
1671  else {
1672  toMap = fromMap;
1673  toMatrix = fromMatrix;
1674  }
1675 
1676  M_ = toMatrix;
1677 
1678  // Vertex weights, if any
1679 
1680  typedef ArrayRCP<const ArrayView<const zscalar_t> > arrayArray_t;
1681 
1682  if (nVwgts > 0){
1683 
1684  ArrayRCP<zscalar_t> weightBuf;
1685  ArrayView<const zscalar_t> *wgts = new ArrayView<const zscalar_t> [nVwgts];
1686 
1687  if (rank == 0){
1688  size_t len = nVwgts * nvtxs;
1689  zscalar_t *buf = new zscalar_t [len];
1690  if (!buf) throw std::bad_alloc();
1691  weightBuf = arcp(buf, 0, len, true);
1692 
1693  for (int widx=0; widx < nVwgts; widx++){
1694  wgts[widx] = ArrayView<const zscalar_t>(buf, nvtxs);
1695  float *vw = vwgts + widx;
1696  for (int i=0; i < nvtxs; i++, vw += nVwgts)
1697  buf[i] = *vw;
1698  buf += nvtxs;
1699  }
1700 
1701  free(vwgts);
1702  vwgts = NULL;
1703  }
1704 
1705  arrayArray_t vweights = arcp(wgts, 0, nVwgts, true);
1706 
1707  RCP<tMVector_t> fromVertexWeights =
1708  rcp(new tMVector_t(fromMap, vweights.view(0, nVwgts), nVwgts));
1709 
1710  RCP<tMVector_t> toVertexWeights;
1711  if (distributeInput) {
1712  toVertexWeights = rcp(new tMVector_t(toMap, nVwgts));
1713  toVertexWeights->doImport(*fromVertexWeights, *importer, Tpetra::INSERT);
1714  }
1715  else
1716  toVertexWeights = fromVertexWeights;
1717 
1718  vtxWeights_ = toVertexWeights;
1719  }
1720 
1721  // Edge weights, if any
1722 
1723  if (haveEdges && nEwgts > 0){
1724 
1725  ArrayRCP<zscalar_t> weightBuf;
1726  ArrayView<const zscalar_t> *wgts = new ArrayView<const zscalar_t> [nEwgts];
1727 
1728  toMap = rcp(new map_t(nedges, M_->getNodeNumEntries(), base, tcomm_));
1729 
1730  if (rank == 0){
1731  size_t len = nEwgts * nedges;
1732  zscalar_t *buf = new zscalar_t [len];
1733  if (!buf) throw std::bad_alloc();
1734  weightBuf = arcp(buf, 0, len, true);
1735 
1736  for (int widx=0; widx < nEwgts; widx++){
1737  wgts[widx] = ArrayView<const zscalar_t>(buf, nedges);
1738  float *ew = ewgts + widx;
1739  for (int i=0; i < nedges; i++, ew += nEwgts)
1740  buf[i] = *ew;
1741  buf += nedges;
1742  }
1743 
1744  free(ewgts);
1745  ewgts = NULL;
1746  fromMap = rcp(new map_t(nedges, nedges, base, tcomm_));
1747  }
1748  else{
1749  fromMap = rcp(new map_t(nedges, 0, base, tcomm_));
1750  }
1751 
1752  arrayArray_t eweights = arcp(wgts, 0, nEwgts, true);
1753 
1754  RCP<tMVector_t> fromEdgeWeights;
1755  RCP<tMVector_t> toEdgeWeights;
1756  RCP<import_t> edgeImporter;
1757  if (distributeInput) {
1758  fromEdgeWeights =
1759  rcp(new tMVector_t(fromMap, eweights.view(0, nEwgts), nEwgts));
1760  toEdgeWeights = rcp(new tMVector_t(toMap, nEwgts));
1761  edgeImporter = rcp(new import_t(fromMap, toMap));
1762  toEdgeWeights->doImport(*fromEdgeWeights, *edgeImporter, Tpetra::INSERT);
1763  }
1764  else
1765  toEdgeWeights = fromEdgeWeights;
1766 
1767  edgWeights_ = toEdgeWeights;
1768  }
1769 }
1770 
1771 void UserInputForTests::getUIChacoCoords(FILE *fptr, string fname)
1772 {
1773  int rank = tcomm_->getRank();
1774  int ndim=0;
1775  double *x=NULL, *y=NULL, *z=NULL;
1776  int fail = 0;
1777 
1778  size_t globalNumVtx = M_->getGlobalNumRows();
1779 
1780  if (rank == 0){
1781 
1782  // This function is from the Zoltan C-library.
1783 
1784  // Reads in the file and closes it when done.
1785  fail = chaco_input_geom(fptr, fname.c_str(), (int)globalNumVtx,
1786  &ndim, &x, &y, &z);
1787 
1788  if (fail)
1789  ndim = 0;
1790 
1791  if (verbose_){
1792  std::cout << "UserInputForTests, read " << globalNumVtx;
1793  std::cout << " " << ndim << "-dimensional coordinates." << std::endl;
1794  }
1795  }
1796 
1797  Teuchos::broadcast<int, int>(*tcomm_, 0, 1, &ndim);
1798 
1799  if (ndim == 0)
1800  throw std::runtime_error("Can't read coordinate file");
1801 
1802  ArrayRCP<ArrayRCP<const zscalar_t> > coords(ndim);
1803  zlno_t len = 0;
1804 
1805  if (rank == 0){
1806 
1807  for (int dim=0; dim < ndim; dim++){
1808  zscalar_t *v = new zscalar_t [globalNumVtx];
1809  if (!v)
1810  throw std::bad_alloc();
1811  coords[dim] = arcp<const zscalar_t>(v, 0, globalNumVtx, true);
1812  double *val = (dim==0 ? x : (dim==1 ? y : z));
1813  for (size_t i=0; i < globalNumVtx; i++)
1814  v[i] = zscalar_t(val[i]);
1815 
1816  free(val);
1817  }
1818 
1819  len = static_cast<zlno_t>(globalNumVtx);
1820  }
1821 
1822  RCP<const map_t> fromMap = rcp(new map_t(globalNumVtx, len, 0, tcomm_));
1823  RCP<const map_t> toMap = M_->getRowMap();
1824  RCP<import_t> importer = rcp(new import_t(fromMap, toMap));
1825 
1826  Array<ArrayView<const zscalar_t> > coordData;
1827  for (int dim=0; dim < ndim; dim++)
1828  coordData.push_back(coords[dim].view(0, len));
1829 
1830  RCP<tMVector_t> fromCoords =
1831  rcp(new tMVector_t(fromMap, coordData.view(0, ndim), ndim));
1832 
1833  RCP<tMVector_t> toCoords = rcp(new tMVector_t(toMap, ndim));
1834 
1835  toCoords->doImport(*fromCoords, *importer, Tpetra::INSERT);
1836 
1837  xyz_ = toCoords;
1838 
1839 }
1840 
1843 
1844 double UserInputForTests::chaco_read_val(
1845  FILE* infile, /* file to read value from */
1846  int *end_flag /* 0 => OK, 1 => EOL, -1 => EOF */
1847 )
1848 {
1849  double val; /* return value */
1850  char *ptr; /* ptr to next string to read */
1851  char *ptr2; /* ptr to next string to read */
1852  int length; /* length of line to read */
1853  int length_left;/* length of line still around */
1854  int white_seen; /* have I detected white space yet? */
1855  int done; /* checking for end of scan */
1856  int i; /* loop counter */
1857 
1858  *end_flag = 0;
1859 
1860  if (chaco_offset == 0 || chaco_offset >= chaco_break_pnt) {
1861  if (chaco_offset >= chaco_break_pnt) { /* Copy rest of line back to beginning. */
1862  length_left = CHACO_LINE_LENGTH - chaco_save_pnt - 1;
1863  ptr2 = chaco_line;
1864  ptr = &chaco_line[chaco_save_pnt];
1865  for (i=length_left; i; i--) *ptr2++ = *ptr++;
1866  length = chaco_save_pnt + 1;
1867  }
1868  else {
1869  length = CHACO_LINE_LENGTH;
1870  length_left = 0;
1871  }
1872 
1873  /* Now read next line, or next segment of current one. */
1874  ptr2 = fgets(&chaco_line[length_left], length, infile);
1875 
1876  if (ptr2 == (char *) NULL) { /* We've hit end of file. */
1877  *end_flag = -1;
1878  return((double) 0.0);
1879  }
1880 
1881  if ((chaco_line[CHACO_LINE_LENGTH - 2] != '\n') && (chaco_line[CHACO_LINE_LENGTH - 2] != '\f')
1882  && (strlen(chaco_line) == CHACO_LINE_LENGTH - 1)){
1883  /* Line too long. Find last safe place in chaco_line. */
1884  chaco_break_pnt = CHACO_LINE_LENGTH - 1;
1885  chaco_save_pnt = chaco_break_pnt;
1886  white_seen = 0;
1887  done = 0;
1888  while (!done) {
1889  --chaco_break_pnt;
1890  if (chaco_line[chaco_break_pnt] != '\0') {
1891  if (isspace((int)(chaco_line[chaco_break_pnt]))) {
1892  if (!white_seen) {
1893  chaco_save_pnt = chaco_break_pnt + 1;
1894  white_seen = 1;
1895  }
1896  }
1897  else if (white_seen) {
1898  done= 1;
1899  }
1900  }
1901  }
1902  }
1903  else {
1904  chaco_break_pnt = CHACO_LINE_LENGTH;
1905  }
1906 
1907  chaco_offset = 0;
1908  }
1909 
1910  while (isspace((int)(chaco_line[chaco_offset])) && chaco_offset < CHACO_LINE_LENGTH) chaco_offset++;
1911  if (chaco_line[chaco_offset] == '%' || chaco_line[chaco_offset] == '#') {
1912  *end_flag = 1;
1913  if (chaco_break_pnt < CHACO_LINE_LENGTH) {
1914  chaco_flush_line(infile);
1915  }
1916  return((double) 0.0);
1917  }
1918 
1919  ptr = &(chaco_line[chaco_offset]);
1920  val = strtod(ptr, &ptr2);
1921 
1922  if (ptr2 == ptr) { /* End of input line. */
1923  chaco_offset = 0;
1924  *end_flag = 1;
1925  return((double) 0.0);
1926  }
1927  else {
1928  chaco_offset = (int) (ptr2 - chaco_line) / sizeof(char);
1929  }
1930 
1931  return(val);
1932 }
1933 
1934 
1935 int UserInputForTests::chaco_read_int(
1936  FILE *infile, /* file to read value from */
1937  int *end_flag /* 0 => OK, 1 => EOL, -1 => EOF */
1938 )
1939 {
1940  int val; /* return value */
1941  char *ptr; /* ptr to next string to read */
1942  char *ptr2; /* ptr to next string to read */
1943  int length; /* length of line to read */
1944  int length_left; /* length of line still around */
1945  int white_seen; /* have I detected white space yet? */
1946  int done; /* checking for end of scan */
1947  int i; /* loop counter */
1948 
1949  *end_flag = 0;
1950 
1951  if (chaco_offset == 0 || chaco_offset >= chaco_break_pnt) {
1952  if (chaco_offset >= chaco_break_pnt) { /* Copy rest of line back to beginning. */
1953  length_left = CHACO_LINE_LENGTH - chaco_save_pnt - 1;
1954  ptr2 = chaco_line;
1955  ptr = &chaco_line[chaco_save_pnt];
1956  for (i=length_left; i; i--) *ptr2++ = *ptr++;
1957  length = chaco_save_pnt + 1;
1958  }
1959  else {
1960  length = CHACO_LINE_LENGTH;
1961  length_left = 0;
1962  }
1963 
1964  /* Now read next line, or next segment of current one. */
1965  ptr2 = fgets(&chaco_line[length_left], length, infile);
1966 
1967  if (ptr2 == (char *) NULL) { /* We've hit end of file. */
1968  *end_flag = -1;
1969  return(0);
1970  }
1971 
1972  if ((chaco_line[CHACO_LINE_LENGTH - 2] != '\n') && (chaco_line[CHACO_LINE_LENGTH - 2] != '\f')
1973  && (strlen(chaco_line) == CHACO_LINE_LENGTH - 1)){
1974  /* Line too long. Find last safe place in line. */
1975  chaco_break_pnt = CHACO_LINE_LENGTH - 1;
1976  chaco_save_pnt = chaco_break_pnt;
1977  white_seen = 0;
1978  done = 0;
1979  while (!done) {
1980  --chaco_break_pnt;
1981  if (chaco_line[chaco_break_pnt] != '\0') {
1982  if (isspace((int)(chaco_line[chaco_break_pnt]))) {
1983  if (!white_seen) {
1984  chaco_save_pnt = chaco_break_pnt + 1;
1985  white_seen = 1;
1986  }
1987  }
1988  else if (white_seen) {
1989  done= 1;
1990  }
1991  }
1992  }
1993  }
1994  else {
1995  chaco_break_pnt = CHACO_LINE_LENGTH;
1996  }
1997 
1998  chaco_offset = 0;
1999  }
2000 
2001  while (isspace((int)(chaco_line[chaco_offset])) && chaco_offset < CHACO_LINE_LENGTH) chaco_offset++;
2002  if (chaco_line[chaco_offset] == '%' || chaco_line[chaco_offset] == '#') {
2003  *end_flag = 1;
2004  if (chaco_break_pnt < CHACO_LINE_LENGTH) {
2005  chaco_flush_line(infile);
2006  }
2007  return(0);
2008  }
2009 
2010  ptr = &(chaco_line[chaco_offset]);
2011  val = (int) strtol(ptr, &ptr2, 10);
2012 
2013  if (ptr2 == ptr) { /* End of input chaco_line. */
2014  chaco_offset = 0;
2015  *end_flag = 1;
2016  return(0);
2017  }
2018  else {
2019  chaco_offset = (int) (ptr2 - chaco_line) / sizeof(char);
2020  }
2021 
2022  return(val);
2023 }
2024 
2025 void UserInputForTests::chaco_flush_line(
2026  FILE *infile /* file to read value from */
2027 )
2028 {
2029  char c; /* character being read */
2030 
2031  c = fgetc(infile);
2032  while (c != '\n' && c != '\f')
2033  c = fgetc(infile);
2034 }
2035 
2036 int UserInputForTests::chaco_input_graph(
2037  FILE *fin, /* input file */
2038  const char *inname, /* name of input file */
2039  int **start, /* start of edge list for each vertex */
2040  int **adjacency, /* edge list data */
2041  int *nvtxs, /* number of vertices in graph */
2042  int *nVwgts, /* # of vertex weights per node */
2043  float **vweights, /* vertex weight list data */
2044  int *nEwgts, /* # of edge weights per edge */
2045  float **eweights /* edge weight list data */
2046 )
2047 {
2048  int *adjptr; /* loops through adjacency data */
2049  float *ewptr; /* loops through edge weight data */
2050  int narcs; /* number of edges expected in graph */
2051  int nedges; /* twice number of edges really in graph */
2052  int nedge; /* loops through edges for each vertex */
2053  int flag; /* condition indicator */
2054  int skip_flag; /* should this edge be ignored? */
2055  int end_flag; /* indicates end of line or file */
2056  int vtx; /* vertex in graph */
2057  int line_num; /* line number in input file */
2058  int sum_edges; /* total number of edges read so far */
2059  int option = 0; /* input option */
2060  int using_ewgts; /* are edge weights in input file? */
2061  int using_vwgts; /* are vertex weights in input file? */
2062  int vtxnums; /* are vertex numbers in input file? */
2063  int vertex; /* current vertex being read */
2064  int new_vertex; /* new vertex being read */
2065  float weight; /* weight being read */
2066  float eweight; /* edge weight being read */
2067  int neighbor; /* neighbor of current vertex */
2068  int error_flag; /* error reading input? */
2069  int j; /* loop counters */
2070 
2071  /* Read first line of input (= nvtxs, narcs, option). */
2072  /* The (decimal) digits of the option variable mean: 1's digit not zero => input
2073  edge weights 10's digit not zero => input vertex weights 100's digit not zero
2074  => include vertex numbers */
2075 
2076  *start = NULL;
2077  *adjacency = NULL;
2078  *vweights = NULL;
2079  *eweights = NULL;
2080 
2081  error_flag = 0;
2082  line_num = 0;
2083 
2084  /* Read any leading comment lines */
2085  end_flag = 1;
2086  while (end_flag == 1) {
2087  *nvtxs = chaco_read_int(fin, &end_flag);
2088  ++line_num;
2089  }
2090  if (*nvtxs <= 0) {
2091  printf("ERROR in graph file `%s':", inname);
2092  printf(" Invalid number of vertices (%d).\n", *nvtxs);
2093  fclose(fin);
2094  return(1);
2095  }
2096 
2097  narcs = chaco_read_int(fin, &end_flag);
2098  if (narcs < 0) {
2099  printf("ERROR in graph file `%s':", inname);
2100  printf(" Invalid number of expected edges (%d).\n", narcs);
2101  fclose(fin);
2102  return(1);
2103  }
2104 
2105  /* Check if vertex or edge weights are used */
2106  if (!end_flag) {
2107  option = chaco_read_int(fin, &end_flag);
2108  }
2109  using_ewgts = option - 10 * (option / 10);
2110  option /= 10;
2111  using_vwgts = option - 10 * (option / 10);
2112  option /= 10;
2113  vtxnums = option - 10 * (option / 10);
2114 
2115  /* Get weight info from Chaco option */
2116  (*nVwgts) = using_vwgts;
2117  (*nEwgts) = using_ewgts;
2118 
2119  /* Read numbers of weights if they are specified separately */
2120  if (!end_flag && using_vwgts==1){
2121  j = chaco_read_int(fin, &end_flag);
2122  if (!end_flag) (*nVwgts) = j;
2123  }
2124  if (!end_flag && using_ewgts==1){
2125  j = chaco_read_int(fin, &end_flag);
2126  if (!end_flag) (*nEwgts) = j;
2127  }
2128 
2129  /* Discard rest of line */
2130  while (!end_flag)
2131  j = chaco_read_int(fin, &end_flag);
2132 
2133  /* Allocate space for rows and columns. */
2134  *start = (int *) malloc((unsigned) (*nvtxs + 1) * sizeof(int));
2135  if (narcs != 0)
2136  *adjacency = (int *) malloc((unsigned) (2 * narcs + 1) * sizeof(int));
2137  else
2138  *adjacency = NULL;
2139 
2140  if (using_vwgts)
2141  *vweights = (float *) malloc((unsigned) (*nvtxs) * (*nVwgts) * sizeof(float));
2142  else
2143  *vweights = NULL;
2144 
2145  if (using_ewgts)
2146  *eweights = (float *)
2147  malloc((unsigned) (2 * narcs + 1) * (*nEwgts) * sizeof(float));
2148  else
2149  *eweights = NULL;
2150 
2151  adjptr = *adjacency;
2152  ewptr = *eweights;
2153 
2154  sum_edges = 0;
2155  nedges = 0;
2156  (*start)[0] = 0;
2157  vertex = 0;
2158  vtx = 0;
2159  new_vertex = 1;
2160  while ((using_vwgts || vtxnums || narcs) && end_flag != -1) {
2161  ++line_num;
2162 
2163  /* If multiple input lines per vertex, read vertex number. */
2164  if (vtxnums) {
2165  j = chaco_read_int(fin, &end_flag);
2166  if (end_flag) {
2167  if (vertex == *nvtxs)
2168  break;
2169  printf("ERROR in graph file `%s':", inname);
2170  printf(" no vertex number in line %d.\n", line_num);
2171  fclose(fin);
2172  return (1);
2173  }
2174  if (j != vertex && j != vertex + 1) {
2175  printf("ERROR in graph file `%s':", inname);
2176  printf(" out-of-order vertex number in line %d.\n", line_num);
2177  fclose(fin);
2178  return (1);
2179  }
2180  if (j != vertex) {
2181  new_vertex = 1;
2182  vertex = j;
2183  }
2184  else
2185  new_vertex = 0;
2186  }
2187  else
2188  vertex = ++vtx;
2189 
2190  if (vertex > *nvtxs)
2191  break;
2192 
2193  /* If vertices are weighted, read vertex weight. */
2194  if (using_vwgts && new_vertex) {
2195  for (j=0; j<(*nVwgts); j++){
2196  weight = chaco_read_val(fin, &end_flag);
2197  if (end_flag) {
2198  printf("ERROR in graph file `%s':", inname);
2199  printf(" not enough weights for vertex %d.\n", vertex);
2200  fclose(fin);
2201  return (1);
2202  }
2203  (*vweights)[(vertex-1)*(*nVwgts)+j] = weight;
2204  }
2205  }
2206 
2207  nedge = 0;
2208 
2209  /* Read number of adjacent vertex. */
2210  neighbor = chaco_read_int(fin, &end_flag);
2211 
2212  while (!end_flag) {
2213  skip_flag = 0;
2214 
2215  if (using_ewgts) { /* Read edge weight if it's being input. */
2216  for (j=0; j<(*nEwgts); j++){
2217  eweight = chaco_read_val(fin, &end_flag);
2218 
2219  if (end_flag) {
2220  printf("ERROR in graph file `%s':", inname);
2221  printf(" not enough weights for edge (%d,%d).\n", vertex, neighbor);
2222  fclose(fin);
2223  return (1);
2224  }
2225 
2226  else {
2227  *ewptr++ = eweight;
2228  }
2229  }
2230  }
2231 
2232  /* Add edge to data structure. */
2233  if (!skip_flag) {
2234  if (++nedges > 2*narcs) {
2235  printf("ERROR in graph file `%s':", inname);
2236  printf(" at least %d adjacencies entered, but nedges = %d\n",
2237  nedges, narcs);
2238  fclose(fin);
2239  return (1);
2240  }
2241  *adjptr++ = neighbor;
2242  nedge++;
2243  }
2244 
2245  /* Read number of next adjacent vertex. */
2246  neighbor = chaco_read_int(fin, &end_flag);
2247  }
2248 
2249  sum_edges += nedge;
2250  (*start)[vertex] = sum_edges;
2251  }
2252 
2253  /* Make sure there's nothing else in file. */
2254  flag = 0;
2255  while (!flag && end_flag != -1) {
2256  chaco_read_int(fin, &end_flag);
2257  if (!end_flag)
2258  flag = 1;
2259  }
2260 
2261  (*start)[*nvtxs] = sum_edges;
2262 
2263  if (vertex != 0) { /* Normal file was read. */
2264  if (narcs) {
2265  }
2266  else { /* no edges, but did have vertex weights or vertex numbers */
2267  free(*start);
2268  *start = NULL;
2269  if (*adjacency != NULL)
2270  free(*adjacency);
2271  *adjacency = NULL;
2272  if (*eweights != NULL)
2273  free(*eweights);
2274  *eweights = NULL;
2275  }
2276  }
2277 
2278  else {
2279  /* Graph was empty */
2280  free(*start);
2281  if (*adjacency != NULL)
2282  free(*adjacency);
2283  if (*vweights != NULL)
2284  free(*vweights);
2285  if (*eweights != NULL)
2286  free(*eweights);
2287  *start = NULL;
2288  *adjacency = NULL;
2289  }
2290 
2291  fclose(fin);
2292 
2293  return (error_flag);
2294 }
2295 
2296 
2297 int UserInputForTests::chaco_input_geom(
2298  FILE *fingeom, /* geometry input file */
2299  const char *geomname, /* name of geometry file */
2300  int nvtxs, /* number of coordinates to read */
2301  int *igeom, /* dimensionality of geometry */
2302  double **x, /* coordinates of vertices */
2303  double **y,
2304  double **z
2305 )
2306 {
2307  double xc, yc, zc =0; /* first x, y, z coordinate */
2308  int nread; /* number of lines of coordinates read */
2309  int flag; /* any bad data at end of file? */
2310  int line_num; /* counts input lines in file */
2311  int end_flag; /* return conditional */
2312  int ndims; /* number of values in an input line */
2313  int i=0; /* loop counter */
2314 
2315  *x = *y = *z = NULL;
2316  line_num = 0;
2317  end_flag = 1;
2318  while (end_flag == 1) {
2319  xc = chaco_read_val(fingeom, &end_flag);
2320  ++line_num;
2321  }
2322 
2323  if (end_flag == -1) {
2324  printf("No values found in geometry file `%s'\n", geomname);
2325  fclose(fingeom);
2326  return (1);
2327  }
2328 
2329  ndims = 1;
2330  yc = chaco_read_val(fingeom, &end_flag);
2331  if (end_flag == 0) {
2332  ndims = 2;
2333  zc = chaco_read_val(fingeom, &end_flag);
2334  if (end_flag == 0) {
2335  ndims = 3;
2336  chaco_read_val(fingeom, &end_flag);
2337  if (!end_flag) {
2338  printf("Too many values on input line of geometry file `%s'\n",
2339  geomname);
2340 
2341  printf(" Maximum dimensionality is 3\n");
2342  fclose(fingeom);
2343  return (1);
2344  }
2345  }
2346  }
2347 
2348  *igeom = ndims;
2349 
2350  *x = (double *) malloc((unsigned) nvtxs * sizeof(double));
2351  (*x)[0] = xc;
2352  if (ndims > 1) {
2353  *y = (double *) malloc((unsigned) nvtxs * sizeof(double));
2354  (*y)[0] = yc;
2355  }
2356  if (ndims > 2) {
2357  *z = (double *) malloc((unsigned) nvtxs * sizeof(double));
2358  (*z)[0] = zc;
2359  }
2360 
2361  for (nread = 1; nread < nvtxs; nread++) {
2362  ++line_num;
2363  if (ndims == 1) {
2364  i = fscanf(fingeom, "%lf", &((*x)[nread]));
2365  }
2366  else if (ndims == 2) {
2367  i = fscanf(fingeom, "%lf%lf", &((*x)[nread]), &((*y)[nread]));
2368  }
2369  else if (ndims == 3) {
2370  i = fscanf(fingeom, "%lf%lf%lf", &((*x)[nread]), &((*y)[nread]),
2371  &((*z)[nread]));
2372  }
2373 
2374  if (i == EOF) {
2375  printf("Too few lines of values in geometry file; nvtxs=%d, but only %d read\n",
2376  nvtxs, nread);
2377  fclose(fingeom);
2378  return (1);
2379  }
2380  else if (i != ndims) {
2381  printf("Wrong number of values in line %d of geometry file `%s'\n",
2382  line_num, geomname);
2383  fclose(fingeom);
2384  return (1);
2385  }
2386  }
2387 
2388  /* Check for spurious extra stuff in file. */
2389  flag = 0;
2390  end_flag = 0;
2391  while (!flag && end_flag != -1) {
2392  chaco_read_val(fingeom, &end_flag);
2393  if (!end_flag)
2394  flag = 1;
2395  }
2396 
2397  fclose(fingeom);
2398 
2399  return (0);
2400 }
2401 
2402 // Chaco input assignments from filename.assign; copied from Zoltan
2403 
2404 int UserInputForTests::chaco_input_assign(
2405  FILE *finassign, /* input assignment file */
2406  const char *inassignname, /* name of input assignment file */
2407  int nvtxs, /* number of vertices to output */
2408  short *assignment) /* values to be printed */
2409 {
2410  int flag; /* logical conditional */
2411  int end_flag; /* return flag from read_int() */
2412  int i, j; /* loop counter */
2413 
2414  /* Get the assignment vector one line at a time, checking as you go. */
2415  /* First read past any comments at top. */
2416  end_flag = 1;
2417  while (end_flag == 1) {
2418  assignment[0] = chaco_read_int(finassign, &end_flag);
2419  }
2420 
2421  if (assignment[0] < 0) {
2422  printf("ERROR: Entry %d in assignment file `%s' less than zero (%d)\n",
2423  1, inassignname, assignment[0]);
2424  fclose(finassign);
2425  return (1);
2426  }
2427 
2428  if (end_flag == -1) {
2429  printf("ERROR: No values found in assignment file `%s'\n", inassignname);
2430  fclose(finassign);
2431  return (1);
2432  }
2433 
2434  flag = 0;
2435  if (assignment[0] > nvtxs)
2436  flag = assignment[1];
2437  for (i = 1; i < nvtxs; i++) {
2438  j = fscanf(finassign, "%hd", &(assignment[i]));
2439  if (j != 1) {
2440  printf("ERROR: Too few values in assignment file `%s'.\n", inassignname);
2441  fclose(finassign);
2442  return (1);
2443  }
2444  if (assignment[i] < 0) {
2445  printf("ERROR: Entry %d in assignment file `%s' less than zero (%d)\n",
2446  i+1, inassignname, assignment[i]);
2447  fclose(finassign);
2448  return (1);
2449  }
2450  if (assignment[i] > nvtxs) { /* warn since probably an error */
2451  if (assignment[i] > flag)
2452  flag = assignment[i];
2453  }
2454  }
2455 
2456  if (flag) {
2457  printf("WARNING: Possible error in assignment file `%s'\n", inassignname);
2458  printf(" More assignment sets (%d) than vertices (%d)\n", flag, nvtxs);
2459  }
2460 
2461  /* Check for spurious extra stuff in file. */
2462  flag = 0;
2463  end_flag = 0;
2464  while (!flag && end_flag != -1) {
2465  chaco_read_int(finassign, &end_flag);
2466  if (!end_flag)
2467  flag = 1;
2468  }
2469  if (flag) {
2470  printf("WARNING: Possible error in assignment file `%s'\n", inassignname);
2471  printf(" Numerical data found after expected end of file\n");
2472  }
2473 
2474  fclose(finassign);
2475  return (0);
2476 }
2477 
2478 // Pamgen Reader
2479 void UserInputForTests::readPamgenMeshFile(string path, string testData)
2480 {
2481 #ifdef HAVE_ZOLTAN2_PAMGEN
2482  int rank = this->tcomm_->getRank();
2483  if (verbose_ && tcomm_->getRank() == 0)
2484  std::cout << "UserInputForTestsBD::readPamgenFile, Read: " << testData << std::endl;
2485 
2486  size_t len;
2487  std::fstream file;
2488  int dimension;
2489  if (rank == 0){
2490  // set file name
2491  std::ostringstream meshFileName;
2492  meshFileName << path << "/" << testData << ".pmgen";
2493  // open file
2494 
2495  file.open(meshFileName.str(), ios::in);
2496 
2497  if(!file.is_open()) // may be a problem with path or filename
2498  {
2499  if(verbose_ && tcomm_->getRank() == 0)
2500  {
2501  std::cout << "Unable to open pamgen mesh: ";
2502  std::cout << meshFileName.str();
2503  std::cout <<"\nPlease check file path and name." << std::endl;
2504  }
2505  len = 0; // broadcaset 0 length ->will cause exit
2506  }else{
2507  // write to character array
2508  // get size of file
2509  file.seekg (0,file.end);
2510  len = file.tellg();
2511  file.seekg (0);
2512 
2513  // get dimension
2514  dimension = 2;
2515  std::string line;
2516  while(std::getline(file,line))
2517  {
2518  if( line.find("nz") != std::string::npos ||
2519  line.find("nphi") != std::string::npos)
2520  {
2521  dimension = 3;
2522  break;
2523  }
2524  }
2525 
2526  file.clear();
2527  file.seekg(0, ios::beg);
2528  }
2529  }
2530 
2531  // broadcast the file size
2532  this->tcomm_->broadcast(0,sizeof(int), (char *)&dimension);
2533  this->tcomm_->broadcast(0,sizeof(size_t),(char *)&len);
2534  this->tcomm_->barrier();
2535 
2536  if(len == 0){
2537  if(verbose_ && tcomm_->getRank() == 0)
2538  std::cout << "Pamgen Mesh file size == 0, exiting UserInputForTests early." << endl;
2539  return;
2540  }
2541 
2542  char * file_data = new char[len];
2543  file_data[len] = '\0'; // critical to null terminate buffer
2544  if(rank == 0){
2545  file.read(file_data,len); // if proc 0 then read file
2546  }
2547 
2548  // broadcast the file to the world
2549  this->tcomm_->broadcast(0,(int)len,file_data);
2550  this->tcomm_->barrier();
2551 
2552  // Create the PamgenMesh
2553 
2554  this->pamgen_mesh = rcp(new PamgenMesh);
2555  this->havePamgenMesh = true;
2556  pamgen_mesh->createMesh(file_data,dimension,this->tcomm_);
2557 
2558  // save mesh info
2559  pamgen_mesh->storeMesh();
2560  this->tcomm_->barrier();
2561 
2562  // set coordinates
2563  this->setPamgenCoordinateMV();
2564 
2565  // set adjacency graph
2566  this->setPamgenAdjacencyGraph();
2567 
2568  this->tcomm_->barrier();
2569  if(rank == 0) file.close();
2570  delete [] file_data;
2571 #else
2572  throw std::runtime_error("Pamgen requested but Trilinos "
2573  "not built with Pamgen");
2574 #endif
2575 }
2576 
2577 #ifdef HAVE_ZOLTAN2_PAMGEN
2578 void UserInputForTests::setPamgenCoordinateMV()
2579 {
2580  int dimension = pamgen_mesh->num_dim;
2581  // get coordinate and point info;
2582 // zlno_t numLocalPoints = pamgen_mesh->num_nodes;
2583 // zgno_t numGlobalPoints = pamgen_mesh->num_nodes_global;
2584  zgno_t numelements = pamgen_mesh->num_elem;
2585  zgno_t numGlobalElements = pamgen_mesh->num_elems_global;
2586  // allocate and set an array of coordinate arrays
2587  zscalar_t **elem_coords = new zscalar_t * [dimension];
2588  for(int i = 0; i < dimension; ++i){
2589  elem_coords[i] = new zscalar_t[numelements];
2590  memcpy(elem_coords[i],&pamgen_mesh->element_coord[i*numelements],sizeof(double) * numelements);
2591  }
2592 
2593  // make a Tpetra map
2594  typedef Tpetra::Map<zlno_t, zgno_t, znode_t> map_t;
2595  RCP<Tpetra::Map<zlno_t, zgno_t, znode_t> > mp;
2596  // mp = rcp(new map_t(numGlobalElements, numelements, 0, this->tcomm_)); // constructo 1
2597 
2598 // Array<zgno_t>::size_type numEltsPerProc = numelements;
2599  Array<zgno_t> elementList(numelements);
2600  for (Array<zgno_t>::size_type k = 0; k < numelements; ++k) {
2601  elementList[k] = pamgen_mesh->element_order_map[k];
2602  }
2603 
2604  mp = rcp (new map_t (numGlobalElements, elementList, 0, this->tcomm_)); // constructor 2
2605 
2606 
2607  // make an array of array views containing the coordinate data
2608  Teuchos::Array<Teuchos::ArrayView<const zscalar_t> > coordView(dimension);
2609  for (int i = 0; i < dimension; i++){
2610  if(numelements > 0){
2611  Teuchos::ArrayView<const zscalar_t> a(elem_coords[i], numelements);
2612  coordView[i] = a;
2613  }
2614  else {
2615  Teuchos::ArrayView<const zscalar_t> a;
2616  coordView[i] = a;
2617  }
2618  }
2619 
2620  // set the xyz_ multivector
2621  xyz_ = RCP<tMVector_t>(new
2622  tMVector_t(mp, coordView.view(0, dimension),
2623  dimension));
2624 }
2625 
2626 void UserInputForTests::setPamgenAdjacencyGraph()
2627 {
2628 // int rank = this->tcomm_->getRank();
2629 // if(rank == 0) cout << "Making a graph from our pamgen mesh...." << endl;
2630 
2631  // Define Types
2632 // typedef zlno_t lno_t;
2633 // typedef zgno_t gno_t;
2634  typedef Tpetra::Map<zlno_t, zgno_t, znode_t> map_t;
2635 
2636  // get info for setting up map
2637  size_t local_nodes = (size_t)this->pamgen_mesh->num_nodes;
2638  size_t local_els = (size_t)this->pamgen_mesh->num_elem;
2639 
2640  size_t global_els = (size_t)this->pamgen_mesh->num_elems_global; // global rows
2641  size_t global_nodes = (size_t)this->pamgen_mesh->num_nodes_global; //global columns
2642  // make map with global elements assigned to this mesh
2643  // make range map
2644 // if(rank == 0) cout << "Building Rowmap: " << endl;
2645  RCP<const map_t> rowMap = rcp(new map_t(global_els,0,this->tcomm_));
2646  RCP<const map_t> rangeMap = rowMap;
2647 
2648  // make domain map
2649  RCP<const map_t> domainMap = rcp(new map_t(global_nodes,0,this->tcomm_));
2650 
2651  // make the element-node adjacency matrix
2652  Teuchos::RCP<tcrsMatrix_t> C = rcp(new tcrsMatrix_t(rowMap,0));
2653 
2654 
2655  Array<zgno_t> g_el_ids(local_els);
2656  for (size_t k = 0; k < local_els; ++k) {
2657  g_el_ids[k] = pamgen_mesh->global_element_numbers[k]-1;
2658  }
2659 
2660  Array<zgno_t> g_node_ids(local_nodes);
2661  for (size_t k = 0; k < local_nodes; ++k) {
2662  g_node_ids[k] = pamgen_mesh->global_node_numbers[k]-1;
2663  }
2664 
2665  int blks = this->pamgen_mesh->num_elem_blk;
2666 
2667  zlno_t el_no = 0;
2668  zscalar_t one = static_cast<zscalar_t>(1);
2669 
2670 // if(rank == 0) cout << "Writing C... " << endl;
2671  for(int i = 0; i < blks; i++)
2672  {
2673  int el_per_block = this->pamgen_mesh->elements[i];
2674  int nodes_per_el = this->pamgen_mesh->nodes_per_element[i];
2675  int * connect = this->pamgen_mesh->elmt_node_linkage[i];
2676 
2677  for(int j = 0; j < el_per_block; j++)
2678  {
2679  const zgno_t gid = static_cast<zgno_t>(g_el_ids[el_no]);
2680  for(int k = 0; k < nodes_per_el; k++)
2681  {
2682  int g_node_i = g_node_ids[connect[j*nodes_per_el+k]-1];
2683  C->insertGlobalValues(gid,
2684  Teuchos::tuple<zgno_t>(g_node_i),
2685  Teuchos::tuple<zscalar_t>(one));
2686  }
2687  el_no++;
2688  }
2689  }
2690 
2691  C->fillComplete(domainMap, rangeMap);
2692 
2693 
2694  // Compute product C*C'
2695 // if(rank == 0) cout << "Compute Multiplication C... " << endl;
2696  RCP<tcrsMatrix_t> A = rcp(new tcrsMatrix_t(rowMap,0));
2697  Tpetra::MatrixMatrix::Multiply(*C, false, *C, true, *A);
2698 
2699  // remove entris not adjacent
2700  // make graph
2701 // if(rank == 0) cout << "Writing M_... " << endl;
2702  this->M_ = rcp(new tcrsMatrix_t(rowMap,0));
2703 
2704 // if(rank == 0) cout << "\nSetting graph of connectivity..." << endl;
2705  for(zgno_t gid : rowMap->getNodeElementList())
2706  {
2707  size_t numEntriesInRow = A->getNumEntriesInGlobalRow (gid);
2708  Array<zscalar_t> rowvals (numEntriesInRow);
2709  Array<zgno_t> rowinds (numEntriesInRow);
2710 
2711  // modified
2712  Array<zscalar_t> mod_rowvals;
2713  Array<zgno_t> mod_rowinds;
2714  A->getGlobalRowCopy (gid, rowinds (), rowvals (), numEntriesInRow);
2715  for (size_t i = 0; i < numEntriesInRow; i++) {
2716 // if (rowvals[i] == 2*(this->pamgen_mesh->num_dim-1))
2717 // {
2718  if (rowvals[i] >= 1)
2719  {
2720  mod_rowvals.push_back(one);
2721  mod_rowinds.push_back(rowinds[i]);
2722  }
2723  }
2724  this->M_->insertGlobalValues(gid, mod_rowinds, mod_rowvals);
2725  }
2726 
2727  this->M_->fillComplete();
2729  // if(rank == 0) cout << "Completed M... " << endl;
2730 
2731 }
2732 
2733 #endif
2734 
2735 #endif
#define TEST_FAIL_AND_THROW(comm, ok, s)
Xpetra::CrsGraph< zlno_t, zgno_t, znode_t > xcrsGraph_t
map_t::node_type default_znode_t
Tpetra::Import< zlno_t, zgno_t, znode_t > import_t
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
Tpetra::Map< zlno_t, zgno_t, znode_t > map_t
string trim_right_copy(const string &s, const string &delimiters=" \f\n\r\t\v")
Tpetra::CrsMatrix< zscalar_t, zlno_t, zgno_t, znode_t > tcrsMatrix_t
size_t global_size_t
void readGeoGenParams(string paramFileName, Teuchos::ParameterList &geoparams, const RCP< const Teuchos::Comm< int > > &comm)
double zscalar_t
Tpetra::MultiVector< zscalar_t, zlno_t, zgno_t, znode_t > tMVector_t
RCP< tMVector_t > getUIWeights()
USERINPUT_FILE_FORMATS
A class that generates typical user input for testing.
static void getUIRandomData(unsigned int seed, zlno_t length, zscalar_t min, zscalar_t max, ArrayView< ArrayRCP< zscalar_t > > data)
Generate lists of random scalars.
Traits of Xpetra classes, including migration method.
int zlno_t
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.
UserInputForTests(string path, string testData, const RCP< const Comm< int > > &c, bool debugInfo=false, bool distributeInput=true)
Constructor that reads in a matrix/graph from disk.
Tpetra::Export< zlno_t, zgno_t, znode_t > export_t
static RCP< tMVector_t > coordinates
string trim_copy(const string &s, const string &delimiters=" \f\n\r\t\v")
RCP< xcrsGraph_t > getUIXpetraCrsGraph()
RCP< xVector_t > getUIXpetraVector()
const char param_comment
RCP< xMVector_t > getUIXpetraMultiVector(int nvec)
bool hasInputDataType(const string &input_type)
RCP< tMVector_t > getUITpetraMultiVector(int nvec)
RCP< tVector_t > getUITpetraVector()
RCP< xcrsMatrix_t > getUIXpetraCrsMatrix()
Xpetra::CrsMatrix< zscalar_t, zlno_t, zgno_t, znode_t > xcrsMatrix_t
RCP< tcrsGraph_t > getUITpetraCrsGraph()
Xpetra::Vector< zscalar_t, zlno_t, zgno_t, znode_t > xVector_t
Xpetra::MultiVector< zscalar_t, zlno_t, zgno_t, znode_t > xMVector_t
static const std::string fail
RCP< tcrsMatrix_t > getUITpetraCrsMatrix()
RCP< tMVector_t > getUIEdgeWeights()
int zgno_t
string trim_left_copy(const string &s, const string &delimiters=" \f\n\r\t\v")
Tpetra::Vector< zscalar_t, zlno_t, zgno_t, znode_t > tVector_t
RCP< tMVector_t > getUICoordinates()
GeometricGen::GeometricGenerator< zscalar_t, zlno_t, zgno_t, znode_t > geometricgen_t
Tpetra::CrsGraph< zlno_t, zgno_t, znode_t > tcrsGraph_t