Actual source code: ex105f.F
petsc-3.12.4 2020-02-04
Report Typos and Errors

      1: !
      2: !   This program tests MatGetDiagonal()
      3: !
      4:       program main
      5:  #include <petsc/finclude/petscmat.h>
      6:       use petscmat
      7:       implicit none

      9:       PetscErrorCode ierr
     10:       PetscInt i,one,twelve,j
     11:       Mat     m
     12:       PetscScalar value

     14:       call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
     15:       if (ierr .ne. 0) then
     16:         print*,'Unable to initialize PETSc'
     17:         stop
     18:       endif

     20:       twelve = 12
     21:       call MatCreate(PETSC_COMM_WORLD,m,ierr)
     22:       call MatSetSizes(m,PETSC_DECIDE,PETSC_DECIDE,twelve,twelve,ierr)
     23:       call MatSetFromOptions(m,ierr)
     24:       call MatSetUp(m,ierr)

     26:       value = 3.0
     27:       i     = 4
     28:       one   = 1
     29:       call MatSetValuesMPIAIJ(m,one,i,one,i,value,ADD_VALUES,ierr)
     30:       i = 5
     31:       j = 7
     32:       call MatSetValuesMPIAIJ(m,one,i,one,j,value,ADD_VALUES,ierr)
     33:       i = 10
     34:       j = 9
     35:       call MatSetValuesMPIAIJ(m,one,i,one,j,value,ADD_VALUES,ierr)
     36:       call MatAssemblyBegin(m,MAT_FINAL_ASSEMBLY,ierr)
     37:       call MatAssemblyEnd(m,MAT_FINAL_ASSEMBLY,ierr)

     39:       call MatDestroy(m,ierr)
     40:       call PetscFinalize(ierr)
     41:       end

     43: !/*TEST
     44: !
     45: !   test:
     46: !      nsize: 2
     47: !
     48: !TEST*/