16#ifndef dealii_trilinos_sparsity_pattern_h
17# define dealii_trilinos_sparsity_pattern_h
22# ifdef DEAL_II_WITH_TRILINOS
29# include <Epetra_FECrsGraph.h>
30# include <Epetra_Map.h>
31# include <Epetra_MpiComm.h>
118 <<
"You tried to access row " << arg1
119 <<
" of a distributed sparsity pattern, "
120 <<
" but only rows " << arg2 <<
" through " << arg3
121 <<
" are stored locally and can be accessed.");
242 <<
"Attempt to access element " << arg2 <<
" of row "
243 << arg1 <<
" which doesn't have that many elements.");
324 const std::vector<size_type> &n_entries_per_row);
370 const std::vector<size_type> &n_entries_per_row);
384 template <
typename SparsityPatternType>
386 copy_from(
const SparsityPatternType &nontrilinos_sparsity_pattern);
437 const MPI_Comm &communicator = MPI_COMM_WORLD,
452 const std::vector<size_type> &n_entries_per_row);
469 const IndexSet &col_parallel_partitioning,
470 const MPI_Comm &communicator = MPI_COMM_WORLD,
485 const IndexSet & col_parallel_partitioning,
487 const std::vector<size_type> &n_entries_per_row);
516 const IndexSet &col_parallel_partitioning,
518 const MPI_Comm &communicator = MPI_COMM_WORLD,
538 const MPI_Comm &communicator = MPI_COMM_WORLD,
554 const std::vector<size_type> &n_entries_per_row);
574 const IndexSet &col_parallel_partitioning,
575 const MPI_Comm &communicator = MPI_COMM_WORLD,
605 const IndexSet &col_parallel_partitioning,
607 const MPI_Comm &communicator = MPI_COMM_WORLD,
616 const IndexSet & col_parallel_partitioning,
618 const std::vector<size_type> &n_entries_per_row);
629 template <
typename SparsityPatternType>
632 const IndexSet & col_parallel_partitioning,
633 const SparsityPatternType &nontrilinos_sparsity_pattern,
634 const MPI_Comm & communicator = MPI_COMM_WORLD,
635 const bool exchange_data =
false);
645 template <
typename SparsityPatternType>
648 const SparsityPatternType &nontrilinos_sparsity_pattern,
649 const MPI_Comm & communicator = MPI_COMM_WORLD,
650 const bool exchange_data =
false);
702 std::pair<size_type, size_type>
781 template <
typename ForwardIterator>
784 ForwardIterator
begin,
786 const bool indices_are_sorted =
false);
797 const Epetra_FECrsGraph &
909 print(std::ostream &out,
910 const bool write_extended_trilinos_info =
false)
const;
939 <<
"An error with error number " << arg1
940 <<
" occurred while calling a Trilinos function");
948 <<
"The entry with index <" << arg1 <<
',' << arg2
949 <<
"> does not exist.");
956 "You are attempting an operation on two sparsity patterns that "
957 "are the same object, but the operation requires that the "
958 "two objects are in fact different.");
968 <<
"You tried to access element (" << arg1 <<
'/' << arg2
970 <<
" of a distributed matrix, but only rows in range ["
971 << arg3 <<
',' << arg4
972 <<
"] are stored locally and can be accessed.");
980 <<
"You tried to access element (" << arg1 <<
'/' << arg2
981 <<
')' <<
" of a sparse matrix, but it appears to not"
982 <<
" exist in the Trilinos sparsity pattern.");
996 std::unique_ptr<Epetra_FECrsGraph>
graph;
1021 const size_type row,
1022 const size_type index)
1027 visit_present_row();
1032 inline Accessor::size_type
1033 Accessor::row()
const
1035 Assert(a_row < sparsity_pattern->n_rows(),
1036 ExcBeyondEndOfSparsityPattern());
1042 inline Accessor::size_type
1043 Accessor::column()
const
1045 Assert(a_row < sparsity_pattern->n_rows(),
1046 ExcBeyondEndOfSparsityPattern());
1047 return (*colnum_cache)[a_index];
1052 inline Accessor::size_type
1053 Accessor::index()
const
1055 Assert(a_row < sparsity_pattern->n_rows(),
1056 ExcBeyondEndOfSparsityPattern());
1063 const size_type row,
1064 const size_type index)
1065 : accessor(sp, row,
index)
1070 inline Iterator::Iterator(
const Iterator &) =
default;
1075 Iterator::operator++()
1077 Assert(accessor.a_row < accessor.sparsity_pattern->n_rows(),
1084 if (accessor.a_index >= accessor.colnum_cache->size())
1086 accessor.a_index = 0;
1089 while (accessor.a_row < accessor.sparsity_pattern->n_rows())
1091 const auto row_length =
1092 accessor.sparsity_pattern->row_length(accessor.a_row);
1093 if (row_length == 0 ||
1094 !accessor.sparsity_pattern->row_is_stored_locally(
1101 accessor.visit_present_row();
1109 Iterator::operator++(
int)
1111 const Iterator old_state = *
this;
1118 inline const Accessor &
1119 Iterator::operator*()
const
1126 inline const Accessor *
1127 Iterator::operator->()
const
1135 Iterator::operator==(
const Iterator &other)
const
1137 return (accessor.a_row == other.accessor.a_row &&
1138 accessor.a_index == other.accessor.a_index);
1144 Iterator::operator!=(
const Iterator &other)
const
1146 return !(*
this == other);
1152 Iterator::operator<(
const Iterator &other)
const
1154 return (accessor.row() < other.accessor.row() ||
1155 (accessor.row() == other.accessor.row() &&
1156 accessor.index() < other.accessor.index()));
1166 const size_type first_valid_row = this->local_range().first;
1212 SparsityPattern::in_local_range(
const size_type index)
const
1215# ifndef DEAL_II_WITH_64BIT_INDICES
1216 begin = graph->RowMap().MinMyGID();
1217 end = graph->RowMap().MaxMyGID() + 1;
1219 begin = graph->RowMap().MinMyGID64();
1220 end = graph->RowMap().MaxMyGID64() + 1;
1232 return graph->Filled();
1253 template <
typename ForwardIterator>
1256 ForwardIterator begin,
1257 ForwardIterator end,
1276 const_cast<typename std::decay<decltype(*
begin)
>::type *>(&*
begin));
1283 if (row_is_stored_locally(row))
1285 graph->InsertGlobalIndices(trilinos_row_index,
n_cols, col_index_ptr);
1286 else if (nonlocal_graph.get() !=
nullptr)
1291 Assert(nonlocal_graph->RowMap().LID(
1293 ExcMessage(
"Attempted to write into off-processor matrix row "
1294 "that has not be specified as being writable upon "
1296 ierr = nonlocal_graph->InsertGlobalIndices(trilinos_row_index,
1301 ierr = graph->InsertGlobalIndices(1,
1302 &trilinos_row_index,
1311 inline const Epetra_FECrsGraph &
1312 SparsityPattern::trilinos_sparsity_pattern()
const
1320 SparsityPattern::locally_owned_domain_indices()
const
1322 return IndexSet(graph->DomainMap());
1328 SparsityPattern::locally_owned_range_indices()
const
1330 return IndexSet(graph->RangeMap());
void add(const size_type i, const size_type j)
unsigned int row_length(const size_type row) const
bool is_compressed() const
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
SparsityPatternBase::const_iterator const_iterator
SparsityPatternBase::size_type size_type
std::shared_ptr< const std::vector< size_type > > colnum_cache
Accessor(const SparsityPattern *sparsity_pattern, const size_type row, const size_type index)
::types::global_dof_index size_type
SparsityPattern * sparsity_pattern
bool operator==(const Iterator &) const
::types::global_dof_index size_type
const Accessor & operator*() const
bool operator<(const Iterator &) const
Iterator(const SparsityPattern *sparsity_pattern, const size_type row, const size_type index)
bool operator!=(const Iterator &) const
const Accessor * operator->() const
Iterator(const Iterator &i)
IndexSet locally_owned_domain_indices() const
size_type row_length(const size_type row) const
void add(const size_type i, const size_type j)
unsigned int max_entries_per_row() const
size_type bandwidth() const
const_iterator end() const
MPI_Comm get_mpi_communicator() const
const_iterator begin(const size_type r) const
std::uint64_t n_nonzero_elements() const
bool exists(const size_type i, const size_type j) const
const Epetra_Map & domain_partitioner() const
std::pair< size_type, size_type > local_range() const
::types::global_dof_index size_type
const Epetra_FECrsGraph & trilinos_sparsity_pattern() const
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
bool is_compressed() const
unsigned int local_size() const
void copy_from(const SparsityPattern &input_sparsity_pattern)
IndexSet locally_owned_range_indices() const
const Epetra_Map & range_partitioner() const
const_iterator begin() const
const_iterator end(const size_type r) const
bool in_local_range(const size_type index) const
virtual ~SparsityPattern() override=default
std::size_t memory_consumption() const
SparsityPattern & operator=(const SparsityPattern &input_sparsity_pattern)
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)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcAccessToNonPresentElement(size_type arg1, size_type arg2)
#define DeclException0(Exception0)
static ::ExceptionBase & ExcBeyondEndOfSparsityPattern()
std::unique_ptr< Epetra_FECrsGraph > graph
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
void print(std::ostream &out, const bool write_extended_trilinos_info=false) const
static ::ExceptionBase & ExcNotImplemented()
void print_gnuplot(std::ostream &out) const
static ::ExceptionBase & ExcInvalidIndexWithinRow(size_type arg1, size_type arg2)
#define Assert(cond, exc)
static ::ExceptionBase & ExcIteratorPastEnd()
std::unique_ptr< Epetra_CrsGraph > nonlocal_graph
static ::ExceptionBase & ExcAccessToNonlocalRow(size_type arg1, size_type arg2, size_type arg3)
#define DeclException2(Exception2, type1, type2, outsequence)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
static ::ExceptionBase & ExcInvalidIndex(size_type arg1, size_type arg2)
static ::ExceptionBase & ExcSourceEqualsDestination()
std::unique_ptr< Epetra_Map > column_space_map
#define AssertIndexRange(index, range)
#define DeclExceptionMsg(Exception, defaulttext)
#define DeclException3(Exception3, type1, type2, type3, outsequence)
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcTrilinosError(int arg1)
static ::ExceptionBase & ExcTrilinosError(int arg1)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
unsigned int global_dof_index