Actual source code: ex58.c


  2: static char help[] = "Test VecCreate{Seq|MPI}CUDAWithArrays.\n\n";

  4: #include "petsc.h"

  6: int main(int argc,char **argv)
  7: {
  8:   Vec         x,y;
  9:   PetscMPIInt size;
 10:   PetscInt    n        = 5;
 11:   PetscScalar xHost[5] = {0.,1.,2.,3.,4.};

 13:   PetscInitialize(&argc, &argv, (char*)0, help);
 14:   MPI_Comm_size(PETSC_COMM_WORLD,&size);

 16:   if (size == 1) VecCreateSeqCUDAWithArrays(PETSC_COMM_WORLD,1,n,xHost,NULL,&x);
 17:   else VecCreateMPICUDAWithArrays(PETSC_COMM_WORLD,1,n,PETSC_DECIDE,xHost,NULL,&x);

 19:   /* print x should be equivalent too xHost */
 20:   VecView(x,PETSC_VIEWER_STDOUT_WORLD);
 21:   VecSet(x,42.0);
 22:   /* print x should be all 42 */
 23:   VecView(x,PETSC_VIEWER_STDOUT_WORLD);

 25:   if (size == 1) VecCreateSeqWithArray(PETSC_COMM_WORLD,1,n,xHost,&y);
 26:   else VecCreateMPIWithArray(PETSC_COMM_WORLD,1,n,PETSC_DECIDE,xHost,&y);

 28:   /* print y should be all 42 */
 29:   VecView(y, PETSC_VIEWER_STDOUT_WORLD);

 31:   VecDestroy(&y);
 32:   VecDestroy(&x);
 33:   PetscFinalize();
 34:   return 0;
 35: }

 37: /*TEST

 39:    build:
 40:       requires: cuda

 42:    test:
 43:       nsize: 1
 44:       suffix: 1

 46:    test:
 47:       nsize: 2
 48:       suffix: 2

 50: TEST*/