Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
6975 Discussions

Basic problems using the Fortran MKL with VS2008

dave_stevens
Beginner
407 Views

I apologise if this is a very basic question - I presume I'm simply missing something obvious.

I need to use a series of functions from the LAPACK component of the MKL, in an F90 project inVisual Studio 2008.

I have added the F95 inteface file (mkl_lapack.f90) to my project, and included the relevant modules in the subroutine I wish to called the LAPACK routines from (i.e. USE MKL95_PRECISION and USE MKL95_LAPACK ). I can call various functions from this interface module, and so long as I am passing the data correctly, the subroutine will compile.

However, when I attempt to build the project I get an "unresolved external symbol" error for each function I am calling. I presume this is because I'm not linking to the MKL properly? If so, how can I direct the project towards the MKL functionsoutlined in mkl_lapack.f90 ?

Thanks in advance for any help you can provide!

0 Kudos
7 Replies
TimP
Honored Contributor III
407 Views
I believe this subject has been touched on before.
The developers expect you to add the path to the folder where the lapack95 .mod files are located as an INCLUDE path, which you could do in the VS properties for your project. Another solution is to move those .mod files up into the main MKL INCLUDE directory. Either of these methods will support the 'USE lapack95'
I don't know why this problem isn't taken care of during ifort installation. In some earlier versions, you had to build the .mod files yourself, before arranging to get them on path.
0 Kudos
fattyboomsticks
Beginner
407 Views
...also, have you read the "Linking your application..." chapter of the MKL user guide (in particular the 'Linking examples' section)? Naturally the libraries you need to link to depend on your platform. The libraries I use in prder to link to MKL are:

'-lmkl_lapack95_lp64 -lmkl_blas95_lp64 -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread'

in that order, which I think is pretty typical. In VS, the '-l' might not be necessary...
0 Kudos
TimP
Honored Contributor III
407 Views
The link advisor at the top of the forum will give a suggestion appropriate to the platform combination. You're right, unresolved references could easily be produced by missing a library in the dependencies, as well as by missing the include setup.
The original question gave no indication whether the Windows build was for 32- or 64-bit, so it's premature to suggest lp64 libraries. The .mod files, of course, also must match the choice of Windows target, and it's possible the scheme which installer currently uses won't work to select the 32- or 64-bit .mod files, so they are left unconnected.
0 Kudos
dave_stevens
Beginner
407 Views
First of all - thank you both for taking the time to help me with this :) To clear up the platform issue; I'mon IA32(Windows XP 32bit).

I think the problem is that I just don't understand the basics mechanics of how visual studio, or compilers in general, work. As a mathematician I've never been taught any computer science related material, and have picked programming up over the years from books and inspecting other example codes.


I read the "linking examples" section of the mkl user guide,however it just lists a few files, and I don't know what to do with them. I was aiming for the static linking, which recommends thefollowing:

ifort myprog.f mkl_intel_c.lib mkl_intel_thread.lib mkl_core.lib libiomp5md.lib

I tried placing the abovefiles in my project /src folder, and adding these files to my project, but doing so gives me the same error as before. I also tried adding the above to the "additional dependencies" field in [project_properties]->Linker->Input, replacing "myprog.f" with either the project name, or the file from which I am calling the subroutines. Inthis case, when building the program, I get an error message saying that "mkl_intel_c.lib" cannot be opened.

Regarding the "mkl95_lapack.mod" file (or any other *lapack.mod)- the only time this appears is when I compile the mkl95_lapack.f90 file that I have included in my project. It is not present anywhere in theprogram files/intel directory. Also, I am unsure how I would link to it were I to find it...


Apologies once again for what must beextremely basic questions, and thank you foryour patience.If there is standard reading material that I should work through before attempting such things, then I would be happy to hear of it.
0 Kudos
fattyboomsticks
Beginner
407 Views
'Hide' : Perhaps this is unclear, however lapack95/blas95 are merely interfaces to the 'old' lapack routines (which are often very cumbersome to use). If you want to use these interfaces (this is probably a good idea), rather than the old ones, then you also need to link to them.

Let's try and get a simple program to compile and run correctly using only the command-line (I'm not familiar with using VS to manage fortran code). I happen to have just such program:

[fortran]PROGRAM helloworld

