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 // @HEADER
2 // *****************************************************************************
3 // Galeri: Finite Element and Matrix Generation Package
4 //
5 // Copyright 2006 ETHZ/NTESS and the Galeri contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include <Tpetra_Core.hpp>
11 #include <Tpetra_MultiVector.hpp>
12 #include <Xpetra_Vector.hpp>
13 #include <Xpetra_CrsMatrix.hpp>
14 #include <Xpetra_CrsGraph.hpp>
15 
16 #include <Galeri_XpetraProblemFactory.hpp>
17 #include <Galeri_XpetraParameters.hpp>
18 
19 #include <Tpetra_KokkosCompat_DefaultNode.hpp>
20 
21 using Teuchos::Comm;
22 using Teuchos::RCP;
23 using Teuchos::rcp;
24 using Teuchos::rcp_const_cast;
25 
26 template <typename lno_t, typename gno_t, typename scalar_t>
27 int buildCrsMatrix(int xdim, int ydim, int zdim, std::string problemType,
28  RCP<const Teuchos::Comm<int> > &comm) {
29  if (comm->getRank() == 0) {
30  cout << "Create matrix with " << problemType;
31  cout << " (and " << xdim;
32  if (zdim > 0)
33  cout << " x " << ydim << " x " << zdim << " ";
34  else if (ydim > 0)
35  cout << " x" << ydim << " x 1 ";
36  else
37  cout << "x 1 x 1 ";
38  cout << " mesh)" << endl;
39 
40  cout << "Template Type Sizes: " << endl
41  << " sizeof(lno_t) = " << sizeof(lno_t) << " " << endl
42  << " sizeof(gno_t) = " << sizeof(gno_t) << " " << endl
43  << " sizeof(scalar_t) = " << sizeof(scalar_t) << endl;
44  }
45 
47  Galeri::Xpetra::Parameters<gno_t> params(tclp, xdim, ydim, zdim, problemType);
48 
49  if (comm->getRank() == 0) cout << "BUILD MAP" << endl;
51  rcp(new Tpetra::Map<lno_t, gno_t>(
52  params.GetNumGlobalElements(), 0, comm));
53 
54  if (comm->getRank() == 0) cout << "BUILD MATRIX" << endl;
55 
57  try {
59  Tpetra::CrsMatrix<scalar_t, lno_t, gno_t>,
60  Tpetra::MultiVector<scalar_t, lno_t, gno_t> > >
61  Pr =
62  Galeri::Xpetra::BuildProblem<scalar_t, lno_t, gno_t,
63  Tpetra::Map<lno_t, gno_t>,
64  Tpetra::CrsMatrix<scalar_t, lno_t, gno_t>,
65  Tpetra::MultiVector<scalar_t, lno_t, gno_t> >(params.GetMatrixType(), map, params.GetParameterList());
66  if (comm->getRank() == 0)
67  cout << "AFTER GALERI BuildProblem M_=" << M_ << endl;
68 
69  M_ = Pr->BuildMatrix();
70  if (comm->getRank() == 0)
71  cout << "AFTER GALERI BuildMatrix M_=" << M_ << endl;
72  } catch (std::exception &e) { // Probably not enough memory
73  cout << "Error returned from Galeri " << e.what() << endl;
74  exit(-1);
75  }
76  if (M_.is_null())
77  return 1;
78  else
79  return 0;
80 }
81 
82 int main(int narg, char **arg) {
83  int ierr, jerr;
84 
85  Tpetra::ScopeGuard mpiSession(&narg, &arg);
86  RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
87 
88  if (comm->getRank() == 0) cout << "TESTING WITH scalar_t == DOUBLE" << endl;
89  ierr = buildCrsMatrix<int, long, double>(10, 10, 10, std::string("Laplace3D"), comm);
90  if (comm->getRank() == 0 && !ierr)
91  cout << "SUCCESS for scalar_t == DOUBLE" << endl
92  << endl
93  << endl;
94 
95  if (comm->getRank() == 0) cout << "TESTING WITH scalar_t == FLOAT" << endl;
96  jerr = buildCrsMatrix<int, long, float>(10, 10, 10, std::string("Laplace3D"), comm);
97  if (comm->getRank() == 0 && !jerr)
98  cout << "SUCCESS for scalar_t == FLOAT" << endl
99  << endl
100  << endl;
101 
102  if (ierr)
103  cout << "FAIL: M_ was NULL for scalar_t == DOUBLE " << endl;
104  if (jerr)
105  cout << "FAIL: M_ was NULL for scalar_t == FLOAT " << endl;
106  if (!ierr && !jerr)
107  cout << "PASS" << endl;
108 }
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:27
int main(int argc, char *argv[])
Definition: CrsMatrix.cpp:29