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)