mkl -- inverse square matrix -- transpose

mkl -- inverse square matrix -- transpose

hi every one,I would like to find the inverse and after that of a square matrix. The matrix it is n x n with n very small, max n = 20-30.
I would like to use the mkl libraries in intel fortran 95\\2003.
what libraries could I use ?
How shall I do?
thanks

19 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Diedro,Please see the MKL Manual Documentation - Lapack\Computations routines\Routines for Matrix Inversion.also see the MKL Linker Adviser - to select what MKL'slibraries are recommended for linking ...--Gennady

hi,thank you very much but it seems very comlicate.I found the functio that are:

    call GETRF(CoeffMat,ipiv)
    call GETRI(CoeffMat,ipiv) 

and I try to compile as:

ifort -L$MKLPATH -lmkl_lapack -mkl -lpthread *.f90

but I get the following error:

quadraturepoints.f90(86): error #6285: There is no matching specific subroutine for this generic subroutine call.   [GETRF]
    call GETRF(CoeffMat,ipiv)
---------^
quadraturepoints.f90(87): error #6285: There is no matching specific subroutine for this generic subroutine call.   [GETRI]

could you please what it is wrong?thank you very much

The combination of array data types and rank declarations must match one of the original BLAS functions. The source code for the lapack use modules is provided in your installation, in case that will help you see what are the supported specific subroutines. You could post a complete small example if you want further advice.

hi,thank you again very much.the function defined in

/opt/intel/composerxe-2011.0.084/mkl/interfaces/lapack95/source/

that I want to use to "computes an LU factorization of a nxm genelral matrix A" (first step to invert a matrix) is:

DGETRF

and in dgetrf.f90 the subroutine is:

PURE SUBROUTINE DGETRF_F95(A,IPIV,INFO)

USE F77_LAPACK, ONLY: F77_GETRF, F77_XERBLA
    ! <<< ENTRY point >>>
    ENTRY DGETRF_MKL95(A,IPIV,INFO)
    ! <<< Implicit statement >>>
    IMPLICIT NONE

...
...
...
END SUBROUTINE DGETRF_F95

As you can see it need only three arguments:1) the matrix to invert A(nxn)2) an array dim(n)3) a flagI compile as:

-L$MKLPATH -lmkl_lapack95 -mkl  *.f90 

It runs but I have the following error:

SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source             
libmkl_intel_lp64  00007FBDAD0B37D3  Unknown               Unknown  Unknown

and here my code:

SUBROUTINE quadraturepoints
USE precisionpc
USE basic_funtions_modal_2D
USE comuni
IMPLICIT NONE

....
....
REAL    (DBL),  DIMENSION(nGP1D,nGP1D) :: CoeffMat
REAL    (DBL),  DIMENSION(nGP1D)       :: IPIV

...
...
CALL DGETRF(CoeffMat,ipiv,info)

...
...
...

If I try to callDGETRF_F95 I have an errotI don't know if the problem is in the link between my code and lapack95 or in the input in the subroutineDGETRF_F95thank you very much you are my lifesaver

You must first resolve the compile time problem. The message you quoted before refers to the list of specific versions of getrf, dgetri, which you will see in lapack/interfaces.f90. Fortran looks at the list of alternatives there and gives you the error when none of the alternate specific subroutines match your data types.
IPIV is not a flag; it's an array of default integers to record interchanges. If you don't get that right, that would give rise to the error. If you supply it as an array of double precision, as you appear to have done, that also will give rise to the rejection. Likewise, INFO, which you may call a flag, must be typed integer (rank 0).
The integer types would be default integer, unless you choose the ilp libraries, in which case they would be integer(kind=8).

Hi really really thank you,A is amatrix andIPIV an array:

REAL    (DBL),  DIMENSION(nGP1D)       :: IPIV

info is an integer, not standard I suppose, what do you mean forilp libraries.
AboutDGETRI_f95, it seems to be inDGETRI.f90 where it calls some F77 subroutine (ex.F77_GETRF)I suppose using lapack_interfaces.f90.How can I use it? How shall compile with mkl?I will use DGETRIeacuse it os double , is it right?thank again

