1program newnonzero 2#include <petsc/finclude/petscmat.h> 3 use petscmat 4 implicit none 5 6 Mat :: A 7 PetscInt :: n,m,idxm(1),idxn(1),nl1,nl2,one,i 8 PetscScalar :: v(1) 9 PetscErrorCode :: ierr 10 11 call PetscInitialize(PETSC_NULL_CHARACTER,ierr) 12 one = 1 13 n=3 14 m=n 15 call MatCreateAIJ(PETSC_COMM_WORLD,PETSC_DECIDE,PETSC_DECIDE,n,m,1,PETSC_NULL_INTEGER,0,PETSC_NULL_INTEGER,A,ierr) 16 17 call MatGetOwnershipRange(A,nl1,nl2,ierr) 18 do i=nl1,nl2-1 19 idxn(1)=i 20 idxm(1)=i 21 v(1)=1.0 22 call MatSetValues(A,one,idxn,one,idxm, v,INSERT_VALUES,ierr) 23 end do 24 call MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr) 25 call MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr) 26 27! Ignore any values set into new nonzero locations 28 call MatSetOption(A,MAT_NEW_NONZERO_LOCATIONS,PETSC_FALSE,ierr) 29 30 idxn(1)=0 31 idxm(1)=n-1 32 if ((idxn(1).ge.nl1).and.(idxn(1).le.nl2-1)) then 33 v(1)=2.0 34 call MatSetValues(A,one,idxn,one,idxm, v,INSERT_VALUES,ierr);CHKERRA(ierr) 35 end if 36 call MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr) 37 call MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr) 38 39 if ((idxn(1).ge.nl1).and.(idxn(1).le.nl2-1)) then 40 call MatGetValues(A,one,idxn,one,idxm, v,ierr) 41 write(6,*) PetscRealPart(v) 42 end if 43 44 call MatDestroy(A,ierr) 45 call PetscFinalize(ierr) 46 47 end program newnonzero 48 49!/*TEST 50! 51! test: 52! nsize: 2 53! filter: Error: 54! 55! test: 56! requires: define(PETSC_USE_INFO) 57! suffix: 2 58! nsize: 2 59! args: -info 60! filter: grep "Skipping" 61! 62!TEST*/ 63