Actual source code: ex209f.F90
petsc-3.12.2 2019-11-22
1: !
2: !
3: !
4: program main
5: #include <petsc/finclude/petscmat.h>
6: use petscmat
7: implicit none
9: Mat A
10: PetscErrorCode ierr
11: PetscScalar, pointer :: km(:,:)
12: PetscInt three,one
13: PetscInt idxm(1),i,j
15: call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
16: if (ierr .ne. 0) then
17: print*,'Unable to initialize PETSc'
18: stop
19: endif
21: call MatCreate(PETSC_COMM_WORLD,A,ierr);CHKERRA(ierr)
22: three = 3
23: call MatSetSizes(A,three,three,three,three,ierr);CHKERRA(ierr)
24: call MatSetBlockSize(A,three,ierr);CHKERRA(ierr)
25: call MatSetType(A, MATSEQBAIJ,ierr);CHKERRA(ierr)
26: call MatSetUp(A,ierr);CHKERRA(ierr)
28: one = 1
29: idxm(1) = 0
30: allocate (km(three,three))
31: do i=1,3
32: do j=1,3
33: km(i,j) = i + j
34: enddo
35: enddo
37: call MatSetValuesBlocked(A, one, idxm, one, idxm, km, ADD_VALUES, ierr);CHKERRA(ierr)
38: call MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr);CHKERRA(ierr)
39: call MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr);CHKERRA(ierr)
40: call MatView(A,PETSC_VIEWER_STDOUT_WORLD,ierr);CHKERRA(ierr)
42: call MatDestroy(A,ierr);CHKERRA(ierr)
44: deallocate(km)
45: call PetscFinalize(ierr)
46: end
48: !/*TEST
49: !
50: ! test:
51: ! requires: double !complex
52: !
53: !TEST*/