Hi,I tried also to set all the variables and mlk again:

./mklvars.sh intel64

and I have:

./mklvars.sh: 12: Bad substitution
diego@diedro:/opt/intel/composerxe-2011/mkl/bin$ 

Is this the problem?

I guess you're not using the ilp (64-bit integer) libraries, but you haven't given us that information. You don't need to change anything in the source code for the MKL .mod files; I just referred you to it to point out where the data type mismatch is (evidently, your wrong data type for IPIV, possibly others).

hi,now I can compile, I hope correctely:

ifort *.f90 -L$MKLPATH/lib/em64t  -lmkl_blas95_ilp64 -lmkl_lapack95_ilp64 -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread

But there is a problem:If I use:

SUBROUTINE quadraturepoints
USE precisionpc
USE basic_funtions_modal_2D
USE mkl95_LAPACK

Fortran compile without any problem, it recognize also:

CALL DGETRF_F95 (Inv,IPIV,INFO)

however the program is non able to run to the end. I have check, the subroutine

DGETRF_F95

seems to not work.If I choose also

USE LAPACK95

and I compile as

 ifort *.f90 -L$MKLPATH/lib/em64t  -lmkl_blas95_ilp64 -lmkl_lapack95_ilp64 -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread -llapack95

I have the following errors:

error #6633: The type of the actual argument differs from the type of the dummy argument.   [INV]
   CALL DGETRF_F95 (Inv,IPIV,INFO)
--------------------^
quadraturepoints.f90(91): error #6633: The type of the actual argument differs from the type of the dummy argument.   [IPIV]
   CALL DGETRF_F95 (Inv,IPIV,INFO)
------------------------^
quadraturepoints.f90(91): error #6633: The type of the actual argument differs from the type of the dummy argument.   [INFO]
   CALL DGETRF_F95 (Inv,IPIV,INFO)
-----------------------------^
compilation aborted for quadraturepoints.f90 (code 1)
diego@diedro:~/Desktop/dottorato/src/fortran_src/cgk2D_gauss_n$ 

why?

hi,now I try ti summurized what is going on.I am using composerxe2011.0.084First of all I compile my program as:

 ifort *.f90 -L$MKLPATH/lib/em64t  -lmkl_blas95_ilp64 -lmkl_lapack95_ilp64 -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread

After that I wrote a program to test the inversion of a matrix using mkl libraries:

program inversion
use f95_precision
use lapack95
implicit none
    
    integer(sp)   :: I, N,info
    integer(sp)  ,  dimension(:)   , allocatable:: IPIV
    real   (sp)  ,  dimension(:,:) , allocatable:: A, AA
    
    N = 3
    
    allocate( IPIV(N) )
    allocate( A(N,N), AA(N,N) )
    
    AA(1,1) = 1.0d0; AA(1,2) = 3.0d0; AA(1,3) = 1.0d0
    AA(2,1) = 1.0d0; AA(2,2) = 1.0d0; AA(2,3) = 2.0d0
    AA(3,1) = 2.0d0; AA(3,2) = 3.0d0; AA(3,3) = 4.0d0

    A = AA

    write(*,*) 'The Matrix A is:'
    do I = 1,N
        write(*,*) AA(I,:)
    end do

    write(*,*) 'The First Step is to Factorise A'
    call GETRF( A, IPIV)


    write(*,*) 'The Inverted Matrix is:'
    do I = 1,N
        write(*,*) A(I,:)
    end do
!     
    write(*,*) 'IPIV',IPIV
    write(*,*) 'The Second Step is to Invert A'
    call GETRI(A, IPIV )
! 
    write(*,*) 'The Inverted Matrix is:'
    do I = 1,N
        write(*,*) A(I,:)
    end do

end program inversion

