Community
cancel
Showing results for 
Search instead for 
Did you mean: 
marko_m_
Beginner
698 Views

Basic linking problem with MKL library

Hi everybody,

Long ago I used to use mkl library 9.1.027, and used it with great joy to run some programs that included a lot of operations on matrices. And it was easy to include in the program, just right click projects->properties and include:

c/c++-->general-->Additional include directories        C:\Program Files\Intel\MKL\9.1.027\include 

linker-->general-->Additional library directories           C:\Program Files\Intel\MKL\9.1.027\ia32\lib

linker-->input-->additional dependencies                    libguide40.lib mkl_c.lib 

 

and in the code to use

extern "C" {//
#include"mkl_cblas.h"
#include"mkl_lapack.h"
#include "mkl_service.h"
#include "mkl.h"
}//

and the programs worked and the library performed really well. Now i would like to see if there are any improvements that could benefit my programs, and so i downloaded the free mkl library w_mkl_2017.3.210.exe,  installed it (got something like IntelSWTools\compilers_and_libraries_2017.4.210), and went to right click projects->properties, removed the include that were used for mkl library 9.1.027. Then per instruction from the website first i went Configuration Properties->Intel Performance Libraries and set the Use Intel MKL option to Parallel, tried to compile program in Visual studio, and it compiled but when I run the program it says "The application was unable to start correctly (0xc000007b). Click OK to close the application". Then I used  the command line tool to give me the dependencies to use, to input manually, so I need static linking, for windows, ia32 architecture, openmp, in visual studio, and the tool gave me what to use and I placed the suggestions (hopefully in the right place) but the results were the same, I got the exact same message.

As above I added:

c/c++-->general-->Additional include directories        C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017.4.210\windows\mkl\include

linker-->general-->Additional library directories          C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017.4.210\windows\mkl\lib\ia32

                                                            C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017.4.210\windows\mkl\..\compiler\lib\ia32

linker-->input-->additional dependencies                    mkl_intel_c.lib mkl_intel_thread.lib mkl_core.lib libiomp5md.lib

I have windows 7 ultimate and for Visual Studio 2013 Ultimate. 

Any and all help how to  make the mkl library run is more than welcome. It can be the automatic linking with Intel performance libraries or by manually setting the needed field (I would prefer this one but anything is ok).

 

Thanks a lot in advance.

0 Kudos
13 Replies
mecej4
Black Belt
697 Views

There are far too many "unknowns" compared to the few "equations" in your post, so I suspect that the problem is underdetermined, and therefore there may be a large number of possible "solutions".

Since you are able to build an EXE, but running that EXE fails, possibly because it does not find the proper runtime DLLs that it depends on, here is a suggestion for loosening the logjam.

1. Open a 32-bit Icl/Ifort command window, and change to a working directory of your choice.

2. In that directory, create a source file that uses at least one MKL routine. If you do not have a short one handy, use the following source, which I will assume is in file xlu.c.

#include <mkl.h>

#include "mkl_lapack.h"

#define N 3

double* A;
lapack_int n=N;
lapack_int* ipiv;

int main(){
    int i=0,j=0,ierr=0;
    A=malloc(n*n*sizeof(double));
    ipiv=malloc(n*sizeof(lapack_int));
    A[0]=1e0;A[1]=0e0;A[2]=0e0;
    A[3]=2e0;A[4]=3e0;A[5]=0e0;
    A[6]=4e0;A[7]=5e0;A[8]=6e0;
    ierr=LAPACKE_dgetrf(LAPACK_ROW_MAJOR,n,n,A,n,ipiv);
    for(i=0;i<n;i++){
        for(j=0;j<n;j++)
          printf("%f ",A[i*n+j]);
        printf("\n");
    }
    printf("ierr=%d\n",ierr);
    free(A);
    free(ipiv);
    return 0;
}

3. Build with the command cl /MD xlu.c mkl_rt.lib.

4. Run the program xlu.exe. The expected output to the console:

4.000000 5.000000 6.000000
0.250000 -1.250000 -1.500000
0.500000 -0.400000 -3.600000
ierr=0

If something goes wrong, please collect and report the details in your reply.

marko_m_
Beginner
697 Views

Hi mecej4,

