Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
XpetraEpetraMatrix.cpp
Go to the documentation of this file.
1 // Program to debug segfaults being reported in CDASH when
2 // -D Kokkos_ENABLE_THREADS:BOOL=ON
3 // -D Tpetra_INST_PTHREAD:BOOL=ON
4 // Problem appears to be in creation of Xpetra::EpetraCrsMatrixT
5 
6 #include <Teuchos_RCP.hpp>
7 #include <Teuchos_DefaultComm.hpp>
8 #include <Teuchos_Comm.hpp>
9 
10 #include <Tpetra_Core.hpp>
11 #include <Tpetra_Map.hpp>
12 #include <Epetra_Map.h>
13 #include <Xpetra_EpetraCrsMatrix.hpp>
14 #include <Xpetra_EpetraUtils.hpp>
15 
16 
17 int main(int narg, char **arg)
18 {
19  using Teuchos::rcp;
20 
21  Tpetra::ScopeGuard tscope(&narg, &arg);
22  Teuchos::RCP<const Teuchos::Comm<int> > tcomm = Tpetra::getDefaultComm();
23  Teuchos::RCP<const Epetra_Comm> ecomm = Xpetra::toEpetra(tcomm);
24 
26  // Build a boring matrix
27 
28  const int nGlobRows = 50;
29  const Epetra_Map emap(nGlobRows, 0, *ecomm);
30  Epetra_CrsMatrix emat(Copy, emap, 1, true);
31  const double one = 1.;
32  for (int i = 0; i < emat.NumMyRows(); i++) {
33  int gid = emat.GCID(i);
34  emat.InsertGlobalValues(gid, 1, &one, &gid);
35  }
36  emat.FillComplete();
37 
39  // Test whether conversion from Epetra_CrsMatrix to Xpetra::EpetraCrsMatrixT
40  // gives a valid resulting matrix.
41 
42  std::cout << "Building Xpetra::EpetraCrsMatrixT from Epetra_CrsMatrix: "
43  << std::endl;
44 
45  Teuchos::RCP<Epetra_CrsMatrix> ematrcp = Teuchos::rcpFromRef(emat);
46  typedef Xpetra::EpetraCrsMatrixT<int, Tpetra::Map<>::node_type> xemat_t;
47  Teuchos::RCP<const xemat_t> xmat;
48 
49  bool aok_mat = true;
50  try {
51  xmat = rcp(new xemat_t(ematrcp));
52  }
53  catch (std::exception &e) {
54  std::cout << "Xpetra::EpetraCrsMatrixT threw an error "
55  << e.what() << std::endl;
56  aok_mat = false;
57  }
58 
59  if (aok_mat)
60  std::cout << "Building Xpetra::EpetraCrsMatrixT from Epetra_CrsMatrix: "
61  << "DONE with no errors caught " << std::endl;
62 
64  // Try the same thing with Epetra_Map and Xpetra::EpetraMapT
65 
66  std::cout << "Building Xpetra::EpetraMapT from Epetra_Map: "
67  << std::endl;
68 
69  Teuchos::RCP<const Epetra_BlockMap> emaprcp = Teuchos::rcpFromRef(emap);
70  typedef Xpetra::EpetraMapT<int, Tpetra::Map<>::node_type> xemap_t;
71  Teuchos::RCP<const xemap_t> xmap;
72 
73  bool aok_map = true;
74  try {
75  xmap = rcp(new xemap_t(emaprcp));
76  }
77  catch (std::exception &e) {
78  std::cout << "Xpetra::EpetraMapT threw an error "
79  << e.what() << std::endl;
80  aok_map = false;
81  }
82 
83  if (aok_map)
84  std::cout << "Building Xpetra::EpetraMapT from Epetra_Map: "
85  << "DONE with no errors caught " << std::endl;
86 
88  // Print some info from the classes
89 
90  std::cout << "Teuchos: Hello from "
91  << tcomm->getRank() << " of "
92  << tcomm->getSize() << std::endl;
93  std::cout << "Epetra_CrsMatrix: Hello from "
94  << ematrcp->Comm().MyPID() << " of "
95  << ematrcp->Comm().NumProc() << std::endl;
96  std::cout << "Epetra_Map: Hello from "
97  << emaprcp->Comm().MyPID() << " of "
98  << emaprcp->Comm().NumProc() << std::endl;
99  if (aok_mat)
100  std::cout << "Xpetra::EpetraCrsMatrixT: Hello from "
101  << xmat->getRowMap()->getComm()->getRank() << " of "
102  << xmat->getRowMap()->getComm()->getSize() << std::endl;
103  if (aok_map)
104  std::cout << "Xpetra::EpetraMapT: Hello from "
105  << xmap->getComm()->getRank() << " of "
106  << xmap->getComm()->getSize() << std::endl;
107 
108  return 0;
109 }
int main(int narg, char **arg)
Definition: coloring1.cpp:199