and this are the results:

 The Matrix A is:
   1.000000       3.000000       1.000000    
   1.000000       1.000000       2.000000    
   2.000000       3.000000       4.000000    
 The First Step is to Factorise A
 The Inverted Matrix is:
   2.000000       3.000000       4.000000    
  0.5000000       1.500000      -1.000000    
  0.5000000     -0.3333333     -0.3333333    
 info           0
 IPIV           3           3           3
 The Second Step is to Invert A
forrtl: severe (174): SIGSEGV, segmentation fault occurred

why Do I have a segmentation fault with the GETRI call?I am not able to understand,GETRF seems to work correctely but notGETRI, and the belong to the same family functions

hi,now I try ti summurized what is going on.First of all I compile my program as:

 ifort *.f90 -L$MKLPATH/lib/em64t  -lmkl_blas95_ilp64 -lmkl_lapack95_ilp64 -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread

After that I wrote a program to test the inversion of a matrix using mkl libraries:

program inversion
use f95_precision
use lapack95
implicit none
    
    integer(sp)   :: I, N,info
    integer(sp)  ,  dimension(:)   , allocatable:: IPIV
    real   (sp)  ,  dimension(:,:) , allocatable:: A, AA
    
    N = 3
    
    allocate( IPIV(N) )
    allocate( A(N,N), AA(N,N) )
    
    AA(1,1) = 1.0d0; AA(1,2) = 3.0d0; AA(1,3) = 1.0d0
    AA(2,1) = 1.0d0; AA(2,2) = 1.0d0; AA(2,3) = 2.0d0
    AA(3,1) = 2.0d0; AA(3,2) = 3.0d0; AA(3,3) = 4.0d0

    A = AA

    write(*,*) 'The Matrix A is:'
    do I = 1,N
        write(*,*) AA(I,:)
    end do

    write(*,*) 'The First Step is to Factorise A'
    call GETRF( A, IPIV)


    write(*,*) 'The Inverted Matrix is:'
    do I = 1,N
        write(*,*) A(I,:)
    end do
!     
    write(*,*) 'IPIV',IPIV
    write(*,*) 'The Second Step is to Invert A'
    call GETRI(A, IPIV )
! 
    write(*,*) 'The Inverted Matrix is:'
    do I = 1,N
        write(*,*) A(I,:)
    end do

end program inversion

and this are the results:

 The Matrix A is:
   1.000000       3.000000       1.000000    
   1.000000       1.000000       2.000000    
   2.000000       3.000000       4.000000    
 The First Step is to Factorise A
 The Inverted Matrix is:
   2.000000       3.000000       4.000000    
  0.5000000       1.500000      -1.000000    
  0.5000000     -0.3333333     -0.3333333    
 info           0
 IPIV           3           3           3
 The Second Step is to Invert A
forrtl: severe (174): SIGSEGV, segmentation fault occurred

why Do I have a segmentation fault with the GETRI call?I am not able to understand,GETRF seems to work correctely but notGETRI, and the belong to the same family functions

Hi,

You need to link with LP64 MKL libraries if yourprogram uses default INTEGERs.
Otherwise please try adding -i8 option for ifort to use INTEGER*8to correspond to ILP64 MKL libraries.
Intel MKL Link Line Advisorwill help you too.

Thanks,
-- Victor

hi,it seems that does not work.I'm using ubuntu 11.04 and this is my bash.bashrc (now I have include also the ilp64 to compile also the integer in 64 bit):

PATH="/opt/intel/compilerpro-12.0.0.084/bin/intel64$PATH"
source /opt/intel/compilerpro-12.0.0.084/bin/ifortvars.sh intel64
export LD_LIBRARY_PATH=/opt/intel/compilerpro-12.0.0.084/debugger/lib/intel64:$LD_LIBRARY_PATH
export PATH
###################################################################################################
source /opt/intel/composerxe-2011.0.084/mkl/bin/mklvars.sh intel64 mod ilp64
export PATH

I have use the Intel MKL Link Line Advisorand here is the result:

