Actual source code: ex120f.F
petsc-3.12.2 2019-11-22
1: !
2: ! This program tests MatCreateVecs() for Shell Matrix
3: !
4: subroutine mymatgetvecs(A,x,y,ierr)
5: #include <petsc/finclude/petscmat.h>
6: use petscmat
7: implicit none
9: PetscErrorCode ierr
10: Mat A
11: Vec x,y
12: PetscInt tw
14: tw = 12
15: call VecCreateSeq(PETSC_COMM_SELF,tw,x,ierr)
16: call VecCreateSeq(PETSC_COMM_SELF,tw,y,ierr)
17: return
18: end
21: program main
22: #include <petsc/finclude/petscmat.h>
23: use petscmat
24: implicit none
26: PetscErrorCode ierr
27: Vec x,y
28: Mat m
29: PetscInt tw
30: external mymatgetvecs
32: call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
33: if (ierr .ne. 0) then
34: print*,'Unable to initialize PETSc'
35: stop
36: endif
38: tw = 12
39: call MatCreateShell(PETSC_COMM_SELF,tw,tw,tw,tw,0,m,ierr)
40: call MatAssemblyBegin(m,MAT_FINAL_ASSEMBLY,ierr)
41: call MatAssemblyEnd(m,MAT_FINAL_ASSEMBLY,ierr)
42: call MatShellSetOperation(m,MATOP_CREATE_VECS,mymatgetvecs,ierr)
43: call MatCreateVecs(m,x,y,ierr)
44: call MatDestroy(m,ierr)
45: call VecDestroy(x,ierr)
46: call VecDestroy(y,ierr)
47: call PetscFinalize(ierr)
48: end
50: !/*TEST
51: !
52: ! test:
53: ! nsize: 2
54: !
55: !TEST*/