MKL Library and DLLEXPORT

MKL Library and DLLEXPORT

Hello,

I would like to use LAPACK functions in my dynamic link library. In visual studio I set the project properties to link to the math kernel library. However when calling the Fortran subroutine from Java it seems that the LAPACK functions are not found and an error is issued:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'C:\Users\...\Documents\Visual Studio 2012\Projects\TEQ\TEQ\Debug\TEQ': The specified module could not be found.

All the subroutines in the Fortran module are exported using DLLEXPORT and I am able to call them in Java. However when one of the LAPACK subroutines is inserted the error is issued. I am not sure how to export the LAPACK subroutines? Do we need to export the routines or point to them in some way?

Thanks,

Mohammad

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

>>...Unable to load library 'C:\Users\...\Documents\Visual Studio 2012\Projects\TEQ\TEQ\Debug\TEQ': The specified module
>>could not be found.

The path points to your directory ...Projects\TEQ\TEQ\Debug\TEQ. All MKL DLLs are located in [ InstallDir ]\Redist\Ia32\Mkl or [ InstallDir ]\Redist\Intel64\Mkl directories. Do you use single-threaded or multi-threaded MKL libraries? Please verify that all paths to MKL directories are set properly ( take a look at environment variables ).

It is typical for interpreted languages to tell you that your own DLL couldn't be loaded when in fact the problem is a dependent DLL. The MKL DLLs are not added to PATH by default as of the 2013 product, so perhaps you need to add the folder with the MKL DLLs to PATH.

Steve

>>...I am not sure how to export the LAPACK subroutines? Do we need to export the routines or point to
>>them in some way?..

No, you don't need to do this. It would be nice if you provide information what LAPACK functions are used, or will be used, in your application?

I am using the following link to setup the mkl libraries: http://download-software.intel.com/sites/default/files/article/184496/in.... I also ran the file mklvars.bat ia32 to set enviornment variables. However I'm getting the following error when trying to build. Is there a more updated instructions to set up the MKL libraries? I appreciate your help.

Mohammad

Error    1     error #11018: Cannot open mkl_intel_ilp64.lib 

Error    2     fatal error LNK1181: cannot open input file 'mkl_intel_ilp64.lib'    LINK    

Observe the occurrences of "64" in the error messages. Those 64-bit libraries should not have been required if you were compiling for X86, as your using the "ia32"  argument to mklvars.bat. That they are asked for by the linker is an indication that one or more objects/libraries given to the linker were compiled for X64. Check the settings in your project and make sure that X64 is not specified anywhere, clean and rebuild all objects and targets (including user-built libraries and third-party libraries).

The 64 library is for using long int and not 64 arch. I also checked it applies to 32 bit system.

>>...The 64 library is for using long int and not 64 arch. I also checked it applies to 32 bit system...

MKL's long int data type is declared in mkl_types.h header file as follows:

...
/* MKL integer types for LP64 and ILP64 */
#if (!defined(__INTEL_COMPILER)) & defined(_MSC_VER)
#define MKL_INT64 __int64
#define MKL_UINT64 unsigned __int64
#else
#define MKL_INT64 long long int
#define MKL_UINT64 unsigned long long int
#endif

#ifdef MKL_ILP64

/* MKL ILP64 integer types */
#ifndef MKL_INT
#define MKL_INT MKL_INT64
#endif
#ifndef MKL_UINT
#define MKL_UINT MKL_UINT64
#endif
#define MKL_LONG MKL_INT64

#else

/* MKL LP64 integer types */
#ifndef MKL_INT
#define MKL_INT int
#endif
#ifndef MKL_UINT
#define MKL_UINT unsigned int
#endif
#define MKL_LONG long int

#endif
...

and it is Not clear for me why you're using the library. These declarations are needed for compilation and they are Not needed for linking.

Citação:

Mohammad K. escreveu:

The 64 library is for using long int and not 64 arch. I also checked it applies to 32 bit system.

With few exceptions (Pardiso being one), there is no provision for calling MKL routines with 64-bit integer arguments from 32-bit code. Such calls would require at least two versions for each MKL routine that takes one or more integer arguments. Multiple library routines of this nature are not provided in 32-bit MKL. The ILP64 and LP64 MKL libraries contain 64-bit code segments, and they cannot be linked to 32-bit code.

By redefining preprocessor symbols such as MKL_INT, it it possible to deceive the compiler and make it behave as if code using 64-bit integers ought to work on the IA32 platform, but code compiled this way will always result in link time failures.

Steve,

I set the path to the MKL libraries in the command prompt using mklvars.bat. I also set net beans to point the java library path to the MKL path

C:\Program Files\Intel\Composer XE 2013\mkl\lib\ia32

But the error of loading the library is not resolved. Any ideas?

Thanks,

Mohammad

I don't know anything about Netbeans. Did you start Java from the MKL command prompt?  I was suggesting editing the system PATH using Computer > Properties > Advanced > Environment Variables.

