Xpetra_EpetraCrsGraph.cpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
47 
48 #include "Xpetra_Exceptions.hpp"
49 #include "Xpetra_Utils.hpp"
50 #include "Xpetra_EpetraExport.hpp"
51 #include "Xpetra_EpetraImport.hpp"
52 
53 namespace Xpetra {
54 
55  // TODO: move that elsewhere
56  template<class GlobalOrdinal, class Node>
57  const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph<int, GlobalOrdinal, Node> > &graph) {
58  XPETRA_RCP_DYNAMIC_CAST(const EpetraCrsGraphT<GlobalOrdinal COMMA Node>, graph, epetraGraph, "toEpetra");
59  return *(epetraGraph->getEpetra_CrsGraph());
60  }
61 
62 #if 0
63  template<class EpetraGlobalOrdinal, class Node>
65  : graph_(Teuchos::rcp(new Epetra_CrsGraph(Copy, toEpetra<EpetraGlobalOrdinal,Node>(rowMap), maxNumEntriesPerRow, toEpetra(pftype)))) { }
66 #endif
67  // TODO: convert array size_t to int
68  // template<class EpetraGlobalOrdinal>
69  // EpetraCrsGraphT<EpetraGlobalOrdinal>::EpetraCrsGraphT(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype)
70  // : graph_(Teuchos::rcp(new Epetra_CrsGraph(Copy, toEpetra(rowMap), NumEntriesPerRowToAlloc.getRawPtr(), toEpetra(pftype)))) { }
71 #if 0
72  template<class EpetraGlobalOrdinal, class Node>
74  : graph_(Teuchos::rcp(new Epetra_CrsGraph(Copy, toEpetra<EpetraGlobalOrdinal,Node>(rowMap), toEpetra<EpetraGlobalOrdinal,Node>(colMap), maxNumEntriesPerRow, toEpetra(pftype)))) { }
75 #endif
76  // TODO: convert array size_t to int
77  // template<class EpetraGlobalOrdinal>
78  // EpetraCrsGraphT<EpetraGlobalOrdinal>::EpetraCrsGraphT(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype)
79  // : graph_(Teuchos::rcp(new Epetra_CrsGraph(Copy, toEpetra<EpetraGlobalOrdinal,Node>(rowMap), toEpetra<EpetraGlobalOrdinal,Node>(colMap), NumEntriesPerRowToAlloc.getRawPtr(), toEpetra(pftype)))) { }
80 #if 0
81  template<class EpetraGlobalOrdinal, class Node>
83  XPETRA_MONITOR("EpetraCrsGraphT::insertGlobalIndices");
84 
85  GlobalOrdinal* indices_rawPtr = const_cast<GlobalOrdinal*>(indices.getRawPtr()); // there is no const in the Epetra interface :(
86  XPETRA_ERR_CHECK(graph_->InsertGlobalIndices(globalRow, indices.size(), indices_rawPtr));
87  }
88 #endif
89 
90 #if 0
91  template<class EpetraGlobalOrdinal, class Node>
93  XPETRA_MONITOR("EpetraCrsGraphT::insertLocalIndices");
94 
95  int* indices_rawPtr = const_cast<int*>(indices.getRawPtr()); // there is no const in the Epetra interface :(
96  XPETRA_ERR_CHECK(graph_->InsertMyIndices(localRow, indices.size(), indices_rawPtr));
97  }
98 #endif
99 #if 0
100  template<class EpetraGlobalOrdinal, class Node>
102  XPETRA_MONITOR("EpetraCrsGraphT::getGlobalRowView");
103 
104  int numEntries;
105  GlobalOrdinal * eIndices;
106 
107  XPETRA_ERR_CHECK(graph_->ExtractGlobalRowView(GlobalRow, numEntries, eIndices));
108  if (numEntries == 0) { eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
109 
110  Indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
111  }
112 #endif
113 #if 0
114  template<class EpetraGlobalOrdinal, class Node>
116  XPETRA_MONITOR("EpetraCrsGraphT::getLocalRowView");
117 
118  int numEntries;
119  int * eIndices;
120 
121  XPETRA_ERR_CHECK(graph_->ExtractMyRowView(LocalRow, numEntries, eIndices));
122  if (numEntries == 0) { eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
123 
124  indices = ArrayView<const int>(eIndices, numEntries);
125  }
126 #endif
127 #if 0
128  template<class EpetraGlobalOrdinal, class Node>
130  XPETRA_MONITOR("EpetraCrsGraphT::fillComplete");
131 
132  graph_->FillComplete(toEpetra<EpetraGlobalOrdinal,Node>(domainMap), toEpetra<EpetraGlobalOrdinal,Node>(rangeMap));
133  bool doOptimizeStorage = true;
134  if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
135  if (doOptimizeStorage) graph_->OptimizeStorage();
136  }
137 #endif
138 #if 0
139  template<class EpetraGlobalOrdinal, class Node>
141  XPETRA_MONITOR("EpetraCrsGraphT::fillComplete");
142 
143  graph_->FillComplete();
144  bool doOptimizeStorage = true;
145  if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
146  if (doOptimizeStorage) graph_->OptimizeStorage();
147  }
148 #endif
149 #if 0
150  template<class EpetraGlobalOrdinal, class Node>
151  std::string EpetraCrsGraphT<EpetraGlobalOrdinal, Node>::description() const { XPETRA_MONITOR("EpetraCrsGraphT::description"); return "NotImplemented"; }
152 
153  template<class EpetraGlobalOrdinal, class Node>
155  XPETRA_MONITOR("EpetraCrsGraphT::describe");
156 
157  out << "EpetraCrsGraphT::describe : Warning, verbosity level is ignored by this method." << std::endl;
158  const Epetra_BlockMap rowmap = graph_->RowMap();
159  if (rowmap.Comm().MyPID() == 0) out << "** EpetraCrsGraphT **\n\nrowmap" << std::endl;
160  rowmap.Print(out);
161  graph_->Print(out);
162  }
163 #endif
164 
165  // TODO: move that elsewhere
166  template<class GlobalOrdinal, class Node>
168  toXpetra (const Epetra_CrsGraph &g)
169  {
170  RCP<const Epetra_CrsGraph> const_graph = rcp (new Epetra_CrsGraph (g));
171  RCP<Epetra_CrsGraph> graph =
172  Teuchos::rcp_const_cast<Epetra_CrsGraph> (const_graph);
174  }
175  //
176 #if 0
177  // TODO: use toEpetra()
178  template<class EpetraGlobalOrdinal, class Node>
181  XPETRA_MONITOR("EpetraCrsGraphT::doImport");
182 
183  XPETRA_DYNAMIC_CAST(const EpetraCrsGraphT<GlobalOrdinal COMMA Node>, source, tSource, "Xpetra::EpetraCrsGraphT::doImport only accept Xpetra::EpetraCrsGraphT as input arguments.");
184  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsGraphT::doImport only accept Xpetra::EpetraImportT as input arguments.");
185 
186  RCP<const Epetra_CrsGraph> v = tSource.getEpetra_CrsGraph();
187  int err = graph_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
188  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
189  }
190 #endif
191 #if 0
192  template<class EpetraGlobalOrdinal,class Node>
195  XPETRA_MONITOR("EpetraCrsGraphT::doExport");
196 
197  XPETRA_DYNAMIC_CAST(const EpetraCrsGraphT<GlobalOrdinal COMMA Node>, dest, tDest, "Xpetra::EpetraCrsGraphT::doImport only accept Xpetra::EpetraCrsGraphT as input arguments.");
198  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsGraphT::doImport only accept Xpetra::EpetraImportT as input arguments.");
199 
200  RCP<const Epetra_CrsGraph> v = tDest.getEpetra_CrsGraph();
201  int err = graph_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
202  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
203  }
204 #endif
205 #if 0
206  template<class EpetraGlobalOrdinal, class Node>
209  XPETRA_MONITOR("EpetraCrsGraphT::doImport");
210 
211  XPETRA_DYNAMIC_CAST(const EpetraCrsGraphT<GlobalOrdinal COMMA Node>, source, tSource, "Xpetra::EpetraCrsGraphT::doImport only accept Xpetra::EpetraCrsGraphT as input arguments.");
212  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsGraphT::doImport only accept Xpetra::EpetraImportT as input arguments.");
213 
214  RCP<const Epetra_CrsGraph> v = tSource.getEpetra_CrsGraph();
215  int err = graph_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
216  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
217 
218  }
219 #endif
220 #if 0
221  template<class EpetraGlobalOrdinal,class Node>
224  XPETRA_MONITOR("EpetraCrsGraphT::doExport");
225 
226  XPETRA_DYNAMIC_CAST(const EpetraCrsGraphT<GlobalOrdinal COMMA Node>, dest, tDest, "Xpetra::EpetraCrsGraphT::doImport only accept Xpetra::EpetraCrsGraphT as input arguments.");
227  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsGraphT::doImport only accept Xpetra::EpetraImportT as input arguments.");
228 
229  RCP<const Epetra_CrsGraph> v = tDest.getEpetra_CrsGraph();
230  int err = graph_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
231  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
232  }
233 #endif
234 
235 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
236 
237 #ifdef HAVE_XPETRA_TPETRA
238 #ifdef HAVE_XPETRA_SERIAL
240 template RCP< const CrsGraph<int, int, Kokkos::Compat::KokkosSerialWrapperNode > > toXpetra<int, Kokkos::Compat::KokkosSerialWrapperNode>(const Epetra_CrsGraph &g);
241 template const Epetra_CrsGraph & toEpetra<int, Kokkos::Compat::KokkosSerialWrapperNode >(const RCP< const CrsGraph<int, int, Kokkos::Compat::KokkosSerialWrapperNode > > &graph);
242 #endif
243 #ifdef HAVE_XPETRA_PTHREAD
245 template RCP< const CrsGraph<int, int, Kokkos::Compat::KokkosThreadsWrapperNode > > toXpetra<int, Kokkos::Compat::KokkosThreadsWrapperNode>(const Epetra_CrsGraph &g);
246 template const Epetra_CrsGraph & toEpetra<int, Kokkos::Compat::KokkosThreadsWrapperNode >(const RCP< const CrsGraph<int, int, Kokkos::Compat::KokkosThreadsWrapperNode > > &graph);
247 #endif
248 #ifdef HAVE_XPETRA_OPENMP
250 template RCP< const CrsGraph<int, int, Kokkos::Compat::KokkosOpenMPWrapperNode > > toXpetra<int, Kokkos::Compat::KokkosOpenMPWrapperNode>(const Epetra_CrsGraph &g);
251 template const Epetra_CrsGraph & toEpetra<int, Kokkos::Compat::KokkosOpenMPWrapperNode >(const RCP< const CrsGraph<int, int, Kokkos::Compat::KokkosOpenMPWrapperNode > > &graph);
252 #endif
253 #ifdef HAVE_XPETRA_CUDA
254 typedef Kokkos::Compat::KokkosCudaWrapperNode default_node_type;
256 template RCP< const CrsGraph<int, int, default_node_type > > toXpetra<int, default_node_type>(const Epetra_CrsGraph &g);
257 template const Epetra_CrsGraph & toEpetra<int, default_node_type >(const RCP< const CrsGraph<int, int, default_node_type > > &graph);
258 #endif
259 #else
260 // Tpetra is disabled and Kokkos not available: use dummy node type
261 typedef Kokkos::Compat::KokkosSerialWrapperNode default_node_type;
263 template RCP< const CrsGraph<int, int, default_node_type > > toXpetra<int, default_node_type>(const Epetra_CrsGraph &g);
264 template const Epetra_CrsGraph & toEpetra<int, default_node_type >(const RCP< const CrsGraph<int, int, default_node_type > > &graph);
265 #endif // HAVE_XPETRA_TPETRA
266 #endif
267 
268 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
269 #ifdef HAVE_XPETRA_TPETRA
270 #ifdef HAVE_XPETRA_SERIAL
272 template RCP< const CrsGraph<int, long long, Kokkos::Compat::KokkosSerialWrapperNode > > toXpetra<long long, Kokkos::Compat::KokkosSerialWrapperNode>(const Epetra_CrsGraph &g);
273 template const Epetra_CrsGraph & toEpetra<long long, Kokkos::Compat::KokkosSerialWrapperNode >(const RCP< const CrsGraph<int, long long, Kokkos::Compat::KokkosSerialWrapperNode > > &graph);
274 #endif
275 #ifdef HAVE_XPETRA_PTHREAD
277 template RCP< const CrsGraph<int, long long, Kokkos::Compat::KokkosThreadsWrapperNode > > toXpetra<long long, Kokkos::Compat::KokkosThreadsWrapperNode>(const Epetra_CrsGraph &g);
278 template const Epetra_CrsGraph & toEpetra<long long, Kokkos::Compat::KokkosThreadsWrapperNode >(const RCP< const CrsGraph<int, long long, Kokkos::Compat::KokkosThreadsWrapperNode > > &graph);
279 #endif
280 #ifdef HAVE_XPETRA_OPENMP
282 template RCP< const CrsGraph<int, long long, Kokkos::Compat::KokkosOpenMPWrapperNode > > toXpetra<long long, Kokkos::Compat::KokkosOpenMPWrapperNode>(const Epetra_CrsGraph &g);
283 template const Epetra_CrsGraph & toEpetra<long long, Kokkos::Compat::KokkosOpenMPWrapperNode >(const RCP< const CrsGraph<int, long long, Kokkos::Compat::KokkosOpenMPWrapperNode > > &graph);
284 #endif
285 #ifdef HAVE_XPETRA_CUDA
286 typedef Kokkos::Compat::KokkosCudaWrapperNode default_node_type;
288 template RCP< const CrsGraph<int, long long, default_node_type > > toXpetra<long long, default_node_type>(const Epetra_CrsGraph &g);
289 template const Epetra_CrsGraph & toEpetra<long long, default_node_type >(const RCP< const CrsGraph<int, long long, default_node_type > > &graph);
290 #endif
291 #else
292 // Tpetra is disabled and Kokkos not available: use dummy node type
293 typedef Kokkos::Compat::KokkosSerialWrapperNode default_node_type;
295 template RCP< const CrsGraph<int, long long, default_node_type > > toXpetra<long long, default_node_type>(const Epetra_CrsGraph &g);
296 template const Epetra_CrsGraph & toEpetra<long long, default_node_type >(const RCP< const CrsGraph<int, long long, default_node_type > > &graph);
297 #endif // HAVE_XPETRA_TPETRA
298 #endif
299 
300 } // namespace Xpetra
T & get(const std::string &name, T def_value)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Xpetra namespace
size_type size() const
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal, Node > > &graph)
void insertGlobalIndices(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices)
Insert global indices into the graph.
void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=null)
Signal that data entry is complete, specifying domain and range maps.
void insertLocalIndices(const LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices)
Insert local indices into the graph.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
#define XPETRA_ERR_CHECK(arg)
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices) const
Return a const, nonpersisting view of local indices in the given row.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
T * getRawPtr() const
#define XPETRA_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
void doExport(const DistObject< GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
#define XPETRA_RCP_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
std::string description() const
Return a simple one-line description of this object.
EpetraCrsGraphT(const RCP< const map_type > &rowMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying fixed number of entries for each row.
Copy
CombineMode
Xpetra::Combine Mode enumerable type.
#define XPETRA_MONITOR(funcName)
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &Indices) const
Return a const, nonpersisting view of global indices in the given row.
void doImport(const DistObject< GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.