[petsc-users] How to pass data to PETSc

Ted Sariyski tsariysk at craft-tech.com
Fri Nov 1 09:12:51 CDT 2013

On 10/31/2013 04:53 PM, Jed Brown wrote:
> 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?
Use KSP for solving a linear system.
>> 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.)
I'll do that. Thanks a lot.

More information about the petsc-users mailing list