Actual source code: ex126f.F

petsc-3.5.4 2015-05-23
Report Typos and Errors
  1: !
  2: ! This program is modified from a user's contribution.
  3: ! It illustrates how to call MUMPS's LU solver
  4: !

  6:       program main
  7:       implicit none

  9: #include <finclude/petscsys.h>
 10: #include <finclude/petscvec.h>
 11: #include <finclude/petscmat.h>

 13:       Vec            x,b,u
 14:       Mat            A, fact
 15:       PetscInt       i,j,II,JJ,m
 16:       PetscInt       Istart, Iend
 17:       PetscInt       ione, ifive
 18:       PetscBool      wmumps
 19:       PetscBool      flg
 20:       PetscScalar    one, v
 21:       IS             perm,iperm
 22:       PetscErrorCode ierr
 23:       PetscReal      info(MAT_FACTORINFO_SIZE)

 25:       call PetscInitialize(PETSC_NULL_CHARACTER, ierr)
 26:       m    = 10
 27:       one  = 1.0
 28:       ione = 1
 29:       ifive = 5

 31:       wmumps = PETSC_FALSE

 33:       call PetscOptionsGetInt(PETSC_NULL_CHARACTER,'-m',m,flg, ierr)
 34:       call PetscOptionsGetBool(PETSC_NULL_CHARACTER,'-use_mumps',                       &
 35:      &                         wmumps,flg,ierr)

 37:       call MatCreate(PETSC_COMM_WORLD, A, ierr)
 38:       call MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, m*m, m*m, ierr)
 39:       call MatSetType(A, MATAIJ, ierr)
 40:       call MatSetFromOptions(A, ierr)
 41:       call MatSeqAIJSetPreallocation(A,ifive, PETSC_NULL_INTEGER, ierr)
 42:       call MatMPIAIJSetPreallocation(A,ifive,PETSC_NULL_INTEGER,ifive,  &
 43:      &     PETSC_NULL_INTEGER,ierr)

 45:       call MatGetOwnershipRange(A,Istart,Iend,ierr)

 47:       do 10, II=Istart,Iend - 1
 48:         v = -1.0
 49:         i = II/m
 50:         j = II - i*m
 51:         if (i.gt.0) then
 52:           JJ = II - m
 53:           call MatSetValues(A,ione,II,ione,JJ,v,INSERT_VALUES,ierr)
 54:         endif
 55:         if (i.lt.m-1) then
 56:           JJ = II + m
 57:           call MatSetValues(A,ione,II,ione,JJ,v,INSERT_VALUES,ierr)
 58:         endif
 59:         if (j.gt.0) then
 60:           JJ = II - 1
 61:           call MatSetValues(A,ione,II,ione,JJ,v,INSERT_VALUES,ierr)
 62:         endif
 63:         if (j.lt.m-1) then
 64:           JJ = II + 1
 65:           call MatSetValues(A,ione,II,ione,JJ,v,INSERT_VALUES,ierr)
 66:         endif
 67:         v = 4.0
 68:         call  MatSetValues(A,ione,II,ione,II,v,INSERT_VALUES,ierr)
 69:  10   continue

 71:       call MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY, ierr)
 72:       call MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY, ierr)

 74:       call VecCreate(PETSC_COMM_WORLD, u, ierr)
 75:       call VecSetSizes(u, PETSC_DECIDE, m*m, ierr)
 76:       call VecSetFromOptions(u, ierr)
 77:       call VecDuplicate(u,b,ierr)
 78:       call VecDuplicate(b,x,ierr)
 79:       call VecSet(u, one, ierr)
 80:       call MatMult(A, u, b, ierr)

 82:       call MatFactorInfoInitialize(info,ierr)
 83:       if (wmumps) then
 84:           write(*,*) 'use MUMPS LU...'
 85:           call MatGetFactor(A,MATSOLVERMUMPS,MAT_FACTOR_LU,fact,ierr)
 86:           call MatLUFactorSymbolic(fact, A, PETSC_NULL_OBJECT,                            &
 87:      &                    PETSC_NULL_OBJECT,info, ierr)
 88:       else
 89:          write(*,*) 'use PETSc LU...'
 90:          call MatGetOrdering(A,MATORDERINGNATURAL,perm,iperm,ierr)
 91:          call MatGetFactor(A,MATSOLVERPETSC,MAT_FACTOR_LU,fact,ierr)

 93:          call MatLUFactorSymbolic(fact, A, perm, iperm,                                   &
 94:      &         info, ierr)
 95:          call ISDestroy(perm,ierr)
 96:          call ISDestroy(iperm,ierr)
 97:       endif

 99:       call MatLUFactorNumeric(fact, A, info, ierr)
100:       call MatSolve(fact, b, x,ierr)
101:       call MatDestroy(fact, ierr)

103:       call MatDestroy(A, ierr)
104:       call VecDestroy(u, ierr)
105:       call VecDestroy(x, ierr)
106:       call VecDestroy(b, ierr)

108:       call PetscFinalize(ierr)
109:       end