solving systems of linear equations

solving systems of linear equations

I want to use some subroutines in LAPACK in Intel Math Kernel Library for solving systems of linear equations. Such as subroutines getrf, getrs. How should I do? I am using FORTRAN 95 under Microsoft Visual Studio.

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

Did you consult lapack95 documentation and the MKL_userguide in your installation?

Yes. I have read

Fortran95 Interface Conventions

Fortran95 interface to LAPACK is implemented through wrappers that call respective FORTRAN77 routines. This interface uses such features of Fortran95 as assumed-shape arrays and optional arguments to provide simplified calls to LAPACK routines with fewer arguments.


For LAPACK, Intel MKL offers two types of Fortran95 interfaces:

  • using only through include statement. Such interfaces allow you to make use of the original LAPACK routines with all their arguments
  • using lapack.f90 that includes improved interfaces. This file is used to generate the module files lapack95.mod and f95_precision.mod. The module files mkl95_lapack.mod and mkl95_precision.mod are also generated. See also section Fortran95 interfaces and wrappers to LAPACK and BLAS of Intel MKL User's Guide for details. The module files are used to process the FORTRAN use clauses referencing the LAPACK interface: use lapack95 (or an equivalent use mkl95_lapack) and use f95_precision (or an equivalent use mkl95_precision).


Fortran 95:

call getrs( a, ipiv, b [, trans] [,info] )


This routine is declared in for FORTRAN 77 interface, in lapack.f90 for Fortran 95 interface, and in mkl_lapack.h for C interface.

Before calling this routine, you must call ?getrf to compute the LU factorization of A.

Specific details for the routine getrs interface are as follows:


Holds the matrix A of size (n, n).


Holds the matrix B of size (n, nrhs).


Holds the vector of length n.


Must be 'N', 'C', or 'T'. The default value is 'N'.

But it is still not clear to me what to do.

Thank you in advance for your help.

There are two parts to understanding "what to do". The first is the linear algebra underlying the calculation. A permutation of a given matrix A can be factorized into the product of a lower triangular matrix L and an upper triangular matrix U. After the factorization is completed, the factors L and U and the permutation matrix (stored as a "pivot vector") are used as many times as needed to do forward elimination and backward substitution to obtain the solution to A.x = b with different vectors b.

The second part is how to call the routines provided in Lapack-95 and MKL to perform the calculations just described. Here is an example.

program main

USE lapack95

implicit none

real a(3,3),b(3)

integer piv(3)

data a/2.5,-1.0,-1.0, &

      -1.0, 2.5,-1.0, &

      -1.0,-1.0, 2.5/

data b/1.0, 2.0, 3.0/


call getrf(a,piv)


call getrs(a,piv,b)


end program main

Compile and run:

x:> ifort /Qmkl xgetrs.f90 mkl_lapack95.lib

x:> xgetrs
   3.714287       4.000001       4.285715

I am using Microsoft Visual Studio. In the directories of my computer, I found lapack95.mod and mkl_lapack95.lib. How should I configure the Project Property Pages?

I did

Fortran > General > Additional Include Directories: set as the directory with lapack95.mod
Fortran > Libraries > Use Intel Math Kernel Library: set as Sequential (/Qmkl:sequential)
Linker > General > Additional Library Directories: set as the directory with mkl_lapack95.lib

But I got followingerror messages when build:

Error1 error LNK2019: unresolved external symbol _SGETRF_F95 referenced in function _MAIN__mkltest.obj
Error2 error LNK2019: unresolved external symbol _SGETRS1_F95 referenced in function _MAIN__mkltest.obj
Error3 fatal error LNK1120: 2 unresolved externalsDebug\mkltest.exe

May I ask your help to solve this problem.

You are almost there:

Linker > General > Additional Library Directories: set as the directory with mkl_lapack95.lib

That only specifies the directory to search. You must also specify mkl_lapack95.lib as an additional library to use when linking.

Linker > Command Line > Additional Options: mkl_lapack95.lib

I would suggest instead of Command Line, adding mkl_lapack95.lib to Linker > Input > Additional Dependencies.

Retired 12/31/2016

Hello Steve,
I did what you told me, it still has trouble with following error messages

Error1 error LNK2019: unresolved external symbol _XERBLA referenced in function _SGETRF_F95mkl_lapack95.lib(sgetrf.obj)
Error2 error LNK2001: unresolved external symbol _XERBLAmkl_lapack95.lib(sgetrs1.obj)
Error3 fatal error LNK1120: 1 unresolved externalsDebug\mkltest.exe

I need your further help.


you could also ad both the *.mod and the *.lib file directly into the project (solution explorer -> project tree -> Source Files -> right click and Add existing item). This is not elegant but should work.

If there are still link errors, your LAPACK routine requires maybe not only the mkl_lapack95.lib.

Kind regards,

It doesn't work. Compile is fine, but there are still link errors. It is hard to test every *.lib file in the folder one by one


maybe you should then stay at Steve's and mecej4's suggestions and set the properties right. I guess the routines in the mkl_lapack95.lib call other routines in e.g. mkl_blas95.lib and so on. Maybe it is enough to ad these libs also into the linker property settings (if you know, in which lib are which subroutines/ functions...).

