00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include "Xpetra_EpetraCrsGraph.hpp"
00047
00048 #include "Xpetra_Exceptions.hpp"
00049 #include "Xpetra_Utils.hpp"
00050 #include "Xpetra_EpetraExport.hpp"
00051 #include "Xpetra_EpetraImport.hpp"
00052
00053 namespace Xpetra {
00054
00055
00056 template<class GlobalOrdinal>
00057 const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph<int, GlobalOrdinal> > &graph) {
00058 XPETRA_RCP_DYNAMIC_CAST(const EpetraCrsGraphT<GlobalOrdinal>, graph, epetraGraph, "toEpetra");
00059 return *(epetraGraph->getEpetra_CrsGraph());
00060 }
00061
00062 template<class EpetraGlobalOrdinal>
00063 EpetraCrsGraphT<EpetraGlobalOrdinal>::EpetraCrsGraphT(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, ProfileType pftype, const Teuchos::RCP< Teuchos::ParameterList > &plist)
00064 : graph_(Teuchos::rcp(new Epetra_CrsGraph(Copy, toEpetra(rowMap), maxNumEntriesPerRow, toEpetra(pftype)))) { }
00065
00066
00067
00068
00069
00070
00071 template<class EpetraGlobalOrdinal>
00072 EpetraCrsGraphT<EpetraGlobalOrdinal>::EpetraCrsGraphT(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, size_t maxNumEntriesPerRow, ProfileType pftype, const Teuchos::RCP< Teuchos::ParameterList > &plist)
00073 : graph_(Teuchos::rcp(new Epetra_CrsGraph(Copy, toEpetra(rowMap), toEpetra(colMap), maxNumEntriesPerRow, toEpetra(pftype)))) { }
00074
00075
00076
00077
00078
00079
00080 template<class EpetraGlobalOrdinal>
00081 void EpetraCrsGraphT<EpetraGlobalOrdinal>::insertGlobalIndices(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &indices) {
00082 XPETRA_MONITOR("EpetraCrsGraphT::insertGlobalIndices");
00083
00084 GlobalOrdinal* indices_rawPtr = const_cast<GlobalOrdinal*>(indices.getRawPtr());
00085 XPETRA_ERR_CHECK(graph_->InsertGlobalIndices(globalRow, indices.size(), indices_rawPtr));
00086 }
00087
00088 template<class EpetraGlobalOrdinal>
00089 void EpetraCrsGraphT<EpetraGlobalOrdinal>::insertLocalIndices(int localRow, const ArrayView<const int> &indices) {
00090 XPETRA_MONITOR("EpetraCrsGraphT::insertLocalIndices");
00091
00092 int* indices_rawPtr = const_cast<int*>(indices.getRawPtr());
00093 XPETRA_ERR_CHECK(graph_->InsertMyIndices(localRow, indices.size(), indices_rawPtr));
00094 }
00095
00096 template<class EpetraGlobalOrdinal>
00097 void EpetraCrsGraphT<EpetraGlobalOrdinal>::getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &Indices) const {
00098 XPETRA_MONITOR("EpetraCrsGraphT::getGlobalRowView");
00099
00100 int numEntries;
00101 GlobalOrdinal * eIndices;
00102
00103 XPETRA_ERR_CHECK(graph_->ExtractGlobalRowView(GlobalRow, numEntries, eIndices));
00104 if (numEntries == 0) { eIndices = NULL; }
00105
00106 Indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
00107 }
00108
00109 template<class EpetraGlobalOrdinal>
00110 void EpetraCrsGraphT<EpetraGlobalOrdinal>::getLocalRowView(int LocalRow, ArrayView<const int> &indices) const {
00111 XPETRA_MONITOR("EpetraCrsGraphT::getLocalRowView");
00112
00113 int numEntries;
00114 int * eIndices;
00115
00116 XPETRA_ERR_CHECK(graph_->ExtractMyRowView(LocalRow, numEntries, eIndices));
00117 if (numEntries == 0) { eIndices = NULL; }
00118
00119 indices = ArrayView<const int>(eIndices, numEntries);
00120 }
00121
00122 template<class EpetraGlobalOrdinal>
00123 void EpetraCrsGraphT<EpetraGlobalOrdinal>::fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > ¶ms){
00124 XPETRA_MONITOR("EpetraCrsGraphT::fillComplete");
00125
00126 graph_->FillComplete(toEpetra(domainMap), toEpetra(rangeMap));
00127 bool doOptimizeStorage = true;
00128 if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
00129 if (doOptimizeStorage) graph_->OptimizeStorage();
00130 }
00131
00132 template<class EpetraGlobalOrdinal>
00133 void EpetraCrsGraphT<EpetraGlobalOrdinal>::fillComplete(const RCP< ParameterList > ¶ms) {
00134 XPETRA_MONITOR("EpetraCrsGraphT::fillComplete");
00135
00136 graph_->FillComplete();
00137 bool doOptimizeStorage = true;
00138 if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
00139 if (doOptimizeStorage) graph_->OptimizeStorage();
00140 }
00141
00142 template<class EpetraGlobalOrdinal>
00143 std::string EpetraCrsGraphT<EpetraGlobalOrdinal>::description() const { XPETRA_MONITOR("EpetraCrsGraphT::description"); return "NotImplemented"; }
00144
00145 template<class EpetraGlobalOrdinal>
00146 void EpetraCrsGraphT<EpetraGlobalOrdinal>::describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const {
00147 XPETRA_MONITOR("EpetraCrsGraphT::describe");
00148
00149 out << "EpetraCrsGraphT::describe : Warning, verbosity level is ignored by this method." << std::endl;
00150 const Epetra_BlockMap rowmap = graph_->RowMap();
00151 if (rowmap.Comm().MyPID() == 0) out << "** EpetraCrsGraphT **\n\nrowmap" << std::endl;
00152 rowmap.Print(out);
00153 graph_->Print(out);
00154 }
00155
00156
00157 template<class GlobalOrdinal>
00158 RCP<const CrsGraph<int, GlobalOrdinal> >
00159 toXpetra (const Epetra_CrsGraph &g)
00160 {
00161 RCP<const Epetra_CrsGraph> const_graph = rcp (new Epetra_CrsGraph (g));
00162 RCP<Epetra_CrsGraph> graph =
00163 Teuchos::rcp_const_cast<Epetra_CrsGraph> (const_graph);
00164 return rcp (new Xpetra::EpetraCrsGraphT<GlobalOrdinal>(graph));
00165 }
00166
00167
00168
00169 template<class EpetraGlobalOrdinal>
00170 void EpetraCrsGraphT<EpetraGlobalOrdinal>::doImport(const DistObject<GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node> &source,
00171 const Import<LocalOrdinal, GlobalOrdinal, Node> &importer, CombineMode CM) {
00172 XPETRA_MONITOR("EpetraCrsGraphT::doImport");
00173
00174 XPETRA_DYNAMIC_CAST(const EpetraCrsGraphT<GlobalOrdinal>, source, tSource, "Xpetra::EpetraCrsGraphT::doImport only accept Xpetra::EpetraCrsGraphT as input arguments.");
00175 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal>, importer, tImporter, "Xpetra::EpetraCrsGraphT::doImport only accept Xpetra::EpetraImportT as input arguments.");
00176
00177 RCP<const Epetra_CrsGraph> v = tSource.getEpetra_CrsGraph();
00178 int err = graph_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
00179 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
00180 }
00181
00182 template<class EpetraGlobalOrdinal>
00183 void EpetraCrsGraphT<EpetraGlobalOrdinal>::doExport(const DistObject<GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node> &dest,
00184 const Import<LocalOrdinal, GlobalOrdinal, Node>& importer, CombineMode CM) {
00185 XPETRA_MONITOR("EpetraCrsGraphT::doExport");
00186
00187 XPETRA_DYNAMIC_CAST(const EpetraCrsGraphT<GlobalOrdinal>, dest, tDest, "Xpetra::EpetraCrsGraphT::doImport only accept Xpetra::EpetraCrsGraphT as input arguments.");
00188 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal>, importer, tImporter, "Xpetra::EpetraCrsGraphT::doImport only accept Xpetra::EpetraImportT as input arguments.");
00189
00190 RCP<const Epetra_CrsGraph> v = tDest.getEpetra_CrsGraph();
00191 int err = graph_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
00192 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
00193 }
00194
00195 template<class EpetraGlobalOrdinal>
00196 void EpetraCrsGraphT<EpetraGlobalOrdinal>::doImport(const DistObject<GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node> &source,
00197 const Export<LocalOrdinal, GlobalOrdinal, Node>& exporter, CombineMode CM) {
00198 XPETRA_MONITOR("EpetraCrsGraphT::doImport");
00199
00200 XPETRA_DYNAMIC_CAST(const EpetraCrsGraphT<GlobalOrdinal>, source, tSource, "Xpetra::EpetraCrsGraphT::doImport only accept Xpetra::EpetraCrsGraphT as input arguments.");
00201 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal>, exporter, tExporter, "Xpetra::EpetraCrsGraphT::doImport only accept Xpetra::EpetraImportT as input arguments.");
00202
00203 RCP<const Epetra_CrsGraph> v = tSource.getEpetra_CrsGraph();
00204 int err = graph_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
00205 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
00206
00207 }
00208
00209 template<class EpetraGlobalOrdinal>
00210 void EpetraCrsGraphT<EpetraGlobalOrdinal>::doExport(const DistObject<GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node> &dest,
00211 const Export<LocalOrdinal, GlobalOrdinal, Node>& exporter, CombineMode CM) {
00212 XPETRA_MONITOR("EpetraCrsGraphT::doExport");
00213
00214 XPETRA_DYNAMIC_CAST(const EpetraCrsGraphT<GlobalOrdinal>, dest, tDest, "Xpetra::EpetraCrsGraphT::doImport only accept Xpetra::EpetraCrsGraphT as input arguments.");
00215 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal>, exporter, tExporter, "Xpetra::EpetraCrsGraphT::doImport only accept Xpetra::EpetraImportT as input arguments.");
00216
00217 RCP<const Epetra_CrsGraph> v = tDest.getEpetra_CrsGraph();
00218 int err = graph_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
00219 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
00220 }
00221
00222 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
00223 template class EpetraCrsGraphT<int>;
00224 template RCP< const CrsGraph<int, int> > toXpetra<int>(const Epetra_CrsGraph &g);
00225 template const Epetra_CrsGraph & toEpetra<int>(const RCP< const CrsGraph<int, int> > &graph);
00226 #endif
00227
00228 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
00229 template class EpetraCrsGraphT<long long>;
00230 template RCP< const CrsGraph<int, long long> > toXpetra<long long>(const Epetra_CrsGraph &g);
00231 template const Epetra_CrsGraph & toEpetra<long long>(const RCP< const CrsGraph<int, long long> > &graph);
00232 #endif
00233
00234 }