Skip to content

Commit

Permalink
reset -> reset_memory
Browse files Browse the repository at this point in the history
  • Loading branch information
lindsayad committed Nov 5, 2024
1 parent 8c19cbe commit 17dc9e1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
2 changes: 2 additions & 0 deletions include/numerics/petsc_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ class PetscMatrix final : public PetscMatrixBase<T>

virtual bool supports_hash_table() const override { return true; }

virtual void reset_memory() override;

protected:
/**
* Perform matrix initialization steps sans preallocation
Expand Down
4 changes: 0 additions & 4 deletions include/numerics/petsc_matrix_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ class PetscMatrixBase : public SparseMatrix<T>

virtual bool closed() const override;

#if PETSC_RELEASE_GREATER_EQUALS(3,23,0)
virtual void reset () override;
#endif

protected:

/**
Expand Down
7 changes: 2 additions & 5 deletions include/numerics/sparse_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,9 @@ class SparseMatrix : public ReferenceCountedObject<SparseMatrix<T>>,
bool use_hash_table() const { return _use_hash_table; }

/**
* Reset the state of the matrix. The default implementation calls \p clear() but this is meant to
* be more nuanced in that it can reset the state of the matrix without deallocating core data
* structures. As an example, this would not destroy the \p Mat data member for PETSc matrix
* derived classes
* Reset the memory storage of the matrix
*/
virtual void reset() { this->clear(); }
virtual void reset_memory() { libmesh_not_implemented(); }

protected:
/**
Expand Down
15 changes: 15 additions & 0 deletions src/numerics/petsc_matrix.C
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,21 @@ PetscMatrix<T>::copy_from_hash ()
}
#endif

template <typename T>
void
PetscMatrix<T>::reset_memory()
{
if (this->_use_hash_table)
#if PETSC_RELEASE_GREATER_EQUALS(3, 23, 0)
// This performs MatReset plus re-establishes the hash table
LibmeshPetscCall(MatResetHash(this->_mat));
#else
libmesh_error_msg("Hash tables not fully supported until PETSc version 3.23");
#endif
else
this->reset_preallocation();
}

//------------------------------------------------------------------
// Explicit instantiations
template class LIBMESH_EXPORT PetscMatrix<Number>;
Expand Down
13 changes: 0 additions & 13 deletions src/numerics/petsc_matrix_base.C
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,6 @@ bool PetscMatrixBase<T>::closed() const
return (assembled == PETSC_TRUE);
}

#if PETSC_RELEASE_GREATER_EQUALS(3,23,0)
template <typename T>
void
PetscMatrixBase<T>::reset()
{
if (this->_use_hash_table)
// This performs MatReset plus re-establishes the hash table
LibmeshPetscCall(MatResetHash(this->_mat));
else
LibmeshPetscCall(MatReset(this->_mat));
}
#endif

//------------------------------------------------------------------
// Explicit instantiations
template class LIBMESH_EXPORT PetscMatrixBase<Number>;
Expand Down

0 comments on commit 17dc9e1

Please sign in to comment.