Actual source code: ex120f.F90

  1: !
  2: !   This program tests MatCreateVecs() for Shell Matrix
  3: !
  4: #include <petsc/finclude/petscmat.h>
  5: module ex120fmodule
  6:   use petscmat
  7:   implicit none
  8:   PetscInt, parameter :: tw = 12
  9: contains
 10:   subroutine mymatgetvecs(A, x, y, ierr)

 12:     PetscErrorCode ierr
 13:     Mat A
 14:     Vec x, y

 16:     PetscCallA(VecCreateSeq(PETSC_COMM_SELF, tw, x, ierr))
 17:     PetscCallA(VecCreateSeq(PETSC_COMM_SELF, tw, y, ierr))
 18:   end
 19: end module ex120fmodule

 21: program main
 22:   use petscmat
 23:   use ex120fmodule
 24:   implicit none

 26:   PetscErrorCode ierr
 27:   Vec x, y
 28:   Mat m

 30:   PetscCallA(PetscInitialize(ierr))

 32:   PetscCallA(MatCreateShell(PETSC_COMM_SELF, tw, tw, tw, tw, 0, m, ierr))
 33:   PetscCallA(MatAssemblyBegin(m, MAT_FINAL_ASSEMBLY, ierr))
 34:   PetscCallA(MatAssemblyEnd(m, MAT_FINAL_ASSEMBLY, ierr))
 35:   PetscCallA(MatShellSetOperation(m, MATOP_CREATE_VECS, mymatgetvecs, ierr))
 36:   PetscCallA(MatCreateVecs(m, x, y, ierr))
 37:   PetscCallA(MatDestroy(m, ierr))
 38:   PetscCallA(VecDestroy(x, ierr))
 39:   PetscCallA(VecDestroy(y, ierr))
 40:   PetscCallA(PetscFinalize(ierr))
 41: end

 43: !/*TEST
 44: !
 45: !   test:
 46: !      nsize: 2
 47: !      output_file: output/empty.out
 48: !
 49: !TEST*/