First of, thank you very much for the time you have allocated to try and help me. I will try to be more, and more specific as we go along to solve this problem. And I apologize, it wasn't on purpose that I didn't provide more info. If I miss anything please tell me so that my replies can be more meaningful.

I can definitely build the EXE file, and for my calculations I need to use the following MKL functions (these are in version 9.1.027, and all versions of the functions work with MKL_Complex16, so complex<double> arguments, adn the code is c++, but I don't know if that matters):

cblas_zgemm, cblas_zdscal, zgetri, zgetrf, vzSqrt, cblas_zaxpy, so nothing special :D. Now my PC is Windows 7 Ultimate 64-bit, but the target exe should be built with ia32. 

I have done per your instructions, and went to Intel Parallel Studio XE 2017-> Compiler and performance Libraries-> Command Prompt with Intel Compiler 17.0 Update 4 and used the IA-32 Visual Studio 2013 environment command prompt to set the environment. With the command

cl /MD "C:\Users\Marko\MKL Test\xlu.c" mkl_rt.lib

i get the xlu.exe and when I run it, I get the exact same thing as you.

What is the next step? Thanks a lot, I really appreciate it.

mecej4
Black Belt
697 Views

Good, now we know that your installation is basically correct. 

After you changed your Visual Studio settings for the changeover to the newer version of MKL, did you do a clean and rebuild?

From the Intel Parallel Studio XE 2017 command prompt, change to the directory containing your target EXE, and run the EXE (with command line arguments, if any) from the command prompt. If you see pop-up message(s) regarding missing DLLs, please note them. You can also use the command path > path.txt and then type out path.txt to see if any incorrect paths to 64-bit DLLs occur in the search path before the corresponding 32-bit DLLs.

It may help if you put the Visual Studio build log file (buildlog.htm) into a zip file and attach that zip file to your reply.

Jing_X_Intel
Employee
697 Views

Did you use https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor to help you to build the exe?

marko_m_
Beginner
697 Views

Hi all,

just a small update before I go to work.

@Jing X. Yes, i used both the mkl-link-line-advisor, and the mkl_link_tool.exe, but thank you for the suggestions. I am 100% certain that I did something wrong, but that is what I have to bother all of you to find out what.

@mecej4 Yes, whenever I do some bigger changes I always do a clean and a rebuild. Thank you very much for the good suggestions, and also when I tried the ia32 command prompt with my EXE, it worked, and produced expected results :D. When I come back later I will do more tests, to see what I did wrong when I set the paths, and dependencies in Visual Studio, but until then if you or anyone else has any other suggestions I more than welcome them.

Thank you all in advance.

Jing_X_Intel
Employee
697 Views

1. Have you tried to add "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017.4.210\windows\redist\ia32_win\mkl" to "VC++ Directories -> General -> Executable Directories"?

2. As suggested at https://stackoverflow.com/questions/10492037/the-application-was-unable-to-start-correctly-0xc000007b, please use dependency walker to check whether there is a problem between your application and its dependencies.

SergeyKostrov
Valued Contributor II
697 Views

>>...it says "The application was unable to start correctly (0xc000007b). Click OK to close the application". When compiled with '-mkl' option a typical threaded 64-bit application for an AVX2 system uses these MKL DLLs ( let's say some matrix multiplication processing with CBLAS functions needs to be done ): mkl_rt.dll mkl_core.dll mkl_avx2.dll mkl_intel_thread.dll I have several computer systems and every time I detect some run time issue(s) similar to what you've described I copy these DLLs to a folder where a compiled executable was saved without any changes to Environment Variables. >>Then I used the command line tool to give me the dependencies to use, to input manually, so I need static linking, for >>windows, ia32 architecture, openmp, in visual studio Take into account that some MKL DLLs are loaded at run-time by mkl_rt.dll. It means, that MS Depends won't show all DLL dependencies.
marko_m_
Beginner
697 Views

Hi all,

So I did the following, since my EXE was able to run when I used the  Intel Parallel Studio XE 2017-> Compiler and performance Libraries-> Command Prompt with Intel Compiler 17.0 Update 4 and used the IA-32 Visual Studio 2013 environment command prompt, I echoed the PATH, LIB and INCLUDE variables, and copied all the mkl destinations I saw in these variables to the visual studio additional include and library directories. Now I can run the program from inside the visual studio but I have the following observation and question:

1) When I run the EXE in  Intel Parallel Studio XE 2017-> Compiler and performance Libraries-> Command Prompt with Intel Compiler 17.0 Update 4 and used the IA-32 Visual Studio 2013 environment command prompt (the one built with visual studio in release win32 form, and just run it in the Command Prompt with Intel Compiler 17.0 Update 4 IA-32 Visual Studio 2013 environment command prompt) and when I run the same EXE from within visual studio, there is about 3x difference in speed, it is 3x slower in visual studio. Is this normal or expected behaviour? If it is normal can someone explain why this is so?

2) I also used dependency walker, and it seems, that somehow I have a remnant from the older mkl libray, it includes em64t\bin\libiomp5md.dll. If anyone has an idea how to remove this from the build I will be very grateful. So when I run the EXE from visual studio it works, but slower, from IA32 command prompt it works, and fast, and if I use the normal command prompt it still doesn't work and shows the same error message, "The application was unable to start correctly (0xc000007b). Click OK to close the application".

