From: Stefano Zampini Date: Mon, 10 Apr 2023 13:47:35 +0000 (+0300) Subject: PetscWrappers::MatrixBase add column sizes accessors X-Git-Tag: v9.5.0-rc1~336^2~4 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8af1289a265dd6d50958719b849d8b912e15378;p=dealii.git PetscWrappers::MatrixBase add column sizes accessors --- diff --git a/include/deal.II/lac/petsc_matrix_base.h b/include/deal.II/lac/petsc_matrix_base.h index 215f8a0c8c..148cc48944 100644 --- a/include/deal.II/lac/petsc_matrix_base.h +++ b/include/deal.II/lac/petsc_matrix_base.h @@ -678,6 +678,24 @@ namespace PETScWrappers bool in_local_range(const size_type index) const; + /** + * Return the local number of columns stored on the present MPI process. + * + * To figure out which elements exactly are stored locally, use + * local_domain(). + */ + size_type + local_domain_size() const; + + /** + * Return a pair of indices indicating which columns of this matrix are + * stored locally. The first number is the index of the first column stored, + * the second the index of the one past the last one that is stored + * locally. + */ + std::pair + local_domain() const; + /** * Return a reference to the MPI communicator object in use with this * matrix. diff --git a/source/lac/petsc_matrix_base.cc b/source/lac/petsc_matrix_base.cc index 43133ce0c3..35a5da4207 100644 --- a/source/lac/petsc_matrix_base.cc +++ b/source/lac/petsc_matrix_base.cc @@ -307,9 +307,9 @@ namespace PETScWrappers MatrixBase::size_type MatrixBase::local_size() const { - PetscInt n_rows, n_cols; + PetscInt n_rows; - const PetscErrorCode ierr = MatGetLocalSize(matrix, &n_rows, &n_cols); + const PetscErrorCode ierr = MatGetLocalSize(matrix, &n_rows, nullptr); AssertThrow(ierr == 0, ExcPETScError(ierr)); return n_rows; @@ -331,6 +331,35 @@ namespace PETScWrappers + MatrixBase::size_type + MatrixBase::local_domain_size() const + { + PetscInt n_cols; + + const PetscErrorCode ierr = MatGetLocalSize(matrix, nullptr, &n_cols); + AssertThrow(ierr == 0, ExcPETScError(ierr)); + + return n_cols; + } + + + + std::pair + MatrixBase::local_domain() const + { + PetscInt begin, end; + + const PetscErrorCode ierr = + MatGetOwnershipRangeColumn(static_cast(matrix), + &begin, + &end); + AssertThrow(ierr == 0, ExcPETScError(ierr)); + + return std::make_pair(begin, end); + } + + + std::uint64_t MatrixBase::n_nonzero_elements() const {