Steve

>>C:\Program Files\Intel\Composer XE 2013\mkl\lib\ia32

This is the path to dynamic link libaries. If you execute an MS-DOS command dir *.lib it will show something like this:

31/08/2012 08:30 AM 31,208 mkl_blacs_dll.lib
31/08/2012 08:27 AM 409,086 mkl_blacs_intelmpi.lib
31/08/2012 08:26 AM 408,592 mkl_blacs_mpich2.lib
31/08/2012 07:57 AM 234,498 mkl_blas95.lib
31/08/2012 08:30 AM 79,154 mkl_cdft_core.lib
31/08/2012 08:31 AM 11,108 mkl_cdft_core_dll.lib
31/08/2012 08:07 AM 184,012,776 mkl_core.lib
18/12/2008 02:14 PM 986 mkl_core_dll.lib
31/08/2012 08:06 AM 8,065,526 mkl_intel_c.lib
31/08/2012 08:24 AM 8,223,846 mkl_intel_c_dll.lib
31/08/2012 08:06 AM 4,573,378 mkl_intel_s.lib
31/08/2012 08:24 AM 4,732,946 mkl_intel_s_dll.lib
31/08/2012 08:07 AM 8,907,124 mkl_intel_thread.lib
31/08/2012 08:23 AM 738,540 mkl_intel_thread_dll.lib
31/08/2012 07:31 AM 3,985,884 mkl_lapack95.lib
31/08/2012 08:07 AM 8,122,758 mkl_pgi_thread.lib
31/08/2012 08:23 AM 732,288 mkl_pgi_thread_dll.lib
31/08/2012 08:24 AM 3,027,402 mkl_rt.lib
31/08/2012 08:45 AM 6,240,934 mkl_scalapack_core.lib
31/08/2012 08:45 AM 495,478 mkl_scalapack_core_dll.li
31/08/2012 08:07 AM 2,556,066 mkl_sequential.lib
31/08/2012 08:23 AM 731,986 mkl_sequential_dll.lib
23/07/2009 03:38 PM 440 mkl_solver.lib
23/07/2009 03:38 PM 440 mkl_solver_sequential.lib

Some of these dynamic link libraries are needed for the Linker and all of them are Not executable modules.

>>
>>But the error of loading the library is not resolved. Any ideas?

You need to verify that in case of a 32-bit test application a path to that directory is set:

C:\Program Files\Intel\Composer XE 2013\Redist\ia32\mkl

In that directory ( and sub-directories ) all MKL DLLs for 32-bit Windows platforms are located.

Steve,

I am not using the MKL command prompt to generate the library. I am using the Visual Studio 2012 that comes with Intel Fortran Composer. I was able to compile and link an application that calls the same program. It is the dynamic linking that is not working. Is there an Intel document that describes in detail what are the settings needed in Visual Studio in terms of libraries, include paths, etc to generate a DLL library which can be called from Java? Also I was able to do this for Fortran DLL that is not dependent on MKL, so that only settings are MKL libraries? I tried using the MKL link adviser and inserted all dependent libraries that are needed but still I'm getting an error that the module is not found. Thanks for your help.

Mohammad

Sergey,

It seems this path need to be set in the application running the Java code. I am using Netbeans to run my java application. Do you know how I can set the java library path to the MKL library path? I tried setting in the VM options under run in Netbeans

-Djava.library.path="C:\Program Files\Intel\Composer XE 2013\mkl\lib\ia32"

But this didn't work.

Thanks,

Mohammad

>>...Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library...

Let me know if you need a small test case which uses Java Native Interface ( JNI ) technology and a couple of MKL functions.

>>...Is there an Intel document that describes in detail what are the settings needed in Visual Studio in terms of libraries,
>>include paths, etc to generate a DLL library which can be called from Java?

1. Take a look at Sticky Posts on MKL Forum.

2. Take a look at Java Native Interface technology ( there are lots of documents online ).

>>...I tried setting in the VM options under run in Netbeans
>>
>>-Djava.library.path="C:\Program Files\Intel\Composer XE 2013\mkl\lib\ia32"
>>
>>But this didn't work.

Here is example of how I use Java VM ( from MS-DOS command prompt ) in my JNI test application with a C dynamic link library built with Visual Studio 2005 Professional Edition ( any latest versions of VS will build it as well ):

...
@java.exe -classpath C:\WorkEnv\TestApps\JavaNITest\HelloWorld HelloWorld
...

Java VM loads HelloWorld.class into memory, then it loads HelloWorldDll.dll into memory and after all initializations are completed Java_HelloWorld_displayHelloWorld proxy function is executed. That function is declared as follows:
...
JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld( JNIEnv *env, jobject obj );
...

Output is as follows:
...
C:\WorkEnv\TestApps\JavaNITest\HelloWorld>Run.bat

