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

  9: contains
 10:   subroutine mymatgetvecs(A, x, y, ierr)

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

 17:     tw = 12
 18:     PetscCallA(VecCreateSeq(PETSC_COMM_SELF, tw, x, ierr))
 19:     PetscCallA(VecCreateSeq(PETSC_COMM_SELF, tw, y, ierr))
 20:   end
 21: end module ex120fmodule

 23: program main
 24:   use petscmat
 25:   use ex120fmodule
 26:   implicit none

 28:   PetscErrorCode ierr
 29:   Vec x, y
 30:   Mat m
 31:   PetscInt tw

 33:   PetscCallA(PetscInitialize(ierr))

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

 47: !/*TEST
 48: !
 49: !   test:
 50: !      nsize: 2
 51: !      output_file: output/empty.out
 52: !
 53: !TEST*/