]> https://gitweb.dealii.org/ - dealii.git/commitdiff
PetscWrappers::MatrixBase add column sizes accessors
authorStefano Zampini <stefano.zampini@gmail.com>
Mon, 10 Apr 2023 13:47:35 +0000 (16:47 +0300)
committerStefano Zampini <stefano.zampini@gmail.com>
Mon, 10 Apr 2023 13:47:35 +0000 (16:47 +0300)
include/deal.II/lac/petsc_matrix_base.h
source/lac/petsc_matrix_base.cc

index 215f8a0c8cfe45b064da57d242a4349a3f2fea56..148cc48944b80740747b46cb615ef6a7e77e9a62 100644 (file)
@@ -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<size_type, size_type>
+    local_domain() const;
+
     /**
      * Return a reference to the MPI communicator object in use with this
      * matrix.
index 43133ce0c34730c6dc16566c6b6d9c8a7212fb0e..35a5da42079477981f0fe16b1cab788740e0547e 100644 (file)
@@ -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::size_type, MatrixBase::size_type>
+  MatrixBase::local_domain() const
+  {
+    PetscInt begin, end;
+
+    const PetscErrorCode ierr =
+      MatGetOwnershipRangeColumn(static_cast<const Mat &>(matrix),
+                                 &begin,
+                                 &end);
+    AssertThrow(ierr == 0, ExcPETScError(ierr));
+
+    return std::make_pair(begin, end);
+  }
+
+
+
   std::uint64_t
   MatrixBase::n_nonzero_elements() const
   {

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.