-L$(MKLROOT)/lib/em64t  -lmkl_blas95_ilp64 -lmkl_lapack95_ilp64 -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread

so I compile as:

~/Desktop/prova/prova3$ ifort *.f90 -L$MKLPATH/lib/em64t  -lmkl_blas95_ilp64 -lmkl_lapack95_ilp64 -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread

after that I run the same program, all in single precision, so I use the:

call GETRF( A, IPIV,info)

and

call GETRI( A, IPIV,info)

but I get the same problem:

 The Matrix A is:
   1.000000       3.000000       1.000000    
   1.000000       1.000000       2.000000    
   2.000000       3.000000       4.000000    
 The First Step is to Factorise A
 The Inverted Matrix is:
   2.000000       3.000000       4.000000    
  0.5000000       1.500000      -1.000000    
  0.5000000     -0.3333333     -0.3333333    
 info           0
 IPIV           3           3           3
 The Second Step is to Invert A
forrtl: severe (174): SIGSEGV, segmentation fault occured

GETRF works but not GETRIHave I done something wrong?do I have to update my compiler? (compilerpro-12.0.0.084)

hi,now it seems to workthe code:

program inversion
use f95_precision
use lapack95
implicit none
!ifort -i8 *.f90 -L$MKLPATH/lib/em64t  -lmkl_blas95_ilp64 -lmkl_lapack95_ilp64 -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core 
    integer(dp)   :: I, N,info
    integer(dp)  ,  dimension(:)   , allocatable:: IPIV
    real   (dp)  ,  dimension(:,:) , allocatable:: A, AA
    
    N = 3
    
    allocate( IPIV(N) )
    allocate( A(N,N), AA(N,N) )
    
    AA(1,1) = 1.0d0; AA(1,2) = 3.0d0; AA(1,3) = 1.0d0
    AA(2,1) = 1.0d0; AA(2,2) = 1.0d0; AA(2,3) = 2.0d0
    AA(3,1) = 2.0d0; AA(3,2) = 3.0d0; AA(3,3) = 4.0d0

    A = AA

    write(*,*) 'The Matrix A is:'
    do I = 1,N
        write(*,*) AA(I,:)
    end do

    write(*,*) 'The First Step is to Factorise A'
    call GETRF( A, IPIV,info)


    write(*,*) 'The Inverted Matrix is:'
    do I = 1,N
        write(*,*) A(I,:)
    end do
!    
    write(*,*) 'info',info 
    write(*,*) 'IPIV',IPIV
    write(*,*) 'The Second Step is to Invert A'
    call GETRI(A, IPIV,info)
! 
    write(*,*) 'The Inverted Matrix is:'
    do I = 1,N
        write(*,*) A(I,:)
    end do
end program inversion

and I compile as:

 ifort -i8 *.f90 -L$MKLPATH/lib/em64t  -lmkl_blas95_ilp64 -lmkl_lapack95_ilp64 -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread

now I have a new question:If I want to compile inQuadruple precision?what are the difference between GETRi e DGETRI, because when I compile with DGETRI?

There's no MKL support for quad precision, in part because quad precision (e.g. ifort REAL(KIND=16)) doesn't allow for the optimizations typical of MKL, including vectorization. You could build the netlib functions using ifort quad precision, if you chose.
The lapack95 getri is simply a way of letting the compiler choose among the f77 ?getri functions, supplying the additional arguments automatically.

hi,ok, I get it.However, DGETRI does not work, I have a segmetation fault error.

hi,do you know why?This is just to understand better.Everything is working now:

CALL GETRF(Inv,IPIV,info)
CALL GETRI(Inv,IPIV,info)

Coeff1D = TRANSPOSE(Inv)
        DO i=1,nCP1D
          DO j=1,nCP1D
              Coeff1D(i,j) = REAL(Coeff1D(i,j),R16P)
          ENDDO
        ENDDO

in this way I get also the quadruple precision

Leave a Comment

Please sign in to add a comment. Not a member? Join today