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

Steps to link LAPACK in Fortran 90 using Visual Studio 2008

Juan_Diego_E_
Beginner
1,172 Views

Good afternoon,

I would deeply appreciate if anybody can help me with the clear steps to link and be able to call a subroutine from the LAPACK library.

I am working with Fortran 90 via Microsoft Visual Studio 2008. IA32 architecture. I already checked that I do have the MKL folder (with files, and some .f90 lapack files, etc). However I have found a lot of information in the internet, but none of them has been successful for me. I guess there are just pieces of information, but not all the steps: from adding sources codes to including USE statements in my source code. Also I am very confused on whether do I have to use lapack only or lapack95 or mkl_lapack95, etc.. Can anybody please clarify this to me?

Thank you very much.

Regards,

Juan Diego

0 Kudos
7 Replies
mecej4
Honored Contributor III
1,172 Views

It comes down to making choices to suit your situation, and accepting the responsibilities and consequences of the choices.

Most of BLAS and Lapack was created in the era when F77 was the most recent version of Fortran. A major limitation of that Fortran was that dynamic allocation of memory was not available. If a library routine needed scratch space, you had to hand over that scratch space through additional subroutine arguments (most often called WORK and IWORK). Calculating the size of the work space was sometimes quite intricate. 

If you have inherited large chunks of code that make F77-style calls, you can continue to use such calls, as they are supported in MKL. However, if you are writing new code, you will find the new F90/F95 interfaces more convenient and less error-prone. These interfaces use fewer arguments and the subroutines have generic names and often take optional arguments. As a consequence, you must provide explicit interfaces, preferably with a USE statement, or with interface blocks. 

You can mix F77-style calls with F95-style calls in your code if you are careful.

The MKL documentation is consistent in the way it displays the subroutine prototypes. For example, the very first entry, "?ASUM", shows the F77 variants sasum, scasum, dasum and dzasum, and the F95 generic name asum. Each manual page lists the arguments and their properties, and displays the module that must be USEd if the F95 entry is called.

If you have any calls to the F95 entries, you must tell the linker to search the BLAS95 and Lapack95 libraries, as appropriate. In all cases, you must tell to linker to search the F77 libraries, because the -95 versions do not actually contain any algorithmic code but translate F95 style calls to the corresponding F77 style calls.

Use the MKL Link Line Advisor for your specific version of MKL to obtain the list of libraries to call. For simple projects, you may find that it is enough to use the /Qmkl (-mkl on Linux and OSX) compiler option.

There are additional complications when you compile for 64-bit targets, since then integer variables may be 4-bytes or 8-bytes long and the proper version of the MKL libraries must be chosen. This too is handled by the MKL Link Line Advisor.

If all this sounds too complicated, (i) start out with simple F95 style calls, (ii) use the -mkl compiler option and, (iii) when/if you run into problems, bring them to this forum.

0 Kudos
Juan_Diego_E_
Beginner
1,172 Views

Thank you very much.

This is what I have done so far in order to use the subroutine DGBSV_F95 in my Fortran 90 code:

1. Followed the steps in this link: https://software.intel.com/en-us/articles/creating-configuring-and-running-intel-visual-fortran-projects-in-microsoft-visual-studio?language=ru

I guess all these steps were to link libraries and paths, I did it exactly as it is shown, even using the " " for each directory.

2. Inluded in the Source File Folder of my Fortran 90 project the source code: lapack.f90 (whose content says: "F95 interface for LAPACK routines").

3. Included the following statement right after the "program statement": use mkl95_lapack

4. I call inside the main program: call DGBSV_F95(BTM, RHS, kl, IPIV, INFO)

After all this should it be ok? When I print out the INFO argument, I get 0, which means there was a succesful exit. I am printing the results as RHS (which is how F77 interface those, I guess is the same for F95 interface, because there is no other argument that I see is for this purpose). However, I do not get the results (I know the results because I am solving exactly the same system of equations with Matlab backslash command). I am getting the original RHS (right hand side vector).

Thanks for the advice.

Juan Diego.

 

0 Kudos
mecej4
Honored Contributor III
1,172 Views

Do not use routines with _F95 in their name, unless you have a valid reason to do so. Those are meant for internal use. Call the generic name GBSV instead, as the MKL manual page tells you.

There is an example of calling GBSV, file gbsv.f90, in the MKL examples/lapack95/sources directory (if you have not already done so, you may need to unzip examples_f95.zip to see it).

The description that you gave in #3 is not enough to troubleshoot. In particular, the declarations of the arguments and their initialization, as appropriate, are unknown. Please post the actual, complete, code.

0 Kudos
Juan_Diego_E_
Beginner
1,172 Views

Thank you. Ok I found the example, and I am running it, but now I am getting this erro when compiling the example code:

Error    1     error LNK2019: unresolved external symbol _SGBSV_MKL95 referenced in function _MAIN__    GBSVEX.obj    

Error    2     fatal error LNK1120: 1 unresolved externals    Debug\GBSVEX.exe    


I guess if I can solve this errors and make the example to work, I can manage to apply this into my code.

Can you please help me with these two errors?

Thank you again.

Juan Diego.

 

0 Kudos
mecej4
Honored Contributor III
1,172 Views

You have to specify mkl_lapack95.lib and  mkl_blas95.lib as additional libraries to search. The page that you referred to in #3, step-1 does not cover the F95 interfaces.

Step-2 was unnecessary, but mostly harmless. 

0 Kudos
Juan_Diego_E_
Beginner
1,172 Views

Thanks a gain. I will try that way, and also I will not add the source file into my source file folder.

Regards,

Juan Diego

0 Kudos
Nägele__Johannes
1,172 Views

Hello everyone, I'm a Fortran as well as MKL newby, so please apologize my rather crude understanding of this architecture.

I got stuck at the exactly the same position when the dependencies of the F95 interfaces couldn't be found. And obviously, as explained in #6, the problem simply is that the library paths aren't specified correctly. However I don't really get how to solve that. I tried to add mkl_lapack95.lib and mkl_blas95.lib in project properties/Fortran/Linker/Input/Additional Dependencies and to add the path to the respective folder under project properties/Fortran/Linker/General/Additional Library Directorys but that didn't work. Then I tried the mklvars.bat to set up the environment variables + rebooting several times with several properties (ia32/intel64...). Again, that didn't help.
My system: Windows 10 x64

I would really appreciate further advice.

0 Kudos
Reply