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>
35# ifdef DEAL_II_WITH_MPI
36# include <Epetra_MpiComm.h>
39# include <Epetra_SerialComm.h>
122 <<
"You tried to access row " << arg1
123 <<
" of a distributed sparsity pattern, "
124 <<
" but only rows " << arg2 <<
" through " << arg3
125 <<
" are stored locally and can be accessed.");
244 <<
"Attempt to access element " << arg2 <<
" of row "
245 << arg1 <<
" which doesn't have that many elements.");
326 const std::vector<size_type> &n_entries_per_row);
372 const std::vector<size_type> &n_entries_per_row);
386 template <
typename SparsityPatternType>
388 copy_from(
const SparsityPatternType &nontrilinos_sparsity_pattern);
439 const MPI_Comm &communicator = MPI_COMM_WORLD,
454 const std::vector<size_type> &n_entries_per_row);
471 const IndexSet &col_parallel_partitioning,
472 const MPI_Comm &communicator = MPI_COMM_WORLD,
487 const IndexSet & col_parallel_partitioning,
489 const std::vector<size_type> &n_entries_per_row);
518 const IndexSet &col_parallel_partitioning,
520 const MPI_Comm &communicator = MPI_COMM_WORLD,
540 const MPI_Comm &communicator = MPI_COMM_WORLD,
556 const std::vector<size_type> &n_entries_per_row);
576 const IndexSet &col_parallel_partitioning,
577 const MPI_Comm &communicator = MPI_COMM_WORLD,
607 const IndexSet &col_parallel_partitioning,
609 const MPI_Comm &communicator = MPI_COMM_WORLD,
618 const IndexSet & col_parallel_partitioning,
620 const std::vector<size_type> &n_entries_per_row);
631 template <
typename SparsityPatternType>
634 const IndexSet & col_parallel_partitioning,
635 const SparsityPatternType &nontrilinos_sparsity_pattern,
636 const MPI_Comm & communicator = MPI_COMM_WORLD,
637 const bool exchange_data =
false);
647 template <
typename SparsityPatternType>
650 const SparsityPatternType &nontrilinos_sparsity_pattern,
651 const MPI_Comm & communicator = MPI_COMM_WORLD,
652 const bool exchange_data =
false);
704 std::pair<size_type, size_type>
783 template <
typename ForwardIterator>
786 ForwardIterator
begin,
788 const bool indices_are_sorted =
false);
799 const Epetra_FECrsGraph &
911 print(std::ostream &out,
912 const bool write_extended_trilinos_info =
false)
const;
941 <<
"An error with error number " << arg1
942 <<
" occurred while calling a Trilinos function");
950 <<
"The entry with index <" << arg1 <<
',' << arg2
951 <<
"> does not exist.");
958 "You are attempting an operation on two sparsity patterns that "
959 "are the same object, but the operation requires that the "
960 "two objects are in fact different.");
970 <<
"You tried to access element (" << arg1 <<
"/" << arg2
972 <<
" of a distributed matrix, but only rows in range ["
973 << arg3 <<
"," << arg4
974 <<
"] are stored locally and can be accessed.");
982 <<
"You tried to access element (" << arg1 <<
"/" << arg2
984 <<
" of a sparse matrix, but it appears to not"
985 <<
" exist in the Trilinos sparsity pattern.");
999 std::unique_ptr<Epetra_FECrsGraph>
graph;
1030 visit_present_row();
1036 Accessor::row()
const
1038 Assert(a_row < sparsity_pattern->n_rows(),
1039 ExcBeyondEndOfSparsityPattern());
1046 Accessor::column()
const
1048 Assert(a_row < sparsity_pattern->n_rows(),
1049 ExcBeyondEndOfSparsityPattern());
1050 return (*colnum_cache)[a_index];
1056 Accessor::index()
const
1058 Assert(a_row < sparsity_pattern->n_rows(),
1059 ExcBeyondEndOfSparsityPattern());
1068 : accessor(sp, row, index)
1073 inline Iterator::Iterator(
const Iterator &) =
default;
1080 Assert(accessor.a_row < accessor.sparsity_pattern->n_rows(),
1087 if (accessor.a_index >= accessor.colnum_cache->size())
1089 accessor.a_index = 0;
1092 while (accessor.a_row < accessor.sparsity_pattern->n_rows())
1094 const auto row_length =
1095 accessor.sparsity_pattern->row_length(accessor.a_row);
1096 if (row_length == 0 ||
1097 !accessor.sparsity_pattern->row_is_stored_locally(
1104 accessor.visit_present_row();
1114 const Iterator old_state = *
this;
1128 inline const Accessor *Iterator::operator->()
const
1138 return (accessor.a_row == other.accessor.a_row &&
1139 accessor.a_index == other.accessor.a_index);
1147 return !(*
this == other);
1155 return (accessor.row() < other.accessor.row() ||
1156 (accessor.row() == other.accessor.row() &&
1157 accessor.index() < other.accessor.index()));
1167 const size_type first_valid_row = this->local_range().first;
1213 SparsityPattern::in_local_range(
const size_type index)
const
1216# ifndef DEAL_II_WITH_64BIT_INDICES
1217 begin = graph->RowMap().MinMyGID();
1218 end = graph->RowMap().MaxMyGID() + 1;
1220 begin = graph->RowMap().MinMyGID64();
1221 end = graph->RowMap().MaxMyGID64() + 1;
1233 return graph->Filled();
1254 template <
typename ForwardIterator>
1257 ForwardIterator
begin,
1258 ForwardIterator
end,
1277 const_cast<typename std::decay<decltype(*
begin)
>::type *>(&*
begin));
1284 if (row_is_stored_locally(row))
1286 graph->InsertGlobalIndices(trilinos_row_index,
n_cols, col_index_ptr);
1287 else if (nonlocal_graph.get() !=
nullptr)
1292 Assert(nonlocal_graph->RowMap().LID(
1294 ExcMessage(
"Attempted to write into off-processor matrix row "
1295 "that has not be specified as being writable upon "
1297 ierr = nonlocal_graph->InsertGlobalIndices(trilinos_row_index,
1302 ierr = graph->InsertGlobalIndices(1,
1303 &trilinos_row_index,
1312 inline const Epetra_FECrsGraph &
1313 SparsityPattern::trilinos_sparsity_pattern()
const
1321 SparsityPattern::locally_owned_domain_indices()
const
1323 return IndexSet(graph->DomainMap());
1329 SparsityPattern::locally_owned_range_indices()
const
1331 return IndexSet(graph->RangeMap());
bool operator!=(const AlignedVector< T > &lhs, const AlignedVector< T > &rhs)
bool operator==(const AlignedVector< T > &lhs, const AlignedVector< T > &rhs)
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
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
size_type n_nonzero_elements() 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)
std::enable_if< std::is_floating_point< T >::value &&std::is_floating_point< U >::value, typenameProductType< std::complex< T >, std::complex< U > >::type >::type operator*(const std::complex< T > &left, const std::complex< U > &right)
#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 add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
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
SparsityPatternBase::const_iterator const_iterator
SparsityPatternBase::size_type size_type
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)
void add(const size_type i, const size_type j)
unsigned int row_length(const size_type row) const
bool is_compressed() const
types::global_dof_index size_type
VectorType::value_type * end(VectorType &V)
VectorType::value_type * begin(VectorType &V)
unsigned int global_dof_index
SynchronousIterators< Iterators > operator++(SynchronousIterators< Iterators > &a)
bool operator<(const SynchronousIterators< Iterators > &a, const SynchronousIterators< Iterators > &b)