[petsc-users] The Matrix and Vector Format Convert between PETSc and HYPRE

Mark Adams mfadams at lbl.gov
Mon Feb 7 09:40:51 CST 2022


On Mon, Feb 7, 2022 at 9:17 AM Sijie Tang <sijietang1995 at gmail.com> wrote:

> I make a mistake there is no hypre_ParCSRVector, that should be
> hypre_ParVector.
>
> Sijie
>
> On Feb 5, 2022, at 21:53, Sijie Tang <sijietang1995 at gmail.com> wrote:
>
> Hi developer,
>
> I have many questions about he Matrix and Vector Format Convert between
> PETSc and HYPRE, could you give me some answers or hints?
>
>
>    1. Can I convert MATHYPRE (in PETSc) to hypre_ParCSRMatrix ( HYPRE )
>    use function MatHYPREGetParCSR() (in PETSc) ?
>
> You specify a hypre matrix with '-mat_type hypre' and then you can use:

PetscErrorCode MatHYPREGetParCSR(Mat A, hypre_ParCSRMatrix **parcsr)


>
>    1. for 2, or I should use MatHYPRE_IJMatrixCreate  and
>    MatHYPRE_IJMatrixCopy to get hypre_IJMatrix, then hypre_IJMatrix
>    convert to hypre_ParCSRMatrix ?
>
> Not sure. It easier to use MatSetFromOptions and '-mat_type hypre'  as
above

>
>    1. for the vector, I don't find any function can convert vector in
>    PETSc to hypre_ParCSRVector, Is there any function can do this work ?
>
> We don't use hypre vectors, or at least we don't expose them. You specify
the vector type (CPU is the default) like -vec_type cuda
Then you use a normal Vec in your code. And use MatCreateVecs to get the
right type. Hypre will use the device if it is available and MatCreateVecs
will create the correct type.

>
>    1. But I find I can use VecHYPRE_IJVectorCreate and VecHYPRE_IJVectorCopy
>    to get hypre_IJVector, then hypre_IJVector convert to
>    hypre_ParCSRVector?
>    2. Is there any function can convert the format back? like hypre_ParCSRMatrix
>    convert to MATHYPRE,
>
> Maybe. I don't see docs on this (very new) but I see:

include/petscmathypre.h:PETSC_EXTERN PetscErrorCode
MatCreateFromParCSR(hypre_ParCSRMatrix*,MatType,PetscCopyMode,Mat*);

And there is a test that you should look at that tests hypre matrices:

src/mat/tests/ex115.c

Mark

>
>    1. and hypre_ParCSRVector convert to PETSc's vector?
>
>
> Thanks,
> Sijie
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220207/46b4df25/attachment.html>


More information about the petsc-users mailing list