USE MKL95_PRECISION, ONLY: WP => DP !specifies LAPACK95's precision type
USE MKL95_BLAS, ONLY: GEMM

IMPLICIT NONE


COMPLEX(WP), DIMENSION(:, :), ALLOCATABLE :: a, b, c, mem

ALLOCATE(a(1:2, 1:2), b(1:2, 1:2), c(1:2, 1:2))

a = 0.0d0
b = 0.0d0
c = 4.0d0

a(1, 1) = 2.0
a(2, 2) = 2.0
b(1, 1) = 3.0
b(2, 2) = 3.0
PRINT *, c
CALL GEMM(a, b, c, beta = DCMPLX(1.0d0, 0.0d0))

PRINT *, c
!CALL pointer_allocation(mem)

!PRINT *, "On exit, 'mem' allocated is:", ALLOCATED(mem)

END PROGRAM helloworld[/fortran]
Here GEMM computes 'c=alpha * a * c + beta * c (incidentally, lapack routines usually still work if you declare your variables as, e.g., REAL(8) rather than as WP' precision).

With regards to which libraries to use, the relevant example given in the MKL User's Guide for your platform is (NB: *latest* MKL version!!)
[bash]ifort helloworld.f -L$MKLPATH -I$MKLINCLUDE -I$MKLINCLUDE/32
-lmkl_lapack95
-lmkl_blas95 -Wl,--start-group $MKLPATH/libmkl_intel.a
$MKLPATH/libmkl_intel_thread.a $MKLPATH/libmkl_core.a -Wl,--end-group
-liomp5 -lpthread
[/bash]
, where I have also linked the mkl_blas95 interface. NB: This is using the parallel MKL libraries!! The order in which these are listed is probably important. Make sure the environment variables are set correctly, for now it might be best to just substitute the correct values directly into the above. In particular, $MKLPATH should be something like /opt/intel/mkl/10.1.2.024/lib/32. As Tim said, you also need to make sure that the blas95/lapack95 interfaces are setup correctly. Rather than recompiling them from scratch, first see if the ones you already have work. On my system, these are contained in the directories /opt/intel/Compiler/11.1/069/mkl/interfaces/blas95/obj and /opt/intel/Compiler/11.1/069/mkl/interfaces/lapack95/obj.

The files contained in each of these directories shoud be:-
mkl95_blas.mod, mkl95_precision.mod, libmkl_blas95.a (or something similar)
mkl95_lapack.mod, libmkl_lapack95.a (or something similar)

If either the 'obj' directory or these files are missing then you need to build them. Ultimately the '.mod' files should be placed in the $MKLINCLUDE directory, however they are not usually there by default. I have found that placing them elsewhere doesn't necessarily work, even if the include path reflects this change. Copy the mod files files across to $MKLINCLUDE (and perhaps to $MKLINCLUDE/32, for good measure). The linraries themselves (*.a files, or whatever the extension is on your system) should be copied over to '/opt/intel/mkl/10.1.2.024/lib/32', for example, if they are not already there.

If, when you compile, you still get the same error message or if the interfaces are missing then you should build them manually. On linux this is easily done using the 'make' program (refer to the mkl documentation for other platforms). If you need to build them from scratch, try and set the install directory to $MKLINCLUDE from the outset, otherwise copy them across as usual.

Ok, I hope this enough to get you started.
0 Kudos
dave_stevens
Beginner
407 Views
Thanksa lot, fattyboomsticks! Lots of information there to helpme...

Iwill try to geta single-fileprogram working, as you suggest, from the command line. After that I will try to migrate to VS2008, and then finallymy full (~60k line) project that I wish to interact with.

Thanks again for taking the time to helpme with this...
0 Kudos
Gennady_F_Intel
Moderator
407 Views
Hello, can you find useful for the following 2 articles from the MKL KB:
How to build MKL application in Intel Visual Fotran (MSVC*2005) ( the article shows step be step how to create MCVS based application with Visual Fortran Compiler).
and
( This video provides instructions on using Intel MKL with Intel Visual Fortran Compiler Professional Edition. A simple DFT code is used to demonstrate the steps to setup Intel MKL with Intel Fortran Compiler Professional Edition.)
--Gennady
0 Kudos
Reply