xref: /petsc/src/mat/tests/ex239.c (revision ffa8c5705e8ab2cf85ee1d14dbe507a6e2eb5283)
1 static char help[] = "Test device/host memory allocation in MatDenseSeqCUDA()\n\n";
2 
3 /* Contributed by: Victor Eijkhout <eijkhout@tacc.utexas.edu> */
4 
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;
13 
14   PetscCall(PetscInitialize(&argc,&argv,NULL,help));
15   PetscCall(MatCreateDenseCUDA(comm,global_size,global_size,global_size,global_size,NULL,&cuda_matrix));
16   PetscCall(MatAssemblyBegin(cuda_matrix,MAT_FINAL_ASSEMBLY));
17   PetscCall(MatAssemblyEnd(cuda_matrix,MAT_FINAL_ASSEMBLY));
18 
19   PetscCall(VecCreateSeqCUDA(comm,global_size,&input));
20   PetscCall(VecDuplicate(input,&output));
21   PetscCall(VecSet(input,1.));
22   PetscCall(VecSet(output,2.));
23   PetscCall(MatMult(cuda_matrix,input,output));
24   PetscCall(VecNorm(output,NORM_2,&nrm));
25   PetscCheckFalse(nrm > PETSC_SMALL,PETSC_COMM_SELF,PETSC_ERR_PLIB,"PETSc generated wrong result. Should be 0, but is %g",(double)nrm);
26   PetscCall(VecDestroy(&input));
27   PetscCall(VecDestroy(&output));
28   PetscCall(MatDestroy(&cuda_matrix));
29   PetscCall(PetscFinalize());
30   return 0;
31 }
32 
33 /*TEST
34    build:
35      requires: cuda
36 
37    test:
38     nsize: 1
39 
40 TEST*/
41