Actual source code: ex120f.F

petsc-3.9.2 2018-05-20
Report Typos and Errors
  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: !      prevent valgrind warning about uninitialized values
 44:       x = tVec(0)
 45:       y = tVec(0)
 46:       call MatCreateVecs(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

 53: !/*TEST
 54: !
 55: !   test:
 56: !      nsize: 2
 57: !
 58: !TEST*/