-1

Ok i want to compare the result using inverse of matrix for dense rectangular matrix non symmetric. Usually using DGETRF and DGETRI Blas for get the matrix inverse. Let say [2000x2000] double precision matrix A, i want to solve to find the matrix - inverse.

And then i got the SuperLU solver. The idea using sparse solver to get inverse matrix, is to solve A*X=I, where I is the identity matrix. If there is a solution, X will be the inverse matrix. So if the A[2000x2000], Ainvers aka X[2000x2000], identity I[2000x2000]

While the input for calling superlu lib in fortran

call c_fortran_dgssv ( iopt, n, ncc, nrhs, acc, icc,ccc, b, ldb, factors, info )
realbabilu
  • 11
  • 3

1 Answers1

0

B in superlu can be (n x n) matrices, A * B = x if A (n x n) input, then inverse A is B (n x n) with x (n x n) as identity matrix, then all B, and X should be (n x n).

  ! a matrix(n,n) bmatrix(n,n) identity matrix(n,n)
  ! find nonzero val in a, get ncc
  ! convert a matrix to ccc matrix first
  allocate (icc(ncc),acc(ncc))
  ....
 
  nrhs = n ! THIS B matrix size
  ldb = n
  allocate (b(n,n))
  b = 0.d0
  !insert identity matrix as B in
  do i = 1, n
    b(i,i) = 1.d0
  end do

  !Factor the matrix in superlu.
  iopt = 1
  call c_fortran_dgssv ( iopt, n, ncc, nrhs, acc, icc,ccc, b, ldb, factors, info )

  !Solve the factored system in superlu.
  iopt = 2
  call c_fortran_dgssv ( iopt, n, ncc, nrhs, acc, icc,ccc, b, ldb, factors, info )

  ! Free memory in superlu.
  iopt = 3
  call c_fortran_dgssv ( iopt, n, ncc, nrhs, acc, icc, ccc, b, ldb, factors, info )
  
  !b out is the inverse
  a = b
  deallocate (b,icc,acc)

Alternatively using B (n) as 1 dimensional matrix for saving memory. as Vladimir pointed out. Do per column of A matrix

do k=1,n
nrhs = 1
ldb = n

do i = 1, n
 if (k.eq.i) b(i) = 1.d0
 if (k.ne.i) b(i) = 0.d0   
end do

!  Factor the matrix.
  iopt = 1
  call c_fortran_dgssv ( iopt, n, ncc, nrhs, acc, icc,ccc, b, ldb, factors, info )
!  Solve the factored system.
  iopt = 2
  call c_fortran_dgssv ( iopt, n, ncc, nrhs, acc, icc,ccc, b, ldb, factors, info )
  do i = 1, n
    a(i,k)= b(i)
  end do
!  Free memory.
  iopt = 3
  call c_fortran_dgssv ( iopt, n, ncc, nrhs, acc, icc, ccc, b, ldb, factors, info )
end do !k

  deallocate (icc,acc)   
realbabilu
  • 11
  • 3