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: {
9: PetscInt global_size=100;
10: Mat cuda_matrix;
11: Vec input,output;
12: MPI_Comm comm = PETSC_COMM_SELF;
13: PetscReal nrm = 1;
15: PetscInitialize(&argc,&argv,NULL,help);if (ierr) return ierr;
16: MatCreateDenseCUDA(comm,global_size,global_size,global_size,global_size,NULL,&cuda_matrix);
17: MatAssemblyBegin(cuda_matrix,MAT_FINAL_ASSEMBLY);
18: MatAssemblyEnd(cuda_matrix,MAT_FINAL_ASSEMBLY);
20: VecCreateSeqCUDA(comm,global_size,&input);
21: VecDuplicate(input,&output);
22: VecSet(input,1.);
23: VecSet(output,2.);
24: MatMult(cuda_matrix,input,output);
25: VecNorm(output,NORM_2,&nrm);
26: if (nrm > PETSC_SMALL) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_PLIB,"PETSc generated wrong result. Should be 0, but is %g",(double)nrm);
27: VecDestroy(&input);
28: VecDestroy(&output);
29: MatDestroy(&cuda_matrix);
30: PetscFinalize();
31: return ierr;
32: }
34: /*TEST
35: build:
36: requires: cuda
38: test:
39: nsize: 1
41: TEST*/