Actual source code: ex6f.F90
1: !
2: ! Demonstrates use of MatShellSetContext() and MatShellGetContext()
3: !
4: ! Contributed by: Samuel Lanthaler
5: !
6: #include "petsc/finclude/petscmat.h"
7: module solver_context_ex6f
8: use petscsys
9: implicit none
10: type :: MatCtx
11: PetscReal :: lambda, kappa
12: PetscReal :: h
13: end type MatCtx
14: end module solver_context_ex6f
16: ! ----------------------------------------------------
17: ! main program
18: ! ----------------------------------------------------
19: program main
20: use petscmat
21: use solver_context_ex6f
22: implicit none
24: Mat :: F
25: type(MatCtx) :: ctxF
26: type(MatCtx), pointer :: ctxF_pt
27: PetscErrorCode :: ierr
28: PetscInt :: n = 128
30: PetscCallA(PetscInitialize(ierr))
31: ctxF%lambda = 3.14d0
32: PetscCallA(MatCreateShell(PETSC_COMM_WORLD, n, n, n, n, ctxF, F, ierr))
33: PetscCallA(MatShellSetContext(F, ctxF, ierr))
34: print *, 'ctxF%lambda = ', ctxF%lambda
36: PetscCallA(MatShellGetContext(F, ctxF_pt, ierr))
37: print *, 'ctxF_pt%lambda = ', ctxF_pt%lambda
39: PetscCallA(MatDestroy(F, ierr))
40: PetscCallA(PetscFinalize(ierr))
41: end program main
43: !/*TEST
44: !
45: ! build:
46: ! requires: double
47: !
48: ! test:
49: !
50: !TEST*/