53 #ifndef AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DEF_HPP
54 #define AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DEF_HPP
56 #include <Epetra_RowMatrix.h>
57 #include <Epetra_Map.h>
58 #include <Epetra_Comm.h>
66 using Teuchos::ArrayView;
68 template <
class DerivedMat>
69 AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::AbstractConcreteMatrixAdapter(RCP<DerivedMat> m)
70 : MatrixAdapter<DerivedMat>(m)
76 template <
class DerivedMat>
78 AbstractConcreteMatrixAdapter<
80 DerivedMat>::getGlobalRowCopy_impl(global_ordinal_t row,
81 const ArrayView<global_ordinal_t>& indices,
82 const ArrayView<scalar_t>& vals,
86 const int local_row = this->row_map_->getLocalElement(row);
89 Teuchos::Array<local_ordinal_t> epetra_lcl_inds_buf;
90 Teuchos::ArrayView<local_ordinal_t> epetra_lcl_inds;
91 if (! std::is_same<global_ordinal_t, local_ordinal_t>::value) {
95 err = this->mat_->NumMyRowEntries (local_row, num_ent);
97 catch (
int integer_exception) {
99 err = integer_exception;
101 TEUCHOS_TEST_FOR_EXCEPTION
102 (threw && err != 0, std::runtime_error,
"Epetra_RowMatrix::"
103 "NumMyRowEntries, called on local row " << local_row <<
", threw "
104 "an integer exception " << err <<
".");
105 TEUCHOS_TEST_FOR_EXCEPTION
106 (! threw && err != 0, std::runtime_error,
"Epetra_RowMatrix returned "
107 "error code " << err <<
" from NumMyRowEntries for local row "
108 << local_row <<
".");
109 epetra_lcl_inds_buf.resize (num_ent);
110 epetra_lcl_inds = epetra_lcl_inds_buf ();
113 using Teuchos::av_reinterpret_cast;
114 epetra_lcl_inds = av_reinterpret_cast<
int> (indices);
118 int rowmatrix_return_val = 0;
120 rowmatrix_return_val =
121 this->mat_->ExtractMyRowCopy(local_row,
122 as<int>(std::min(epetra_lcl_inds.size(), vals.size())),
125 epetra_lcl_inds.getRawPtr());
127 catch (
int integer_exception) {
129 rowmatrix_return_val = integer_exception;
131 TEUCHOS_TEST_FOR_EXCEPTION
132 (threw && rowmatrix_return_val != 0, std::runtime_error,
133 "Epetra_RowMatrix::ExtractMyRowCopy, called on local row " << local_row
134 <<
", threw an integer exception " << rowmatrix_return_val <<
".");
135 TEUCHOS_TEST_FOR_EXCEPTION
136 (! threw && rowmatrix_return_val != 0, std::runtime_error,
137 "Epetra_RowMatrix object returned error code "
138 << rowmatrix_return_val <<
" from ExtractMyRowCopy." );
139 nnz = as<size_t>(nnz_ret);
143 for(
size_t i = 0; i < nnz; ++i ){
144 indices[i] = this->col_map_->getGlobalElement(epetra_lcl_inds[i]);
148 template <
class DerivedMat>
150 AbstractConcreteMatrixAdapter<
152 DerivedMat>::getGlobalColCopy_impl(global_ordinal_t col,
153 const ArrayView<global_ordinal_t>& indices,
154 const ArrayView<scalar_t>& vals,
157 TEUCHOS_TEST_FOR_EXCEPTION(
true,
159 "Column access to row-based object not yet supported. "
160 "Please contact the Amesos2 developers." );
164 template <
class DerivedMat>
165 template<
typename KV_GO,
typename KV_S>
167 AbstractConcreteMatrixAdapter<
169 DerivedMat>::getGlobalRowCopy_kokkos_view_impl(global_ordinal_t row,
174 using index_t =
typename KV_GO::value_type;
175 using value_t =
typename KV_S::value_type;
176 ArrayView<value_t> vals_array (vals.data(), vals.extent(0));
177 ArrayView<index_t> indices_array (indices.data(), indices.extent(0));
179 this->getGlobalRowCopy_impl(row, indices_array, vals_array, nnz);
184 template <
class DerivedMat>
185 typename AbstractConcreteMatrixAdapter<
187 DerivedMat>::global_size_t
188 AbstractConcreteMatrixAdapter<
190 DerivedMat>::getGlobalNNZ_impl()
const
192 return Teuchos::as<global_size_t>(this->mat_->NumGlobalNonzeros());
195 template <
class DerivedMat>
197 AbstractConcreteMatrixAdapter<
199 DerivedMat>::getLocalNNZ_impl()
const
201 return Teuchos::as<size_t>(this->mat_->NumMyNonzeros());
204 template <
class DerivedMat>
205 typename AbstractConcreteMatrixAdapter<
207 DerivedMat>::global_size_t
208 AbstractConcreteMatrixAdapter<
210 DerivedMat>::getGlobalNumRows_impl()
const
212 return Teuchos::as<global_size_t>(this->mat_->NumGlobalRows());
215 template <
class DerivedMat>
216 typename AbstractConcreteMatrixAdapter<
218 DerivedMat>::global_size_t
219 AbstractConcreteMatrixAdapter<
221 DerivedMat>::getGlobalNumCols_impl()
const
223 return Teuchos::as<global_size_t>(this->mat_->NumGlobalCols());
226 template <
class DerivedMat>
228 AbstractConcreteMatrixAdapter<
230 DerivedMat>::getMaxRowNNZ_impl()
const
232 return Teuchos::as<size_t>(this->mat_->MaxNumEntries());
235 template <
class DerivedMat>
237 AbstractConcreteMatrixAdapter<
239 DerivedMat>::getMaxColNNZ_impl()
const
241 TEUCHOS_TEST_FOR_EXCEPTION(
true,
243 "Column access to row-based object not yet supported. "
244 "Please contact the Amesos2 developers." );
247 template <
class DerivedMat>
249 AbstractConcreteMatrixAdapter<
251 DerivedMat>::getGlobalRowNNZ_impl(global_ordinal_t row)
const
254 Epetra_Map rowmap = this->mat_->RowMatrixRowMap();
255 int gid = Teuchos::as<int>(row);
256 TEUCHOS_TEST_FOR_EXCEPTION( !rowmap.MyGID(gid),
257 std::invalid_argument,
258 "The specified global row id does not belong to me" );
259 int lid = rowmap.LID(gid);
261 this->mat_->NumMyRowEntries(lid, nnz);
265 template <
class DerivedMat>
267 AbstractConcreteMatrixAdapter<
269 DerivedMat>::getLocalRowNNZ_impl(local_ordinal_t row)
const
271 Epetra_Map rowmap = this->mat_->RowMatrixRowMap();
272 int lid = Teuchos::as<int>(row);
273 TEUCHOS_TEST_FOR_EXCEPTION( !rowmap.MyLID(lid),
274 std::invalid_argument,
275 "The specified local row id does not beloing to me" );
277 this->mat_->NumMyRowEntries(row, num_entries);
281 template <
class DerivedMat>
283 AbstractConcreteMatrixAdapter<
285 DerivedMat>::getGlobalColNNZ_impl(global_ordinal_t col)
const
287 TEUCHOS_TEST_FOR_EXCEPTION(
true,
289 "Column access to row-based object not yet supported. "
290 "Please contact the Amesos2 developers." );
293 template <
class DerivedMat>
295 AbstractConcreteMatrixAdapter<
297 DerivedMat>::getLocalColNNZ_impl(local_ordinal_t col)
const
299 TEUCHOS_TEST_FOR_EXCEPTION(
true,
301 "Column access to row-based object not yet supported. "
302 "Please contact the Amesos2 developers." );
305 template <
class DerivedMat>
306 const RCP<const Tpetra::Map<MatrixTraits<Epetra_RowMatrix>::local_ordinal_t,
307 MatrixTraits<Epetra_RowMatrix>::global_ordinal_t,
308 MatrixTraits<Epetra_RowMatrix>::node_t> >
309 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getMap_impl()
const
316 return( Teuchos::null );
319 template <
class DerivedMat>
320 const RCP<const Tpetra::Map<MatrixTraits<Epetra_RowMatrix>::local_ordinal_t,
321 MatrixTraits<Epetra_RowMatrix>::global_ordinal_t,
322 MatrixTraits<Epetra_RowMatrix>::node_t> >
323 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getRowMap_impl()
const
326 const Epetra_Map rowmap = this->mat_->RowMatrixRowMap();
327 return( Util::epetra_map_to_tpetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(rowmap) );
330 template <
class DerivedMat>
331 const RCP<const Tpetra::Map<MatrixTraits<Epetra_RowMatrix>::local_ordinal_t,
332 MatrixTraits<Epetra_RowMatrix>::global_ordinal_t,
333 MatrixTraits<Epetra_RowMatrix>::node_t> >
334 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getColMap_impl()
const
337 const Epetra_Map colmap = this->mat_->RowMatrixColMap();
338 return( Util::epetra_map_to_tpetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(colmap) );
341 template <
class DerivedMat>
342 const RCP<const Teuchos::Comm<int> >
343 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getComm_impl()
const
348 template <
class DerivedMat>
350 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::isLocallyIndexed_impl()
const
352 return this->mat_->IndicesAreLocal();
355 template <
class DerivedMat>
357 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::isGloballyIndexed_impl()
const
359 return this->mat_->IndicesAreGlobal();
363 template <
class DerivedMat>
364 RCP<const MatrixAdapter<DerivedMat> >
365 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::get_impl(
const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map,
EDistribution distribution)
const
370 return dynamic_cast<ConcreteMatrixAdapter<DerivedMat>*
>(
this)->get_impl(map, distribution);
372 return static_cast<ConcreteMatrixAdapter<DerivedMat>*
>(
this)->get_impl(map, distribution);
376 template <
class DerivedMat>
377 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>
379 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getSparseRowPtr()
const
381 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::spmtx_ptr_t sp_rowptr =
nullptr;
382 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::spmtx_idx_t sp_colind =
nullptr;
383 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::spmtx_val_t sp_values =
nullptr;
385 this->mat_->ExtractCrsDataPointers(sp_rowptr, sp_colind, sp_values);
390 template <
class DerivedMat>
391 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>
393 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getSparseColInd()
const
395 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::spmtx_ptr_t sp_rowptr =
nullptr;
396 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::spmtx_idx_t sp_colind =
nullptr;
397 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::spmtx_val_t sp_values =
nullptr;
399 this->mat_->ExtractCrsDataPointers(sp_rowptr, sp_colind, sp_values);
404 template <
class DerivedMat>
405 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>
407 AbstractConcreteMatrixAdapter<Epetra_RowMatrix, DerivedMat>::getSparseValues()
const
409 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::spmtx_ptr_t sp_rowptr =
nullptr;
410 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::spmtx_idx_t sp_colind =
nullptr;
411 typename AbstractConcreteMatrixAdapter<Epetra_RowMatrix,DerivedMat>::spmtx_val_t sp_values =
nullptr;
413 this->mat_->ExtractCrsDataPointers(sp_rowptr, sp_colind, sp_values);
420 #endif // AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DEF_HPP
const RCP< const Teuchos::Comm< int > > to_teuchos_comm(RCP< const Epetra_Comm > c)
Transform an Epetra_Comm object into a Teuchos::Comm object.
Provides the Epetra_RowMatrix abstraction for the concrete Epetra row matric adapters.
EDistribution
Definition: Amesos2_TypeDecl.hpp:123