16 #ifndef dealii_chunk_sparsity_pattern_h
17 #define dealii_chunk_sparsity_pattern_h
327 const std::vector<size_type> &row_lengths,
350 const std::vector<size_type> &row_lengths,
397 const std::vector<size_type> &row_lengths,
499 template <
typename ForwardIterator>
503 const ForwardIterator
begin,
504 const ForwardIterator
end,
512 template <
typename SparsityPatternType>
523 template <
typename number>
544 template <
typename Sparsity>
548 const Sparsity &sparsity_pattern_for_chunks,
550 const bool optimize_diagonal =
true);
730 print(std::ostream &out)
const;
764 <<
"The provided number is invalid here: " << arg1);
771 <<
"The given index " << arg1 <<
" should be less than "
779 <<
"Upon entering a new entry to row " << arg1
780 <<
": there was no free entry any more. " << std::endl
781 <<
"(Maximum number of entries for this row: " << arg2
782 <<
"; maybe the matrix is already compressed?)");
789 "The operation you attempted is only allowed after the SparsityPattern "
790 "has been set up and compress() was called.");
797 "The operation you attempted changes the structure of the SparsityPattern "
798 "and is not possible after compress() has been called.");
809 <<
"The iterators denote a range of " << arg1
810 <<
" elements, but the given number of rows was " << arg2);
820 <<
"The number of partitions you gave is " << arg1
821 <<
", but must be greater than zero.");
828 <<
"The array has size " << arg1 <<
" but should have size "
871 : sparsity_pattern(sparsity_pattern)
872 , reduced_accessor(row == sparsity_pattern->n_rows() ?
873 *sparsity_pattern->sparsity_pattern.
end() :
874 *sparsity_pattern->sparsity_pattern.
begin(
875 row / sparsity_pattern->get_chunk_size()))
876 , chunk_row(row == sparsity_pattern->n_rows() ?
878 row % sparsity_pattern->get_chunk_size())
885 : sparsity_pattern(sparsity_pattern)
886 , reduced_accessor(*sparsity_pattern->sparsity_pattern.
end())
894 Accessor::is_valid_entry()
const
896 return reduced_accessor.is_valid_entry() &&
899 sparsity_pattern->n_rows() &&
900 sparsity_pattern->get_chunk_size() * reduced_accessor.column() +
902 sparsity_pattern->n_cols();
908 Accessor::row()
const
912 return sparsity_pattern->get_chunk_size() * reduced_accessor.row() +
919 Accessor::column()
const
923 return sparsity_pattern->get_chunk_size() * reduced_accessor.column() +
930 Accessor::reduced_index()
const
934 return reduced_accessor.linear_index;
945 return (reduced_accessor == other.reduced_accessor &&
946 chunk_row == other.chunk_row && chunk_col == other.chunk_col);
956 if (chunk_row != other.chunk_row)
958 if (reduced_accessor.linear_index ==
959 reduced_accessor.container->n_nonzero_elements())
961 if (other.reduced_accessor.linear_index ==
962 reduced_accessor.container->n_nonzero_elements())
965 const auto global_row = sparsity_pattern->get_chunk_size() *
966 reduced_accessor.row() +
968 other_global_row = sparsity_pattern->get_chunk_size() *
969 other.reduced_accessor.row() +
971 if (global_row < other_global_row)
973 else if (global_row > other_global_row)
978 reduced_accessor.linear_index < other.reduced_accessor.linear_index ||
979 (reduced_accessor.linear_index == other.reduced_accessor.linear_index &&
980 chunk_col < other.chunk_col));
987 const auto chunk_size = sparsity_pattern->get_chunk_size();
991 sparsity_pattern->n_rows() &&
992 reduced_accessor.column() *
chunk_size + chunk_col <
993 sparsity_pattern->n_cols(),
997 reduced_accessor.advance();
1005 reduced_accessor.column() *
chunk_size + chunk_col ==
1006 sparsity_pattern->n_cols())
1008 const auto reduced_row = reduced_accessor.row();
1010 if (reduced_accessor.linear_index + 1 ==
1011 reduced_accessor.container->rowstart[reduced_row + 1])
1020 sparsity_pattern->n_rows()))
1023 reduced_accessor.advance();
1028 reduced_accessor.linear_index =
1029 reduced_accessor.container->rowstart[reduced_row];
1034 reduced_accessor.advance();
1044 : accessor(sparsity_pattern, row)
1061 const Iterator iter = *
this;
1068 inline const Accessor &
1076 inline const Accessor *
1077 Iterator::operator->()
const
1086 return (accessor == other.accessor);
1094 return !(accessor == other.accessor);
1101 return accessor < other.accessor;
1136 return {
this, r + 1};
1172 template <
typename ForwardIterator>
1176 const ForwardIterator
begin,
1177 const ForwardIterator
end,
1188 std::vector<size_type> row_lengths;
1189 row_lengths.reserve(
n_rows);
1190 for (ForwardIterator i =
begin; i !=
end; ++i)
1191 row_lengths.push_back(std::distance(i->begin(), i->end()) +
1192 (is_square ? 1 : 0));
1197 using inner_iterator =
1198 typename std::iterator_traits<ForwardIterator>::value_type::const_iterator;
1199 for (ForwardIterator i =
begin; i !=
end; ++i, ++row)
1201 const inner_iterator end_of_row = i->end();
1202 for (inner_iterator j = i->begin(); j != end_of_row; ++j)
bool operator!=(const AlignedVector< T > &lhs, const AlignedVector< T > &rhs)
bool operator==(const AlignedVector< T > &lhs, const AlignedVector< T > &rhs)
SparsityPatternIterators::Accessor reduced_accessor
bool is_valid_entry() const
Accessor(const ChunkSparsityPattern *matrix, const size_type row)
std::size_t reduced_index() const
bool operator<(const Accessor &) const
types::global_dof_index size_type
Accessor(const ChunkSparsityPattern *matrix)
bool operator==(const Accessor &) const
const ChunkSparsityPattern * sparsity_pattern
bool operator!=(const Iterator &) const
bool operator==(const Iterator &) const
const Accessor * operator->() const
const Accessor & operator*() const
Iterator(const ChunkSparsityPattern *sp, const size_type row)
types::global_dof_index size_type
bool operator<(const Iterator &) const
void create_from(const size_type m, const size_type n, const Sparsity &sparsity_pattern_for_chunks, const size_type chunk_size, const bool optimize_diagonal=true)
void add(const size_type i, const size_type j)
void block_write(std::ostream &out) const
bool stores_only_added_elements() const
~ChunkSparsityPattern() override=default
static const size_type invalid_entry
std::size_t memory_consumption() const
types::global_dof_index size_type
bool exists(const size_type i, const size_type j) const
iterator end(const size_type r) const
void reinit(const size_type m, const size_type n, const size_type max_per_row, const size_type chunk_size)
void print_gnuplot(std::ostream &out) const
void block_read(std::istream &in)
bool is_compressed() const
ChunkSparsityPattern & operator=(const ChunkSparsityPattern &)
size_type max_entries_per_row() const
size_type bandwidth() const
size_type n_nonzero_elements() const
SparsityPattern sparsity_pattern
size_type row_length(const size_type row) const
void print(std::ostream &out) const
size_type get_chunk_size() const
void copy_from(const size_type n_rows, const size_type n_cols, const ForwardIterator begin, const ForwardIterator end, const size_type chunk_size)
iterator begin(const size_type r) const
static constexpr size_type invalid_entry
std::enable_if_t< std::is_floating_point< T >::value &&std::is_floating_point< U >::value, typename ProductType< std::complex< T >, std::complex< U > >::type > operator*(const std::complex< T > &left, const std::complex< U > &right)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcMETISNotInstalled()
#define DeclException0(Exception0)
static ::ExceptionBase & ExcInvalidArraySize(size_type arg1, size_type arg2)
static ::ExceptionBase & ExcInvalidIndex(size_type arg1, size_type arg2)
static ::ExceptionBase & ExcNotCompressed()
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcNotEnoughSpace(size_type arg1, size_type arg2)
static ::ExceptionBase & ExcIteratorRange(size_type arg1, size_type arg2)
static ::ExceptionBase & ExcIteratorPastEnd()
#define Assert(cond, exc)
static ::ExceptionBase & ExcInvalidIterator()
#define DeclException2(Exception2, type1, type2, outsequence)
static ::ExceptionBase & ExcInvalidNumberOfPartitions(size_type arg1)
#define AssertIndexRange(index, range)
#define DeclExceptionMsg(Exception, defaulttext)
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcEmptyObject()
static ::ExceptionBase & ExcMatrixIsCompressed()
static ::ExceptionBase & ExcInvalidNumber(size_type arg1)
@ matrix
Contents is actually a matrix.
types::global_dof_index size_type
VectorType::value_type * begin(VectorType &V)
VectorType::value_type * end(VectorType &V)
unsigned int global_dof_index
SynchronousIterators< Iterators > operator++(SynchronousIterators< Iterators > &a)
bool operator<(const SynchronousIterators< Iterators > &a, const SynchronousIterators< Iterators > &b)
void advance(std::tuple< I1, I2 > &t, const unsigned int n)