mumps_binding.f90 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14

module LinearAlgebra

  implicit none 

  private

  include 'dmumps_struc.h'

  type, public :: sparse_mat
    private
    type(dmumps_struc) :: mumps_par    
  end type sparse_mat

Rémy Mozul's avatar
Rémy Mozul committed
15 16 17
  public declare, build, &
         solve,   erase, &
         init, finalize
18 19 20

  contains

Rémy Mozul's avatar
Rémy Mozul committed
21 22 23 24 25 26 27
  subroutine init()
    implicit none

    print *, 'empty initialization'

  end subroutine

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
  subroutine declare(matrix, nb_dofs, nb_non_zero, i_indices, j_indices, is_sym, info)
    implicit none

    type(sparse_mat) :: matrix

    integer(kind=4)                        :: nb_dofs, nb_non_zero, info
    integer(kind=4), dimension(:), pointer :: i_indices
    integer(kind=4), dimension(:), pointer :: j_indices

    logical                                :: is_sym

    ! initializing a mumps instance
    matrix%mumps_par%job = -1

    matrix%mumps_par%comm = 0

    ! is input symetric ?
    if (is_sym) then
      matrix%mumps_par%sym  = 1
    else
      matrix%mumps_par%sym  = 0
    endif
    ! is parallelism used ?
    matrix%mumps_par%par  = 1

    ! let's do it

    call DMUMPS( matrix%mumps_par )

    ! Analysis
    matrix%mumps_par%job = 1

    ! setting verbosity to minimum
    matrix%mumps_par%ICNTL(1)=0
    matrix%mumps_par%ICNTL(2)=0
    matrix%mumps_par%ICNTL(3)=0
    matrix%mumps_par%ICNTL(4)=0


    ! assembled format input matrix
    matrix%mumps_par%ICNTL(5 ) = 0
    ! triplet coordinates
    matrix%mumps_par%ICNTL(18) = 0
    matrix%mumps_par%N   =  nb_dofs
    matrix%mumps_par%NZ  =  nb_non_zero
    matrix%mumps_par%IRN => i_indices
    matrix%mumps_par%JCN => j_indices

    ! scaling method
    !matrix%mumps_par%ICNTL(8) = 8

    ! let's do it
    call DMUMPS( matrix%mumps_par )

    info = matrix%mumps_par%INFOG(1)

  end subroutine


  subroutine build(matrix, val, info)
    implicit none
    type(sparse_mat) :: matrix
    real(kind=8)   , dimension(:), pointer :: val
    integer(kind=4) :: info

    ! Factorize
    matrix%mumps_par%job = 2

    matrix%mumps_par%A   => val

    ! let's do it
    call DMUMPS( matrix%mumps_par )

    info = matrix%mumps_par%INFOG(1)

  end subroutine

  subroutine solve(matrix, rhs, info)
    implicit none

    type(sparse_mat) :: matrix

    real(kind=8)   , dimension(:), pointer :: rhs
    integer(kind=4) :: info

    ! solve
    matrix%mumps_par%job = 3

    ! rhs
    matrix%mumps_par%RHS => rhs

    ! let's do it
    call DMUMPS( matrix%mumps_par )
    info = -matrix%mumps_par%INFOG(1)

  end subroutine

  subroutine erase(matrix)
    implicit none
    type(sparse_mat) :: matrix

    matrix%mumps_par%job = -2

    ! let's do it
    call DMUMPS( matrix%mumps_par )

  end subroutine

Rémy Mozul's avatar
Rémy Mozul committed
136 137 138 139 140 141 142
  subroutine finalize()
    implicit none

    print *, 'empty finalization'

  end subroutine

143
end module