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 18 call MatGetOwnershipRange(A,nl1,nl2,ierr) 19 do i=nl1,nl2-1 20 idxn(1)=i 21 idxm(1)=i 22 v(1)=1.0 23 call MatSetValues(A,one,idxn,one,idxm, v,INSERT_VALUES,ierr) 24 end do 25 call MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr) 26 call MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr) 27 28! Ignore any values set into new nonzero locations 29 call MatSetOption(A,MAT_NEW_NONZERO_LOCATIONS,PETSC_FALSE,ierr) 30 31 idxn(1)=0 32 idxm(1)=n-1 33 if ((idxn(1).ge.nl1).and.(idxn(1).le.nl2-1)) then 34 v(1)=2.0 35 call MatSetValues(A,one,idxn,one,idxm, v,INSERT_VALUES,ierr);CHKERRA(ierr) 36 end if 37 call MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr) 38 call MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr) 39 40 if ((idxn(1).ge.nl1).and.(idxn(1).le.nl2-1)) then 41 call MatGetValues(A,one,idxn,one,idxm, v,ierr) 42 write(6,*) PetscRealPart(v) 43 end if 44 45 call MatDestroy(A,ierr) 46 call PetscFinalize(ierr) 47 48 end program newnonzero 49 50!/*TEST 51! 52! test: 53! nsize: 2 54! filter: Error: 55! 56! test: 57! suffix: 2 58! nsize: 2 59! args: -info 60! filter: grep "Skipping" 61! 62!TEST*/ 63