nathrock
nathrock

Reputation: 31

"module could not be found" using MATLAB mex with Fortran and intel mkl

I am trying to execute a MATLAB mex function written in Fortran that uses Intel MKL with the following setup (per http://www.mathworks.com/support/compilers/R2015b/):

  1. MATLAB 2015b, Win64
  2. Visual Studio Professional 2013
  3. Intel Visual Fortran Composer XE 2013 SP1
  4. Rogue Wave IMSL* Fortran Numerical Libraries 7.0.1

So far everything compiles successfully, e.g.,

mex -v Fsolution.f90 COMPFLAGS="/Qopenmp $COMPFLAGS" ...
-I"C:\Program Files (x86)\Intel\Composer XE 2013 SP1\redist\intel64\mkl" ...
-I"C:\Program Files (x86)\VNI\imsl\fnl701\Intel64\include\dll"

yields

... Looking for compiler 'Intel Visual Fortran Composer XE 2013 with Microsoft Visual Studio 2013' ...
... Looking for environment variable 'IFORT_COMPILER14' ...Yes ('C:\Program Files (x86)\Intel\Composer XE 2013 SP1\').
... Looking for file 'C:\Program Files (x86)\Intel\Composer XE 2013 SP1\/Bin/intel64/ifort.exe' ...Yes.
... Looking for folder 'C:\Program Files (x86)\Intel\Composer XE 2013 SP1\' ...Yes.
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 12.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 12.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7' 12.0 ...Yes ('C:\Program Files (x86)\Microsoft Visual Studio 12.0\').
... Looking for file 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64\cl.exe' ...Yes.
... Looking for folder 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC' ...Yes.
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.1' InstallationFolder ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.1' InstallationFolder ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v8.1' InstallationFolder ...Yes ('C:\Program Files (x86)\Windows Kits\8.1\').
Found installed compiler 'Intel Visual Fortran Composer XE 2013 with Microsoft Visual Studio 2013'.
Set PATH = C:\Program Files (x86)\Intel\Composer XE 2013 SP1\\bin\intel64;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\VCPackages;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\..\Common7\IDE;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\..\Common7\Tools;C:\Program Files (x86)\Windows Kits\8.1\\bin\x64;C:\Program Files (x86)\Windows Kits\8.1\\Bin\x86;;C:\Program Files (x86)\VNI\imsl\fnl701\Intel64\lib;C:\Program Files (x86)\VNI\imsl\fnl701\IA32\lib;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\mpirt;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32\mpirt;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32\compiler;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\MATLAB\R2015b\runtime\win64;C:\Program Files\MATLAB\R2015b\bin;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Skype\Phone\
Set INCLUDE = C:\Program Files (x86)\Intel\Composer XE 2013 SP1\\include;C:\Program Files (x86)\Intel\Composer XE 2013 SP1\\compiler\include;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\ATLMFC\INCLUDE;C:\Program Files (x86)\Windows Kits\8.1\\include\shared;C:\Program Files (x86)\Windows Kits\8.1\\include\um;C:\Program Files (x86)\Windows Kits\8.1\\include\winrt;C:\Program Files\MATLAB\R2015b\extern\include;;
Set LIB = C:\Program Files (x86)\Intel\Composer XE 2013 SP1\\lib\intel64;C:\Program Files (x86)\Intel\Composer XE 2013 SP1\\compiler\lib\intel64;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\Lib\amd64;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\ATLMFC\Lib\amd64;C:\Program Files (x86)\Windows Kits\8.1\\lib\winv6.3\um\x64;C:\Program Files\MATLAB\R2015b\lib\win64;
Set LIBPATH = C:\Program Files (x86)\Intel\Composer XE 2013 SP1\\compiler\Lib\Intel64;C:\Program Files (x86)\Windows Kits\8.1\\LIB\x64;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\LIB\amd64;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\ATLMFC\LIB\amd64;C:\Program Files\MATLAB\R2015b\extern\lib\win64;;
Options file details
-------------------------------------------------------------------
    Compiler location: C:\Program Files (x86)\Intel\Composer XE 2013 SP1\
    Options file: C:\Users\Marx\AppData\Roaming\MathWorks\MATLAB\R2015b\mex_FORTRAN_win64.xml
    CMDLINE100 : ifort /c /Qopenmp /nologo /fpp /Qprec /MD /fp:source /assume:bscc -I"C:\Program Files (x86)\Intel\Composer XE 2013 SP1\redist\intel64\mkl" -I"C:\Program Files (x86)\VNI\imsl\fnl701\Intel64\include\dll"  -I"C:\Program Files\MATLAB\R2015b\extern\include"  /DMX_COMPAT_32   /DMATLAB_MEX_FILE /O2 /DNDEBUG "C:\Users\Marx\Dropbox\PRT Uncertainty\Code\Revised Manuscript\Habit-fixme-test\Fsolution.f90" /FoC:\Users\Marx\AppData\Local\Temp\mex_8780273189710_2516\Fsolution.obj
    CMDLINE200 : link  /nologo /manifest /INCREMENTAL:NO /DLL   /EXPORT:MEXFUNCTION C:\Users\Marx\AppData\Local\Temp\mex_8780273189710_2516\Fsolution.obj  /LIBPATH:"C:\Program Files\MATLAB\R2015b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib  ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /out:Fsolution.mexw64
    CMDLINE250 : mt -outputresource:Fsolution.mexw64;2 -manifest Fsolution.mexw64.manifest
    CMDLINE300 : del Fsolution.exp Fsolution.lib Fsolution.mexw64.manifest Fsolution.ilk
    COMPILER : ifort
    COMPFLAGS : /Qopenmp /nologo /fpp /Qprec /MD /fp:source /assume:bscc -I"C:\Program Files (x86)\Intel\Composer XE 2013 SP1\redist\intel64\mkl" -I"C:\Program Files (x86)\VNI\imsl\fnl701\Intel64\include\dll"  -I"C:\Program Files\MATLAB\R2015b\extern\include"  /DMX_COMPAT_32   /DMATLAB_MEX_FILE
    COMPDEFINES : /DMX_COMPAT_32   /DMATLAB_MEX_FILE
    OPTIMFLAGS : /O2 /DNDEBUG
    INCLUDE : -I"C:\Program Files (x86)\Intel\Composer XE 2013 SP1\redist\intel64\mkl" -I"C:\Program Files (x86)\VNI\imsl\fnl701\Intel64\include\dll"  -I"C:\Program Files\MATLAB\R2015b\extern\include"
    DEBUGFLAGS : /Z7
    LINKER : link
    LINKFLAGS :  /nologo /manifest /INCREMENTAL:NO
    LINKTYPE : /DLL
    LINKEXPORT :  /EXPORT:MEXFUNCTION
    LINKLIBS : /LIBPATH:"C:\Program Files\MATLAB\R2015b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib  ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
    LINKDEBUGFLAGS : /debug /PDB:"Fsolution.mexw64.pdb"
    LINKOPTIMFLAGS : 
    OBJEXT : .obj
    LDEXT : .mexw64
    SETENV : set COMPILER=ifort 
                set COMPFLAGS=/c /Qopenmp /nologo /fpp /Qprec /MD /fp:source /assume:bscc -I"C:\Program Files (x86)\Intel\Composer XE 2013 SP1\redist\intel64\mkl" -I"C:\Program Files (x86)\VNI\imsl\fnl701\Intel64\include\dll"  -I"C:\Program Files\MATLAB\R2015b\extern\include"  /DMX_COMPAT_32   /DMATLAB_MEX_FILE /DMX_COMPAT_32   /DMATLAB_MEX_FILE $MATLABMEX 
                set OPTIMFLAGS=/O2 /DNDEBUG 
                set DEBUGFLAGS=/Z7 
                set LINKER=link 
                set LINKFLAGS= /nologo /manifest /INCREMENTAL:NO /export:%ENTRYPOINT% /DLL /LIBPATH:"C:\Program Files\MATLAB\R2015b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib  ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  /EXPORT:MEXFUNCTION 
                set LINKDEBUGFLAGS=/debug /PDB:"%OUTDIR%%MEX_NAME%.mexw64.pdb" 
                set NAME_OUTPUT=/out:"%OUTDIR%%MEX_NAME%%MEX_EXT%"
    FORTRANROOT : C:\Program Files (x86)\Intel\Composer XE 2013 SP1\
    VCROOT : C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC
    SDKROOT : C:\Program Files (x86)\Windows Kits\8.1\
    MATLABROOT : C:\Program Files\MATLAB\R2015b
    ARCH : win64
    SRC : "C:\Users\Marx\Dropbox\PRT Uncertainty\Code\Revised Manuscript\Habit-fixme-test\Fsolution.f90"
    OBJ : C:\Users\Marx\AppData\Local\Temp\mex_8780273189710_2516\Fsolution.obj
    OBJS : C:\Users\Marx\AppData\Local\Temp\mex_8780273189710_2516\Fsolution.obj 
    SRCROOT : C:\Users\Marx\Dropbox\PRT Uncertainty\Code\Revised Manuscript\Habit-fixme-test\Fsolution
    DEF : C:\Users\Marx\AppData\Local\Temp\mex_8780273189710_2516\Fsolution.def
    EXP : Fsolution.exp
    LIB : Fsolution.lib
    EXE : Fsolution.mexw64
    ILK : Fsolution.ilk
    MANIFEST : Fsolution.mexw64.manifest
    TEMPNAME : Fsolution
    EXEDIR : 
    EXENAME : Fsolution
    OPTIM : /O2 /DNDEBUG
    LINKOPTIM : 
-------------------------------------------------------------------
Building with 'Intel Visual Fortran Composer XE 2013 with Microsoft Visual Studio 2013'.
ifort /c /Qopenmp /nologo /fpp /Qprec /MD /fp:source /assume:bscc -I"C:\Program Files (x86)\Intel\Composer XE 2013 SP1\redist\intel64\mkl" -I"C:\Program Files (x86)\VNI\imsl\fnl701\Intel64\include\dll"  -I"C:\Program Files\MATLAB\R2015b\extern\include"  /DMX_COMPAT_32   /DMATLAB_MEX_FILE /O2 /DNDEBUG "C:\Users\Marx\Dropbox\PRT Uncertainty\Code\Revised Manuscript\Habit-fixme-test\Fsolution.f90" /FoC:\Users\Marx\AppData\Local\Temp\mex_8780273189710_2516\Fsolution.obj
link  /nologo /manifest /INCREMENTAL:NO /DLL   /EXPORT:MEXFUNCTION C:\Users\Marx\AppData\Local\Temp\mex_8780273189710_2516\Fsolution.obj  /LIBPATH:"C:\Program Files\MATLAB\R2015b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib  ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /out:Fsolution.mexw64
   Creating library Fsolution.lib and object Fsolution.exp

mt -outputresource:Fsolution.mexw64;2 -manifest Fsolution.mexw64.manifest
Microsoft (R) Manifest Tool version 6.3.9600.16384

Copyright (c) Microsoft Corporation 2012. 

All rights reserved.


del Fsolution.exp Fsolution.lib Fsolution.mexw64.manifest Fsolution.ilk
MEX completed successfully.

However, Fsolution.mexw64 fails to execute with the following error:

Invalid MEX-file '...\Fsolution.mexw64': The specified module could not be found.

Dependency walker shows that

MKL_INTEL_THREAD.DLL "Error opening file. The system cannot find the file specified (2)."

As an alternative I compiled with

mex -v Fsolution.f90 COMPFLAGS="/Qopenmp $COMPFLAGS" ...
-L"C:\Program Files (x86)\Intel\Composer XE 2013 SP1\mkl\lib\intel64" -lmkl_intel_thread ...
-I"C:\Program Files (x86)\VNI\imsl\fnl701\Intel64\include\dll"

but received the same errors in both MATLAB and dependency walker. Other mex functions that do not rely on MKL_INTEL_THREAD.DLL execute without error.

Upvotes: 1

Views: 378

Answers (2)

Maggie Young
Maggie Young

Reputation: 11

I have the same problem when executing a MATLAB mex function written in C that uses Intel MKL. Dependency walker shows the same problem. I just copy the file (find in the computer, usually in C:\) to the folder where the C file exists. Then it works.

Hope this will help.

Upvotes: 1

nathrock
nathrock

Reputation: 31

This problem was the result of a change to the name of the dynamic library. In IMSL Fortran Library Version 6 the dynamic library was "link_fnl_shared.h". In version 7, it is named "link_fnl_shared_imsl.h".

See IMSL Fortran 7.1 Getting Started Guide - Windows.

Upvotes: 1

Related Questions