[petsc-users] Simple query about GPU usage in PETSc
Matthew Knepley
knepley at gmail.com
Tue Dec 18 20:58:54 CST 2012
On Tue, Dec 18, 2012 at 9:17 PM, Gaurish Telang <gaurish108 at gmail.com> wrote:
> I am trying out PETSc's GPU features for the first time.
>
> After skimming, a paper on the PETSc-GPU interface.
> http://www.stanford.edu/~vminden/docs/gpus.pdf
>
> I just wanted to confirm whether the following observation is correct.
>
> Suppose I want to solve Ax=b and set the PETSc vector- and matrix-type
> from the command-line
>
> Then to make my code run on the GPU, *all* I need to do is to
> (1) set the "-vec_type" at the command-line as "seqcusp" or "mpicusp"
> (depending on whether I am using a single/multiple GPU process )
> (2) set the "-mat_type" at the command-line as "seqaijcusp" or
> "mpiaijcusp" (depending on whether I am using a single/multiple CPU process
> )
> (3) Solving the system Ax=b is done the "usual" way (see below) i.e
> nothing CUDA specific.
>
> ierr = KSPCreate(PETSC_COMM_WORLD,&ksp);CHKERRQ(ierr);
> ierr = KSPSetOperators(ksp,A,A,DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr);
> ierr = KSPGetPC(ksp,&pc);CHKERRQ(ierr);
> ierr = PCSetType(pc,PCJACOBI);CHKERRQ(ierr);
> ierr =
> KSPSetTolerances(ksp,1.e-5,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_DEFAULT);CHKERRQ(ierr);
>
> if (nonzeroguess) {
> PetscScalar p = .5;
> ierr = VecSet(x,p);CHKERRQ(ierr);
> ierr = KSPSetInitialGuessNonzero(ksp,PETSC_TRUE);CHKERRQ(ierr);
> }
> ierr = KSPSolve(ksp,b,x);CHKERRQ(ierr);
>
> (4) Looking at the type of the vector and the matrix, PETSc hands over the
> control to the corresponding CUSP solver.
Yes, that should work.
Matt
> Thank you,
>
> Gaurish
--
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which
their experiments lead.
-- Norbert Wiener
More information about the petsc-users
mailing list