[petsc-users] Simple query about GPU usage in PETSc

Gaurish Telang gaurish108 at gmail.com
Tue Dec 18 20:17:54 CST 2012


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.



Thank you,

Gaurish
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20121218/78fedb8a/attachment.html>


More information about the petsc-users mailing list