Actual source code: ex239.c

  1: static char help[] = "Test device/host memory allocation in MatDenseSeqCUDA()\n\n";

  3: /* Contributed by: Victor Eijkhout <eijkhout@tacc.utexas.edu> */

  5: #include <petscmat.h>
  6: int main(int argc, char** argv)
  7: {
  8:   PetscInt  global_size = 100;
  9:   Mat       cuda_matrix;
 10:   Vec       input,output;
 11:   MPI_Comm  comm        = PETSC_COMM_SELF;
 12:   PetscReal nrm         = 1;

 14:   PetscInitialize(&argc,&argv,NULL,help);
 15:   MatCreateDenseCUDA(comm,global_size,global_size,global_size,global_size,NULL,&cuda_matrix);
 16:   MatAssemblyBegin(cuda_matrix,MAT_FINAL_ASSEMBLY);
 17:   MatAssemblyEnd(cuda_matrix,MAT_FINAL_ASSEMBLY);

 19:   VecCreateSeqCUDA(comm,global_size,&input);
 20:   VecDuplicate(input,&output);
 21:   VecSet(input,1.);
 22:   VecSet(output,2.);
 23:   MatMult(cuda_matrix,input,output);
 24:   VecNorm(output,NORM_2,&nrm);
 26:   VecDestroy(&input);
 27:   VecDestroy(&output);
 28:   MatDestroy(&cuda_matrix);
 29:   PetscFinalize();
 30:   return 0;
 31: }

 33: /*TEST
 34:    build:
 35:      requires: cuda

 37:    test:
 38:     nsize: 1

 40: TEST*/