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