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 PetscFunctionBeginUser; 15 PetscCall(PetscInitialize(&argc, &argv, NULL, help)); 16 PetscCall(MatCreateDenseCUDA(comm, global_size, global_size, global_size, global_size, NULL, &cuda_matrix)); 17 18 PetscCall(VecCreateSeqCUDA(comm, global_size, &input)); 19 PetscCall(VecDuplicate(input, &output)); 20 PetscCall(VecSet(input, 1.)); 21 PetscCall(VecSet(output, 2.)); 22 PetscCall(MatMult(cuda_matrix, input, output)); 23 PetscCall(VecNorm(output, NORM_2, &nrm)); 24 PetscCheck(nrm <= PETSC_SMALL, PETSC_COMM_SELF, PETSC_ERR_PLIB, "PETSc generated wrong result. Should be 0, but is %g", (double)nrm); 25 PetscCall(VecDestroy(&input)); 26 PetscCall(VecDestroy(&output)); 27 PetscCall(MatDestroy(&cuda_matrix)); 28 PetscCall(PetscFinalize()); 29 return 0; 30 } 31 32 /*TEST 33 build: 34 requires: cuda 35 36 test: 37 nsize: 1 38 output_file: output/empty.out 39 40 TEST*/ 41