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

Problem with using mkl module

EGMguy
Novice
2,416 Views

I've installed Intel Fortran, running on MS Visual Studio 2022, and also installed Intel oneMKL.  For a test program (shown below) I made sure, under properties, that Fortran included enabled Intel Math Kernel Library and that Linker included additional Library directory, C:\Program Files (x86)\Intel\oneAPI\mkl\2025.0\lib.  Compilation seems to work.  First error on running the program was "mkl_sequential.2.dll not found."  This was corrected (I guess) using instructions found at https://www.dllme.com/dll/files/mkl_sequential_2, where mkl_sequential.2.dll now (also) sits in C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE.  Now the program runs but gets stuck when attempting to call a module in the mkl.  I'm not versed in the background details of these software packages - can anyone help a novice?  Thanks.

program:

PROGRAM TESTMKL
! Program to test the use of routines in the math library MKL
!
REAL*8 A(3,3)
INTEGER N3,IPIV(3),INFO
!
! Define the matrix for LU factorization
DATA A/1.D0, 1.D0, 1.D0, 3.D0, 3.D0, 4.D0, 3.D0, 4.D0, 3.D0/
!
! Compute its LU factorization using an MKL routine
N3=3
print*,'ok up to here'
CALL DGETRF(N3,N3,A,N3,IPIV,INFO)
PRINT*,A
PRINT*,IPIV
PRINT*,INFO
!
STOP
END

 

The output (with error messages):

ok up to here
forrtl: severe (172): Program Exception - exception code = 0x7e (126)
Image PC Routine Line Source
KERNELBASE.dll 00007FFA7C02AB89 Unknown Unknown Unknown
mkl_sequential.2. 00007FF9B8D2288E Unknown Unknown Unknown
mkl_sequential.2. 00007FF9B8D222B5 Unknown Unknown Unknown
test.exe 00007FF635273813 Unknown Unknown Unknown
test.exe 00007FF6352710AC Unknown Unknown Unknown
test.exe 00007FF63527499E Unknown Unknown Unknown
test.exe 00007FF635274CF4 Unknown Unknown Unknown
KERNEL32.DLL 00007FFA7CE07344 Unknown Unknown Unknown
ntdll.dll 00007FFA7E4826B1 Unknown Unknown Unknown
Press any key to continue . . .

 

0 Kudos
1 Solution
EGMguy
Novice
2,224 Views

Hi, Shiquan_Su

 

I think I may have serendipitously stumbled on the solution.  On the site: https://stackoverflow.com/questions/79173586/how-to-force-intel-fortran-to-include-mkl-code-into-and-exe-mklsequential-2-dll it is suggested to ensure that "in addition to using Math Kernel Library Sequential /Qmkl:sequential,... for Runtime library, you have to use /libs:static", which is done by selecting the project properties in MS VS and then going to Fortran>Libraries.  Then everything works (at least for the test program I had).

 

Thanks for your time.

 

View solution in original post

0 Kudos
10 Replies
Shiquan_Su
Moderator
2,400 Views

Shiquan_Su_0-1736874016222.png

Hi, there:

By visiting the https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-link-line-advisor.html

I can get the above compile/link line command.

In Windows, I launch the Intel OneAPI Command prompt, then I can run the following. Can you repeat this? If so, you may also make sure mkl_intel_ilp64.lib mkl_sequential.lib mkl_core.lib all 3 lib files are in your MS VS lib folder.

 

C:\Program Files (x86)\Intel\oneAPI>ifx /4I8 -I"%MKLROOT%\include" testmkl.f90 mkl_intel_ilp64.lib mkl_sequential.lib mkl_core.lib
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2024.0.2 Build 20231213
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

Microsoft (R) Incremental Linker Version 14.33.31630.0
Copyright (C) Microsoft Corporation. All rights reserved.

-out:testmkl.exe
-subsystem:console
testmkl.obj
mkl_intel_ilp64.lib
mkl_sequential.lib
mkl_core.lib

C:\Program Files (x86)\Intel\oneAPI>testmkl.exe
ok up to here
1.00000000000000 1.00000000000000 1.00000000000000
3.00000000000000 1.00000000000000 0.000000000000000E+000
3.00000000000000 0.000000000000000E+000 1.00000000000000
1 3 3
0

 

 

The testmkl.f90 is:

