Galeri Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bug_5851.cpp
Go to the documentation of this file.
1 
2 #include <Tpetra_Core.hpp>
3 #include <Tpetra_MultiVector.hpp>
4 #include <Xpetra_Vector.hpp>
5 #include <Xpetra_CrsMatrix.hpp>
6 #include <Xpetra_CrsGraph.hpp>
7 
8 #include <Galeri_XpetraProblemFactory.hpp>
9 #include <Galeri_XpetraParameters.hpp>
10 
11 #include <Tpetra_KokkosCompat_DefaultNode.hpp>
12 
13 using Teuchos::RCP;
14 using Teuchos::Comm;
15 using Teuchos::rcp;
16 using Teuchos::rcp_const_cast;
17 
18 
19 template <typename lno_t, typename gno_t, typename scalar_t>
20 int buildCrsMatrix(int xdim, int ydim, int zdim, std::string problemType,
21  RCP<const Teuchos::Comm<int> > &comm)
22 {
23  if (comm->getRank() == 0){
24  cout << "Create matrix with " << problemType;
25  cout << " (and " << xdim;
26  if (zdim > 0)
27  cout << " x " << ydim << " x " << zdim << " ";
28  else if (ydim > 0)
29  cout << " x" << ydim << " x 1 ";
30  else
31  cout << "x 1 x 1 ";
32  cout << " mesh)" << endl;
33 
34  cout << "Template Type Sizes: " << endl
35  << " sizeof(lno_t) = " << sizeof(lno_t) << " " << endl
36  << " sizeof(gno_t) = " << sizeof(gno_t) << " " << endl
37  << " sizeof(scalar_t) = " << sizeof(scalar_t) << endl;
38  }
39 
41  Galeri::Xpetra::Parameters<gno_t> params(tclp, xdim, ydim, zdim, problemType);
42 
43  if (comm->getRank() == 0) cout << "BUILD MAP" << endl;
45  rcp(new Tpetra::Map<lno_t, gno_t>(
46  params.GetNumGlobalElements(), 0, comm));
47 
48  if (comm->getRank() == 0) cout << "BUILD MATRIX" << endl;
49 
51  try{
53  Tpetra::CrsMatrix<scalar_t, lno_t, gno_t>,
54  Tpetra::MultiVector<scalar_t, lno_t, gno_t> > > Pr=
55  Galeri::Xpetra::BuildProblem<scalar_t, lno_t, gno_t,
56  Tpetra::Map<lno_t, gno_t>,
57  Tpetra::CrsMatrix<scalar_t, lno_t, gno_t>,
58  Tpetra::MultiVector<scalar_t, lno_t, gno_t> >
59  (params.GetMatrixType(), map, params.GetParameterList());
60  if (comm->getRank() == 0)
61  cout << "AFTER GALERI BuildProblem M_=" << M_ << endl;
62 
63  M_ = Pr->BuildMatrix();
64  if (comm->getRank() == 0)
65  cout << "AFTER GALERI BuildMatrix M_=" << M_ << endl;
66  }
67  catch (std::exception &e) { // Probably not enough memory
68  cout << "Error returned from Galeri " << e.what() << endl;
69  exit(-1);
70  }
71  if (M_.is_null())
72  return 1;
73  else
74  return 0;
75 }
76 
77 int main(int narg, char **arg)
78 {
79  int ierr, jerr;
80 
81  Tpetra::ScopeGuard mpiSession(&narg, &arg);
82  RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
83 
84  if (comm->getRank() == 0) cout << "TESTING WITH scalar_t == DOUBLE" << endl;
85  ierr = buildCrsMatrix<int, long, double>(10, 10, 10, std::string("Laplace3D"), comm);
86  if (comm->getRank() == 0 && !ierr)
87  cout << "SUCCESS for scalar_t == DOUBLE" << endl << endl << endl;
88 
89  if (comm->getRank() == 0) cout << "TESTING WITH scalar_t == FLOAT" << endl;
90  jerr = buildCrsMatrix<int, long, float>(10, 10, 10, std::string("Laplace3D"), comm);
91  if (comm->getRank() == 0 && !jerr)
92  cout << "SUCCESS for scalar_t == FLOAT" << endl << endl << endl;
93 
94  if (ierr)
95  cout << "FAIL: M_ was NULL for scalar_t == DOUBLE " << endl;
96  if (jerr)
97  cout << "FAIL: M_ was NULL for scalar_t == FLOAT " << endl;
98  if (!ierr && !jerr)
99  cout << "PASS" << endl;
100 }
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
bool is_null(const RCP< T > &p)
int buildCrsMatrix(int xdim, int ydim, int zdim, std::string problemType, RCP< const Teuchos::Comm< int > > &comm)
Definition: bug_5851.cpp:20
int main(int argc, char *argv[])
Definition: CrsMatrix.cpp:61