An example for the right property settings may be found in the some sample projects for visual studio in your installation folder (C:\Program Files (x86)\Intel\Composer XE 2011 SP1\mkl\tools\builder\MSVS_Projects\VS2010\.). These are C++ versions...

Kind regards,

The entry _XERBLA is contained in mkl_rt.lib (and other similar libraries). It gets pulled in if the project settings contain a request to use MKL.

This thread illustrates how a trivial example of compiling a program using a simple command becomes difficult to provide help for when the user uses a comprehensive IDE with numerous settings and we have not been told which settings have been used.

After adding all files of *.lib into Property Pages > Linker > Input > Additional Dependencies, I was able to make the executable.But it has then another problem when run.

source file:
1 program main
2 USE lapack95
3 implicit none
4 real a(3,3),b(3)
5integer piv(3)
6 data a/2.5,-1.0,-1.0, &
7 -1.0, 2.5,-1.0, &
8 -1.0,-1.0, 2.5/
9 data b/1.0, 2.0, 3.0/
10call getrf(a,piv)
11write(*,*) 'a='
12 write(*,*) a
13 write(*,*) 'b='
14 write(*,*) b
15write(*,*) 'piv='
16 write(*,*) piv
17 pause 'initial'
18 call getrs(a,piv,b)
19 write(*,*) b
20 end program main

execution result:

2.500000 -0.4000000 -0.4000000 -1.000000 2.100000
-0.6666667 -1.000000 -1.400000 1.166667
1.000000 2.000000 3.000000
1 2 3

forrtl: severe (157): Program Exception - access violation
Image PC Routine Line Source
mkltest.exe 004AB546 Unknown Unknown Unknown
mkltest.exe 00401452 _MAIN__ 18 mkltest.f90
mkltest.exe 004AD903 Unknown Unknown Unknown
mkltest.exe 0044D3D7 Unknown Unknown Unknown
mkltest.exe 0044D2AF Unknown Unknown Unknown
kernel32.dll 7C817077 Unknown Unknown Unknown

From above result (until line 17 pause 'initial'), it seems that call getrf works,the problem appears when call getrs. I could not fix the problem. Many thanks if you can help me.

What do you do when the program pauses? Why do you have the PAUSE statement? What happens if you relocate the PAUSE statement to just before the END statement?

Yes, I put PAUSE statement in the code, see line 17. With this method I know that the code runs into the problem by calling getrs.

Best Reply

Hi all,

I put the sample code from in a VS project to test it. I will also use MKL routines for a current project and therefore have to be sure that it works fine.

I modified the original code marginal and running in debug mode everything is fine, with and without the PAUSE and with single and double precision.

here my source code:

program MKL_test


USE lapack95


implicit none


real(kind(1.d0))  ::  a(3,3),b(3)

!real              ::  a(3,3),b(3)

integer           ::  piv(3)



a(1:3,1) = [ 2.5,-1.0,-1.0]

a(1:3,2) = [-1.0, 2.5,-1.0]

a(1:3,3) = [-1.0,-1.0, 2.5]
b        = [ 1.0, 2.0, 3.0]
call getrf(a,piv)
write(*,*) 'a='

write(*,*) a

write(*,*) 'b='

write(*,*) b

write(*,*) 'piv='

write(*,*) piv
!pause 'initial'  
call getrs(a,piv,b)
write(*,*) b 
end program MKL_test

And that is what I get as result:

2.50000000000000 -0.400000000000000 -0.400000000000000
-1.00000000000000 2.10000000000000 -0.666666666666667
-1.00000000000000 -1.40000000000000 1.16666666666667
1.00000000000000 2.00000000000000 3.00000000000000
1 2 3
3.71428571428571 4.00000000000000 4.28571428571428

However, in my installation everything seems to work fine.

Kind regards,


linker settings:
/OUT:"Debug\MKL_test.exe" /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:\Program Files (x86)\Intel\Composer XE 2011 SP1\mkl\lib\ia32" /MANIFEST /MANIFESTFILE:"D:\Arbeitsverzeichnis_Jo\Fortran\MKL_test\Debug\MKL_test.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"D:\Arbeitsverzeichnis_Jo\Fortran\MKL_test\Debug\MKL_test.pdb" /SUBSYSTEM:CONSOLE /IMPLIB:"D:\Arbeitsverzeichnis_Jo\Fortran\MKL_test\Debug\MKL_test.lib" mkl_lapack95.lib

fortran settings:
/nologo /debug:full /Od /I"C:\Program Files (x86)\Intel\Composer XE 2011 SP1\mkl\include\ia32" /warn:interfaces /module:"Debug\" /object:"Debug\" /Fd"Debug\vc100.pdb" /traceback /check:bounds /libs:static /threads /dbglibs /Qmkl:sequential /c

all other settings are default

Hi, Johannes,
It looks like that you are also in Germany. Thank you very much for your help.
I found finally that I need both mkl_lapack95.lib and mkl_intel_c.lib and then I could get the correct result. If I input more *.lib files, it could run into the problem that I mentioned in earlier messages.

Best regards

When you specify "*.lib", in essence you declare that all you care about is that routine names be found, regardless of whether the library is compatible w.r.t. linkage with your compiled objects. If you say "use any ole library", you should not be surprised when you get "any ole results".


I am new here. may I ask how I can install and use LAPACK or IS there any internal package in intel fortran parallel so I can use to solve dense linear system od equations?


Leave a Comment

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