Actual source code: ex120f.F

  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

 20:       program main
 21: #include <petsc/finclude/petscmat.h>
 22:       use petscmat
 23:       implicit none

 25:       PetscErrorCode ierr
 26:       Vec     x,y
 27:       Mat     m
 28:       PetscInt tw
 29:       external  mymatgetvecs

 31:       call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
 32:       if (ierr .ne. 0) then
 33:         print*,'Unable to initialize PETSc'
 34:         stop
 35:       endif

 37:       tw = 12
 38:       call MatCreateShell(PETSC_COMM_SELF,tw,tw,tw,tw,0,m,ierr)
 39:       call MatAssemblyBegin(m,MAT_FINAL_ASSEMBLY,ierr)
 40:       call MatAssemblyEnd(m,MAT_FINAL_ASSEMBLY,ierr)
 41:       call MatShellSetOperation(m,MATOP_CREATE_VECS,mymatgetvecs,ierr)
 42:       call MatCreateVecs(m,x,y,ierr)
 43:       call MatDestroy(m,ierr)
 44:       call VecDestroy(x,ierr)
 45:       call VecDestroy(y,ierr)
 46:       call PetscFinalize(ierr)
 47:       end

 49: !/*TEST
 50: !
 51: !   test:
 52: !      nsize: 2
 53: !
 54: !TEST*/