Skip to content
Snippets Groups Projects
Commit ef68ae0e authored by Markus Blatt's avatar Markus Blatt
Browse files

[!232] [!230] [bugfix] Use submatrix index vector to implement O(1) look-up

Merge branch 'cherry-pick-0f4b78a9' into 'releases/2.6'

ref:core/dune-istl Merge branch 'feature/fix-quadratic-umfpacksetup' into
'master'

ref:core/dune-istl Looking up if a column index is contained in submatrix
could degenerate to accumulated O(n) complexity for each row in the old
implementation. By setting up a look-up before, this can be improved to O(1).
Fortunately such a vector is constructed anyway so we can simple use it after
minor reordering of code.

This should fix [[#54]].

See merge request [[!230]]

Closes [#54]

(cherry picked from commit 0f4b78a9)

22a5ae5f \[bugfix\] Use submatrix index vector to implement O(1) look-up

See merge request [!232]

  [#54]: gitlab.dune-project.org/NoneNone/issues/54
  [!230]: gitlab.dune-project.org/core/dune-istl/merge_requests/230
  [!232]: gitlab.dune-project.org/core/dune-istl/merge_requests/232
parents 5d4f0c2a a158111d
No related branches found
No related tags found
1 merge request!232[!230] [bugfix] Use submatrix index vector to implement O(1) look-up
Pipeline #13405 passed
......@@ -266,8 +266,11 @@ namespace Dune
template<typename Iter>
void addRowNnz(const Iter& row) const;
template<typename Iter, typename Set>
void addRowNnz(const Iter& row, const Set& s) const;
template<typename Iter, typename FullMatrixIndex>
void addRowNnz(const Iter& row, const std::set<FullMatrixIndex>& indices) const;
template<typename Iter, typename SubMatrixIndex>
void addRowNnz(const Iter& row, const std::vector<SubMatrixIndex>& indices) const;
void allocate();
......@@ -323,12 +326,12 @@ namespace Dune
}
template<class T, class A, int n, int m>
template<typename Iter, typename Map>
template<typename Iter, typename FullMatrixIndex>
void ColCompMatrixInitializer<BCRSMatrix<FieldMatrix<T,n,m>,A> >::addRowNnz(const Iter& row,
const Map& indices) const
const std::set<FullMatrixIndex>& indices) const
{
typedef typename Iter::value_type::const_iterator RIter;
typedef typename Map::const_iterator MIter;
typedef typename std::set<FullMatrixIndex>::const_iterator MIter;
MIter siter =indices.begin();
for(RIter entry=row->begin(); entry!=row->end(); ++entry)
{
......@@ -341,6 +344,17 @@ namespace Dune
}
}
template<class T, class A, int n, int m>
template<typename Iter, typename SubMatrixIndex>
void ColCompMatrixInitializer<BCRSMatrix<FieldMatrix<T,n,m>,A> >::addRowNnz(const Iter& row,
const std::vector<SubMatrixIndex>& indices) const
{
using RIter = typename Iter::value_type::const_iterator;
for(RIter entry=row->begin(); entry!=row->end(); ++entry)
if (indices[entry.index()]!=std::numeric_limits<SubMatrixIndex>::max())
++mat->Nnz_;
}
template<class T, class A, int n, int m>
void ColCompMatrixInitializer<BCRSMatrix<FieldMatrix<T,n,m>,A> >::allocate()
{
......@@ -461,12 +475,6 @@ namespace Dune
typedef typename std::iterator_traits<Iter>::value_type row_type;
typedef typename row_type::const_iterator CIter;
// Calculate upper Bound for nonzeros
for(Iter row=mrs.begin(); row!= mrs.end(); ++row)
initializer.addRowNnz(row, mrs.rowIndexSet());
initializer.allocate();
typedef typename MRS::Matrix::size_type size_type;
// A vector containing the corresponding indices in
......@@ -479,6 +487,12 @@ namespace Dune
for(SIter index = mrs.rowIndexSet().begin(); index!=mrs.rowIndexSet().end(); ++index)
subMatrixIndex[*index]=s++;
// Calculate upper Bound for nonzeros
for(Iter row=mrs.begin(); row!= mrs.end(); ++row)
initializer.addRowNnz(row, subMatrixIndex);
initializer.allocate();
for(Iter row=mrs.begin(); row!= mrs.end(); ++row)
for(CIter col=row->begin(); col != row->end(); ++col) {
if(subMatrixIndex[col.index()]!=std::numeric_limits<size_type>::max())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment