[petsc-users] How to pass data to PETSc

Jed Brown jedbrown at mcs.anl.gov
Thu Oct 31 15:53:29 CDT 2013


Ted Sariyski <tsariysk at craft-tech.com> writes:

> Hi,
> I am about to use PETSc linear algebra. Two questions.
>
> Q1: I have the stiffness matrix and the rhs vector assembled (outside) 
> and in PETSc order. Do I still need to create a scatter:"ierr = 
> VecScatterCreate(bb,isglobal,localX,islocal,&scatter)"?

What do you want to do with the Vec?

> Q2: I have PETSc vectors and matrix set:
>
> ierr = VecCreate(MPI_COMM_WORLD,&bb);CHKERRQ(ierr);
> ierr = VecSetFromOptions(bb);CHKERRQ(ierr);CHKPT
> ierr = VecSetSizes(bb,Nvlocal,Nvglobal);CHKERRQ(ierr);
> ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);
> ierr = MatSetSizes(A,Nvlocal,Nvlocal,Nvglobal,Nvglobal);CHKERRQ(ierr);
>
> I passed the rhs myData to bb using VecSetValues:
> ierr = VecSetValues(bb,Nvlocal,vertices,myData,INSERT_VALUES);CHKERRQ(ierr);
>
> The matrix is in HYPRE sparse format. What is the recommended way to 
> pass it to A?

Best is to use MatSetValues while you are generating the matrix entries
(so that you don't store the Hypre format).  You can always do this
afterward.  (The Hypre matrix can't be used directly because Hypre does
not expose a complete set of functionality.  There is not a conversion
routine in PETSc, though it would be easy to add.)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20131031/a480e29f/attachment.pgp>


More information about the petsc-users mailing list