Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Petsc mat mpi getter #14575

Merged
merged 3 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/news/changes/minor/20221213StefanoZampini-b
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed: Add default MPI getter for PETSc Mat objects, that queries the underlying PETSc type.
<br>
(Stefano Zampini, 2022/12/13)
20 changes: 18 additions & 2 deletions include/deal.II/lac/petsc_matrix_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ namespace PETScWrappers
*/
MatrixBase();

/**
* Initialize a Matrix from a PETSc Mat object. Note that we do not copy
* the matrix.
luca-heltai marked this conversation as resolved.
Show resolved Hide resolved
*/
explicit MatrixBase(const Mat &);

/**
* Copy constructor. It is deleted as copying this base class
* without knowing the concrete kind of matrix stored may both
Expand Down Expand Up @@ -335,6 +341,7 @@ namespace PETScWrappers
*/
MatrixBase &
operator=(const value_type d);

/**
* Release all memory and return to a state just like after having called
* the default constructor.
Expand Down Expand Up @@ -643,10 +650,11 @@ namespace PETScWrappers

/**
* Return a reference to the MPI communicator object in use with this
* matrix. This function has to be implemented in derived classes.
* matrix. If not implemented, it returns the communicator used by the
* PETSc Mat.
*/
virtual const MPI_Comm &
get_mpi_communicator() const = 0;
get_mpi_communicator() const;

/**
* Return the number of nonzero elements of this matrix. Actually, it
Expand Down Expand Up @@ -1610,6 +1618,14 @@ namespace PETScWrappers
prepare_action(VectorOperation::insert);
}

inline const MPI_Comm &
MatrixBase::get_mpi_communicator() const
{
static MPI_Comm comm;
PetscObjectGetComm(reinterpret_cast<PetscObject>(matrix), &comm);
drwells marked this conversation as resolved.
Show resolved Hide resolved
return comm;
}

# endif // DOXYGEN
} // namespace PETScWrappers

Expand Down
10 changes: 10 additions & 0 deletions source/lac/petsc_matrix_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ namespace PETScWrappers
{}


MatrixBase::MatrixBase(const Mat &A)
: matrix(A)
, last_action(VectorOperation::unknown)
{
const PetscErrorCode ierr =
PetscObjectReference(reinterpret_cast<PetscObject>(matrix));
AssertNothrow(ierr == 0, ExcPETScError(ierr));
(void)ierr;
luca-heltai marked this conversation as resolved.
Show resolved Hide resolved
}


MatrixBase::~MatrixBase()
{
Expand Down