3) When I use mklvars.bat ia32 vs2013 (or should I use some other .bat file) is there a way to make the changes to the path and other variables permanent, or is there an efficient way to purge these variables if a newer version comes about? How could I remove or again re-add the old mkl variables to the path and other variables (besides reinstalling them) ?

Thank you all so much for your time and advice.

Jing_X_Intel
Employee
697 Views

1) It seems to be a Visual Studio-related problem.

https://social.msdn.microsoft.com/Forums/vstudio/en-US/50661821-5925-4dd3-ab38-a52ccdf6383e/visual-s...;

2) Did you put libiomp5md.lib in your linking list when you build your program?

In normal command prompt, your exe cannot find MKL dlls so the error message appears. Please add the path of MKL dll directory into the system's environment variable PATH.

3) Suppose you have MKL 9.0 and 2017 installed in your system. You can execute the mklvars.bat in the bin directory of MKL 9 to set environment variables for the old version. If you want to use the new version, you can start a new command prompt and then execute the mklvars.bat contained in the bin directory of the new MKL version.

Alternatively, you may manually set these environment variables using windows environment variable setting command.

marko_m_
Beginner
696 Views

Hi Jing X.,

I did a little searching and found out that for 1)  it is because VS uses the debug heap instead of the default one. Anyway if you set the _NO_DEBUG_HEAP=1 to Project Properties->Configuration Properties->Debugging->Environment

like it says here, the speeds of execution become the same, if this solution is appropriate for the person that does the testing. So read about Low-Fragmentation heap, and see if it is ok for you to remove it.

https://stackoverflow.com/questions/1060337/why-does-my-stl-code-run-so-slowly-when-i-have-the-debug...

2) I did this and now I don't have the libiomp5md.dll problem, but I screwed up something else. Now at least I can see the light at the end of the tunnel, so I will play around more, and when I find what I did wrong I will post my solution here (or ask for help if I get stuck).

Thank you all for the wonderful advice.

SergeyKostrov
Valued Contributor II
696 Views

>>...When I use mklvars.bat... Take a look at that bat-file and a new, tuned configuration for your needs, could be created. Note: I recently did some corrections to MS bat-files to enable support of a legacy Intel C++ cross-compiler v11 for Itanium architecture to work with VSs 2005, 2008, and 2010.
Jing_X_Intel
Employee
696 Views

Thank you for sharing the KB article.

marko_m_
Beginner
696 Views

Hi everybody,

I finally got ome time for testing, and lets say I have made it running. I had to remove the path to the libiomp5md.dll from the path variable in  Advanced System Settings->Environment Variables->System Variables and then delete the path for the old MKL 10.0.012 library and add the new path for the 2017 version. After that I just had to start the Intel Parallel Studio XE 2017 -> Visual Studio Integrations -> Launch VS2013. In Visual Studio I just had to go to Project Properties->Configuration Properties->Intel Performance Libraries and choose to use Parallel Intel MKL. I checked in dependency walker, and in essence it works, there are some functions  that cannot be reached (at least what the dependency walker says) but never the less it works, and gives correct results.

I would like to thank all the people that have given suggestion, you have helped me a lot. I have additional questions, but they are for a new thread, and I hope to see you there. Also I hope that this thread can help somebody else if they have similar troubles like me.

Reply