15#ifndef dealii_trilinos_tpetra_sparsity_pattern_h
16#define dealii_trilinos_tpetra_sparsity_pattern_h
20#ifdef DEAL_II_TRILINOS_WITH_TPETRA
30# include <Tpetra_CrsGraph.hpp>
45 namespace TpetraWrappers
47 template <
typename MemorySpace>
50 template <
typename Number,
typename MemorySpace>
55 template <
typename MemorySpace>
64 namespace TpetraWrappers
79 template <
typename MemorySpace = ::MemorySpace::Host>
91# if DEAL_II_TRILINOS_VERSION_GTE(14, 2, 0)
92 using NodeType = Tpetra::KokkosCompat::KokkosDeviceWrapperNode<
93 typename MemorySpace::kokkos_space::execution_space,
94 typename MemorySpace::kokkos_space>;
96 using NodeType = Kokkos::Compat::KokkosDeviceWrapperNode<
97 typename MemorySpace::kokkos_space::execution_space,
98 typename MemorySpace::kokkos_space>;
138 <<
"You tried to access row " <<
arg1
139 <<
" of a distributed sparsity pattern, "
140 <<
" but only rows " <<
arg2 <<
" through " <<
arg3
141 <<
" are stored locally and can be accessed.");
171 std::shared_ptr<std::vector<::types::signed_global_dof_index>>
191 template <
typename MemorySpace = ::MemorySpace::Host>
203# if DEAL_II_TRILINOS_VERSION_GTE(14, 2, 0)
204 using NodeType = Tpetra::KokkosCompat::KokkosDeviceWrapperNode<
205 typename MemorySpace::kokkos_space::execution_space,
206 typename MemorySpace::kokkos_space>;
208 using NodeType = Kokkos::Compat::KokkosDeviceWrapperNode<
209 typename MemorySpace::kokkos_space::execution_space,
210 typename MemorySpace::kokkos_space>;
277 <<
"Attempt to access element " <<
arg2 <<
" of row "
278 <<
arg1 <<
" which doesn't have that many elements.");
309 template <
typename MemorySpace = ::MemorySpace::Host>
321# if DEAL_II_TRILINOS_VERSION_GTE(14, 2, 0)
322 using NodeType = Tpetra::KokkosCompat::KokkosDeviceWrapperNode<
323 typename MemorySpace::kokkos_space::execution_space,
324 typename MemorySpace::kokkos_space>;
326 using NodeType = Kokkos::Compat::KokkosDeviceWrapperNode<
327 typename MemorySpace::kokkos_space::execution_space,
328 typename MemorySpace::kokkos_space>;
447 template <
typename SparsityPatternType>
692 template <
typename SparsityPatternType>
708 template <
typename SparsityPatternType>
753 std::pair<size_type, size_type>
832 template <
typename ForwardIterator>
841 const ::types::global_dof_index &row,
857 Teuchos::RCP<GraphType>
968 print(std::ostream &out,
998 <<
"An error with error number " <<
arg1
999 <<
" occurred while calling a Trilinos function");
1007 <<
"The entry with index <" <<
arg1 <<
',' <<
arg2
1008 <<
"> does not exist.");
1018 <<
"You tried to access element (" <<
arg1 <<
'/' <<
arg2
1020 <<
" of a distributed matrix, but only rows in range ["
1022 <<
"] are stored locally and can be accessed.");
1030 <<
"You tried to access element (" <<
arg1 <<
'/' <<
arg2
1031 <<
')' <<
" of a sparse matrix, but it appears to not"
1032 <<
" exist in the Trilinos sparsity pattern.");
1071 template <
typename MemorySpace>
1074 const size_type row,
1075 const size_type index)
1080 visit_present_row();
1085 template <
typename MemorySpace>
1086 inline typename Accessor<MemorySpace>::size_type
1087 Accessor<MemorySpace>::row()
const
1090 ExcBeyondEndOfSparsityPattern());
1096 template <
typename MemorySpace>
1097 inline typename Accessor<MemorySpace>::size_type
1098 Accessor<MemorySpace>::column()
const
1101 ExcBeyondEndOfSparsityPattern());
1102 return (*colnum_cache)[a_index];
1107 template <
typename MemorySpace>
1108 inline typename Accessor<MemorySpace>::size_type
1109 Accessor<MemorySpace>::index()
const
1112 ExcBeyondEndOfSparsityPattern());
1118 template <
typename MemorySpace>
1119 inline Iterator<MemorySpace>::Iterator(
1121 const size_type row,
1122 const size_type index)
1128 template <
typename MemorySpace>
1134 template <
typename MemorySpace>
1136 Iterator<MemorySpace>::operator++()
1138 Assert(accessor.a_row < accessor.sparsity_pattern->n_rows(),
1145 if (accessor.a_index >=
1147 accessor.colnum_cache->size()))
1149 accessor.a_index = 0;
1152 while (accessor.a_row <
1154 accessor.sparsity_pattern->n_rows()))
1156 const auto row_length =
1157 accessor.sparsity_pattern->row_length(accessor.a_row);
1158 if (row_length == 0 ||
1159 !accessor.sparsity_pattern->row_is_stored_locally(
1166 accessor.visit_present_row();
1173 template <
typename MemorySpace>
1175 Iterator<MemorySpace>::operator++(
int)
1184 template <
typename MemorySpace>
1186 Iterator<MemorySpace>::operator*()
const
1193 template <
typename MemorySpace>
1195 Iterator<MemorySpace>::operator->()
const
1202 template <
typename MemorySpace>
1204 Iterator<MemorySpace>::operator==(
1207 return (accessor.a_row ==
other.accessor.a_row &&
1208 accessor.a_index ==
other.accessor.a_index);
1213 template <
typename MemorySpace>
1215 Iterator<MemorySpace>::operator!=(
1218 return !(*
this ==
other);
1223 template <
typename MemorySpace>
1227 return (accessor.row() <
other.accessor.row() ||
1228 (accessor.row() ==
other.accessor.row() &&
1229 accessor.index() <
other.accessor.index()));
1236 template <
typename MemorySpace>
1246 template <
typename MemorySpace>
1250 return const_iterator(
this, n_rows(), 0);
1255 template <
typename MemorySpace>
1260 if (row_length(r) > 0)
1261 return const_iterator(
this, r, 0);
1268 template <
typename MemorySpace>
1277 for (size_type i = r + 1;
1280 if (row_length(i) > 0)
1281 return const_iterator(
this, i, 0);
1290 template <
typename MemorySpace>
1295 graph->getRowMap()->getMinGlobalIndex();
1297 graph->getRowMap()->getMaxGlobalIndex() + 1;
1299 return ((index >=
static_cast<size_type>(begin)) &&
1305 template <
typename MemorySpace>
1309 return graph->isFillComplete();
1314 template <
typename MemorySpace>
1318 return ((n_rows() == 0) && (n_cols() == 0));
1323 template <
typename MemorySpace>
1327 add_entries(i, &
j, &
j + 1);
1332 template <
typename MemorySpace>
1333 template <
typename ForwardIterator>
1373 if (row_is_stored_locally(row))
1375 else if (nonlocal_graph.get() !=
nullptr)
1380 Assert(nonlocal_graph->getRowMap()->getLocalElement(row) !=
1383 ExcMessage(
"Attempted to write into off-processor matrix row "
1384 "that has not be specified as being writable upon "
1394 template <
typename MemorySpace>
1406 template <
typename MemorySpace>
1410 return IndexSet(graph->getDomainMap().getConst());
1415 template <
typename MemorySpace>
1419 return IndexSet(graph->getRangeMap().getConst());
Tpetra::KokkosCompat::KokkosDeviceWrapperNode< typename MemorySpace::kokkos_space::execution_space, typename MemorySpace::kokkos_space > NodeType
Accessor(const SparsityPattern< MemorySpace > *sparsity_pattern, const size_type row, const size_type index)
std::shared_ptr< std::vector<::types::signed_global_dof_index > > colnum_cache
SparsityPattern< MemorySpace > * sparsity_pattern
Iterator< MemorySpace > & operator++()
Iterator(const Iterator< MemorySpace > &i)
Iterator(const SparsityPattern< MemorySpace > *sparsity_pattern, const size_type row, const size_type index)
const Accessor< MemorySpace > * operator->() const
Accessor< MemorySpace > accessor
bool operator!=(const Iterator< MemorySpace > &) const
bool operator<(const Iterator< MemorySpace > &) const
bool operator==(const Iterator< MemorySpace > &) const
Tpetra::KokkosCompat::KokkosDeviceWrapperNode< typename MemorySpace::kokkos_space::execution_space, typename MemorySpace::kokkos_space > NodeType
const Accessor< MemorySpace > & operator*() const
Teuchos::RCP< MapType > column_space_map
Teuchos::RCP< const Teuchos::Comm< int > > get_teuchos_mpi_communicator() const
Teuchos::RCP< const MapType > domain_partitioner() const
std::pair< size_type, size_type > local_range() const
IndexSet locally_owned_range_indices() const
Teuchos::RCP< GraphType > nonlocal_graph
void copy_from(const SparsityPattern< MemorySpace > &input_sparsity_pattern)
SparsityPattern< MemorySpace > & operator=(const SparsityPattern< MemorySpace > &input_sparsity_pattern)
void print(std::ostream &out, const bool write_extended_trilinos_info=false) const
unsigned int max_entries_per_row() const
const_iterator end() const
void print_gnuplot(std::ostream &out) const
IndexSet locally_owned_domain_indices() const
bool is_compressed() const
MPI_Comm get_mpi_communicator() const
Tpetra::CrsGraph< int, ::types::signed_global_dof_index, NodeType > GraphType
std::uint64_t n_nonzero_elements() const
const_iterator end(const size_type r) const
size_type bandwidth() const
bool exists(const size_type i, const size_type j) const
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
Teuchos::RCP< const MapType > range_partitioner() const
unsigned int local_size() const
virtual void add_row_entries(const ::types::global_dof_index &row, const ArrayView< const ::types::global_dof_index > &columns, const bool indices_are_sorted=false) override
void add(const size_type i, const size_type j)
Teuchos::RCP< GraphType > trilinos_sparsity_pattern() const
Teuchos::RCP< GraphType > graph
const_iterator begin() const
Tpetra::KokkosCompat::KokkosDeviceWrapperNode< typename MemorySpace::kokkos_space::execution_space, typename MemorySpace::kokkos_space > NodeType
const_iterator begin(const size_type r) const
Tpetra::Map< int, ::types::signed_global_dof_index, NodeType > MapType
virtual ~SparsityPattern() override=default
size_type row_length(const size_type row) const
bool in_local_range(const size_type index) const
std::size_t memory_consumption() const
bool row_is_stored_locally(const size_type i) const
void reinit(const size_type m, const size_type n, const size_type n_entries_per_row=0)
virtual void add_entries(const ArrayView< const std::pair< size_type, size_type > > &entries)
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
bool is_compressed() const
void add(const size_type i, const size_type j)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcTrilinosError(int arg1)
#define DeclException0(Exception0)
static ::ExceptionBase & ExcAccessToNonPresentElement(size_type arg1, size_type arg2)
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcIteratorPastEnd()
#define DeclException2(Exception2, type1, type2, outsequence)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcBeyondEndOfSparsityPattern()
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcAccessToNonlocalRow(size_type arg1, size_type arg2, size_type arg3)
#define DeclException3(Exception3, type1, type2, type3, outsequence)
static ::ExceptionBase & ExcInvalidIndex(size_type arg1, size_type arg2)
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcInvalidIndexWithinRow(size_type arg1, size_type arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
types::global_dof_index size_type
const Iterator const std_cxx20::type_identity_t< Iterator > & end
int signed_global_dof_index