Actual source code: ex219f.F90

  1: program newnonzero
  2: #include <petsc/finclude/petscmat.h>
  3:  use petscmat
  4:  implicit none

  6:  Mat :: A
  7:  PetscInt :: n,m,idxm(1),idxn(1),nl1,nl2,zero,one,i
  8:  PetscScalar :: v(1)
  9:  PetscErrorCode :: ierr

 11:  call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
 12:  zero = 0
 13:  one = 1
 14:  n=3
 15:  m=n
 16:  call MatCreateAIJ(PETSC_COMM_WORLD,PETSC_DECIDE,PETSC_DECIDE,n,m,one,PETSC_NULL_INTEGER,zero,PETSC_NULL_INTEGER,A,ierr)


 19:  call MatGetOwnershipRange(A,nl1,nl2,ierr)
 20:  do i=nl1,nl2-1
 21:    idxn(1)=i
 22:    idxm(1)=i
 23:    v(1)=1.0
 24:    call MatSetValues(A,one,idxn,one,idxm, v,INSERT_VALUES,ierr)
 25:  end do
 26:  call MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr)
 27:  call MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr)

 29: ! Ignore any values set into new nonzero locations
 30:  call MatSetOption(A,MAT_NEW_NONZERO_LOCATIONS,PETSC_FALSE,ierr)

 32:  idxn(1)=0
 33:  idxm(1)=n-1
 34:  if ((idxn(1).ge.nl1).and.(idxn(1).le.nl2-1)) then
 35:    v(1)=2.0
 36:    call MatSetValues(A,one,idxn,one,idxm, v,INSERT_VALUES,ierr);CHKERRA(ierr)
 37:  end if
 38:  call MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr)
 39:  call MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr)

 41:  if ((idxn(1).ge.nl1).and.(idxn(1).le.nl2-1)) then
 42:    call MatGetValues(A,one,idxn,one,idxm, v,ierr)
 43:    write(6,*) PetscRealPart(v)
 44:  end if

 46:  call MatDestroy(A,ierr)
 47:  call PetscFinalize(ierr)

 49:  end program newnonzero

 51: !/*TEST
 52: !
 53: !     test:
 54: !       nsize: 2
 55: !       filter: Error:
 56: !
 57: !     test:
 58: !       requires: define(PETSC_USE_INFO)
 59: !       suffix: 2
 60: !       nsize: 2
 61: !       args: -info
 62: !       filter: grep "Skipping"
 63: !
 64: !TEST*/