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::RCP;
22 using Teuchos::Comm;
23 using Teuchos::rcp;
24 using Teuchos::rcp_const_cast;
25 
26 
27 template <typename lno_t, typename gno_t, typename scalar_t>
28 int buildCrsMatrix(int xdim, int ydim, int zdim, std::string problemType,
29  RCP<const Teuchos::Comm<int> > &comm)
30 {
31  if (comm->getRank() == 0){
32  cout << "Create matrix with " << problemType;
33  cout << " (and " << xdim;
34  if (zdim > 0)
35  cout << " x " << ydim << " x " << zdim << " ";
36  else if (ydim > 0)
37  cout << " x" << ydim << " x 1 ";
38  else
39  cout << "x 1 x 1 ";
40  cout << " mesh)" << endl;
41 
42  cout << "Template Type Sizes: " << endl
43  << " sizeof(lno_t) = " << sizeof(lno_t) << " " << endl
44  << " sizeof(gno_t) = " << sizeof(gno_t) << " " << endl
45  << " sizeof(scalar_t) = " << sizeof(scalar_t) << endl;
46  }
47 
49  Galeri::Xpetra::Parameters<gno_t> params(tclp, xdim, ydim, zdim, problemType);
50 
51  if (comm->getRank() == 0) cout << "BUILD MAP" << endl;
53  rcp(new Tpetra::Map<lno_t, gno_t>(
54  params.GetNumGlobalElements(), 0, comm));
55 
56  if (comm->getRank() == 0) cout << "BUILD MATRIX" << endl;
57 
59  try{
61  Tpetra::CrsMatrix<scalar_t, lno_t, gno_t>,
62  Tpetra::MultiVector<scalar_t, lno_t, gno_t> > > Pr=
63  Galeri::Xpetra::BuildProblem<scalar_t, lno_t, gno_t,
64  Tpetra::Map<lno_t, gno_t>,
65  Tpetra::CrsMatrix<scalar_t, lno_t, gno_t>,
66  Tpetra::MultiVector<scalar_t, lno_t, gno_t> >
67  (params.GetMatrixType(), map, params.GetParameterList());
68  if (comm->getRank() == 0)
69  cout << "AFTER GALERI BuildProblem M_=" << M_ << endl;
70 
71  M_ = Pr->BuildMatrix();
72  if (comm->getRank() == 0)
73  cout << "AFTER GALERI BuildMatrix M_=" << M_ << endl;
74  }
75  catch (std::exception &e) { // Probably not enough memory
76  cout << "Error returned from Galeri " << e.what() << endl;
77  exit(-1);
78  }
79  if (M_.is_null())
80  return 1;
81  else
82  return 0;
83 }
84 
85 int main(int narg, char **arg)
86 {
87  int ierr, jerr;
88 
89  Tpetra::ScopeGuard mpiSession(&narg, &arg);
90  RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
91 
92  if (comm->getRank() == 0) cout << "TESTING WITH scalar_t == DOUBLE" << endl;
93  ierr = buildCrsMatrix<int, long, double>(10, 10, 10, std::string("Laplace3D"), comm);
94  if (comm->getRank() == 0 && !ierr)
95  cout << "SUCCESS for scalar_t == DOUBLE" << endl << endl << endl;
96 
97  if (comm->getRank() == 0) cout << "TESTING WITH scalar_t == FLOAT" << endl;
98  jerr = buildCrsMatrix<int, long, float>(10, 10, 10, std::string("Laplace3D"), comm);
99  if (comm->getRank() == 0 && !jerr)
100  cout << "SUCCESS for scalar_t == FLOAT" << endl << endl << 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:28
int main(int argc, char *argv[])
Definition: CrsMatrix.cpp:29