Hello Java Native Interface!
...

Here is additional information for MKL DLLs.

For example, the following sets of MKL DLLs are needed for systems with different CPUs:

[ Intel Core i7 CPU ]

mkl_rt.dll
mkl_intel_thread.dll
mkl_core.dll
mkl_avx.dll

[ Default CPU ]

mkl_rt.dll
mkl_intel_thread.dll
mkl_core.dll
mkl_def.dll

[ Intel Pentium 4 CPU ]

mkl_rt.dll
mkl_intel_thread.dll
mkl_core.dll
mkl_p4.dl

Here is a working test case and you could use it ( once again, take a look at JNI examples in Java SDK ( v1.4, v1.5, v1.6, etc) ):

...
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// HelloWorldImp.c

#include "Stdafx.h"
#include "HelloWorld.h"

JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld( JNIEnv *env, jobject obj )
{
printf( "Hello Java Native Interface!\n" );
printf( "Hello Intel MKL!\n" );

#ifdef _DEBUG
printf( "Win32 Debug Configuration\n" );
#else
printf( "Win32 Release Configuration\n" );
#endif

HMODULE hMklRtDll = NULL;

void ( *pfMklGetVersionString )( char *, int ) = NULL;
void ( *pfMklGetVersion )( MKLVersion * ) = NULL;

bool bOk = false;

while( true )
{
hMklRtDll = ::LoadLibrary( _T("mkl_rt.dll") );
if( hMklRtDll == NULL )
break;

_tprintf( _T("Dynamic library mkl_rt.dll loaded\n") );

pfMklGetVersionString = ( void ( * )( char *, int ) )::GetProcAddress( hMklRtDll, "MKL_Get_Version_String" );
if( pfMklGetVersionString == NULL )
break;

pfMklGetVersion = ( void ( * )( MKLVersion * ) )::GetProcAddress( hMklRtDll, "MKL_Get_Version" );
if( pfMklGetVersion == NULL )
break;

_tprintf( _T("MKL Initialization Done\n") );

bOk = true;
break;
}

if( bOk == true )
{
_tprintf( "\n" );

MKLVersion Ver = { 0x0 };
int iLenData = 256;
char szVerData[256] = { 0x0 };

pfMklGetVersionString( szVerData, iLenData );
_tprintf( "\t%s\n", szVerData );

pfMklGetVersion( &Ver );
_tprintf( "\tMajor version : %d\n", Ver.MajorVersion );
_tprintf( "\tMinor version : %d\n", Ver.MinorVersion );
_tprintf( "\tUpdate version : %d\n", Ver.UpdateVersion );
_tprintf( "\tProduct status : %s\n", Ver.ProductStatus );
_tprintf( "\tBuild : %s\n", Ver.Build );
// _tprintf( "\tProcessor optimization: %s\n", Ver.Processor );

_tprintf( "\n" );
}
else
_tprintf( _T("MKL Initialization Failed\n") );

if( hMklRtDll != NULL )
{
::FreeLibrary( hMklRtDll );
hMklRtDll = NULL;

_tprintf( _T("Dynamic library mkl_rt.dll unloaded\n") );
}
}
...

This is how output looks like:

...
..\JavaNITest\HelloWorldDll\Release>Run.bat

Hello Java Native Interface!
Hello Intel MKL!
Win32 Release Configuration
Dynamic library mkl_rt.dll loaded
MKL Initialization Done

Intel(R) Math Kernel Library Version 10.3.12 Product Build 20120831 for 32-bit applications
Major version : 10
Minor version : 3
Update version : 12
Product status : Product
Build : 20120831

Dynamic library mkl_rt.dll unloaded
...

>>...the following link to setup the mkl libraries: http://download-software.intel.com/sites/default/files/article/184496/in...

There is a typing error in the document Developing an Intel® MKL based application in Microsoft Visual Studio* - a Beginner's Guide located at: http://download-software.intel.com/sites/default/files/article/184496/in...

On a page 16 instead of:
...
c. Select Project -> Properties -> Linker -> General -> Additional Library Directories. Add the architecture-specific lib folder, for example, [mkl directory]\lib\ia32
...

the directory [mkl directory]\lib\intel64 needs to be used and a corrected text is as follows:
...
c. Select Project -> Properties -> Linker -> General -> Additional Library Directories. Add the architecture-specific lib folder, for example, [mkl directory]\lib\intel64
...

This is because:

- Current project configuration is x64 ( Debug )
- The library mkl_intel_ilp64.lib is located in [mkl directory]\lib\intel64 directory
- There is No mkl_intel_ilp64.lib in [mkl directory]\lib\ia32 directory

If a developer will follow that recommendation exactly there will be an error during linking the test application, something like, ...Library Not Found...

Hi Steve, Could you move the thread to Intel Math Kernel Library forum, please? Thanks.

Login to leave a comment.