PROGRAM TESTMKL
! Program to test the use of routines in the math library MKL
!
REAL*8 A(3,3)
INTEGER N3,IPIV(3),INFO
!
! Define the matrix for LU factorization
DATA A/1.D0, 1.D0, 1.D0, 3.D0, 3.D0, 4.D0, 3.D0, 4.D0, 3.D0/
!
! Compute its LU factorization using an MKL routine
N3=3
print*,'ok up to here'
CALL DGETRF(N3,N3,A,N3,IPIV,INFO)
PRINT*,A
PRINT*,IPIV
PRINT*,INFO
!
STOP
END

0 Kudos
EGMguy
Novice
2,386 Views

Hi, Shiquan_Su,

 

Thank you for your answer.  I'm not comfortable with using command-line runs - I prefer using the MS VS.  I now specifically added the lib's in the project (although I thought that ...mkl/2025/lib would cover them all, but maybe not).  I still get the same error.  Can you tell me where specifically I need to include these libraries - i.e., is there a separate/different location for the MS VS lib's?

 

Thanks.

 

 

0 Kudos
Shiquan_Su
Moderator
2,380 Views

Can you remove  mkl_sequential.2.dll to make sure the code links to mkl_sequential.lib? If you still have failures, please share the build commands from the command-line or build output in Visual studio.

0 Kudos
EGMguy
Novice
2,369 Views

Hi, Shiquan_Su

 

I removed mkl_sequential.2.dll and the build is fine (screen shot):

EGMguy_0-1736877272092.png

 

But, when I run the program, I get

EGMguy_1-1736877317333.png

The only way to avoid this error seems to be to add mkl_sequential.2.dll in the ... Common7/IDE folder.

 

0 Kudos
Shiquan_Su
Moderator
2,345 Views

Hi, there:

Are you familiar with dynamic linking and static linking? The .dll files in Windows mean dynamic linking. What I showed you above is a static linking solution. It seems that you need a dynamic linking solution. I edited the configuration in https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-link-line-advisor.html

accordingly. and it shows that you need nothing for linking flag, and you need "/4I8 /Qmkl-ilp64:sequential /MD" for compile flag. Do you know which button in your VS panel to hit and which fields to edit to put in the above flags? Do you know which button to click to instruct VS to print out the build(compile/link) command? The above error seems like you compile the test code in a static linking way, but run it as a dynamic linking app. 

 

Shiquan_Su_0-1736878556766.png

 

0 Kudos
EGMguy
Novice
2,294 Views

Hi, Shiquan_Su

Unfortunately, I do not know where these flags can be set within MS VS - at least it is not obvious how to do it (I tried project properties, but there was no option to "set flags".  Also, I tried using the command-line procedure you mentioned, but immediately encountered an error:  (again, I'm no expert with command-line programming and have no idea how to fix the error).  Any help with this or the MS VS option would be highly appreciated.

EGMguy_0-1736884419652.png

Thanks.

 

 

0 Kudos
Shiquan_Su
Moderator
2,277 Views

You can not use the normal windows dark terminal for the above test. The normal window has not set up oneapi yet.

You may follow the steps on this page:

https://www.intel.com/content/www/us/en/docs/dpcpp-cpp-compiler/developer-guide-reference/2025-0/use-the-command-line-on-windows.html

to launch the oneAPI windows command prompt. The terminal will first print out the oneAPI env initialization steps for you.

0 Kudos
Shiquan_Su
Moderator
2,253 Views

In your Windows OS "start" menu, you should be able to search for: "Intel oneAPI command prompt for Intel 64 for Visual Studio 2022", which should initialize the oneAPI env for you.

0 Kudos
EGMguy
Novice
2,237 Views

Hi, Shiquan_Su,

Indeed, that is what I did, but still get the error that ifx is not recognized.  However, after some searching I found that ifx.exe is located in C:\Program Files (x86)\Intel\oneAPI\compiler\2023.0.0\windows\bin.  There "ifx" is recognized.  I'll try working with this but hope that someone can come up with an easier solution going through MS VS.

Thanks. 

0 Kudos
EGMguy
Novice
2,225 Views

Hi, Shiquan_Su

 

I think I may have serendipitously stumbled on the solution.  On the site: https://stackoverflow.com/questions/79173586/how-to-force-intel-fortran-to-include-mkl-code-into-and-exe-mklsequential-2-dll it is suggested to ensure that "in addition to using Math Kernel Library Sequential /Qmkl:sequential,... for Runtime library, you have to use /libs:static", which is done by selecting the project properties in MS VS and then going to Fortran>Libraries.  Then everything works (at least for the test program I had).

 

Thanks for your time.

 

0 Kudos
Reply