Actual source code: ex120f.F
petsc-3.4.2 2013-07-02

      1: !
      2: !   This program tests MatGetVecs() for Shell Matrix
      3: !
      4:       subroutine mymatgetvecs(A,x,y,ierr)
      5:       implicit none

      7: #include <finclude/petscsys.h>
      8: #include <finclude/petscis.h>
      9: #include <finclude/petscvec.h>
     10: #include <finclude/petscmat.h>
     11:       PetscErrorCode ierr
     12:       Mat A
     13:       Vec x,y

     15:       if (x .ne. -1) then
     16:         call VecCreateSeq(PETSC_COMM_SELF,12,x,ierr)
     17:       endif
     18:       if (y .ne. -1) then
     19:         call VecCreateSeq(PETSC_COMM_SELF,12,y,ierr)
     20:       endif

     22:       return
     23:       end

     26:       program main
     27:       implicit none

     29: #include <finclude/petscsys.h>
     30: #include <finclude/petscis.h>
     31: #include <finclude/petscvec.h>
     32: #include <finclude/petscmat.h>
     33: #include <finclude/petscviewer.h>

     35:       PetscErrorCode ierr
     36:       Vec     x,y
     37:       Mat     m
     38:       external  mymatgetvecs

     40:       call PetscInitialize(PETSC_NULL_CHARACTER,ierr)

     42:       call MatCreateShell(PETSC_COMM_SELF,12,12,12,12,0,m,ierr)
     43:       call MatAssemblyBegin(m,MAT_FINAL_ASSEMBLY,ierr)
     44:       call MatAssemblyEnd(m,MAT_FINAL_ASSEMBLY,ierr)
     45:       call MatShellSetOperation(m,MATOP_GET_VECS,mymatgetvecs,ierr)
     46:       call MatGetVecs(m,x,y,ierr)
     47:       call MatDestroy(m,ierr)
     48:       call VecDestroy(x,ierr)
     49:       call VecDestroy(y,ierr)
     50:       call PetscFinalize(ierr)
     51:       end