Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Jerome_M_
Beginner
164 Views

dynamic load/free library who used mkl will result in the main program crash

Dear Team,

Hope you are doing well! I has a  dynamic library sample used some simple MKL code, if  load/free this dynamic library in the main program by LoadLibrary/FreeLibrary 542 times then the maim program will crashed and exited, but if I link the dynamic library with its export .lib everything is going OK. I'm confused is there limitations for the trial MKL, could you please confirm it? The tested studio is "parallel_studio_xe_2016_update2_setup.exe"  and vs2010.

The dynamic library's source code and main program's source code could be find in the attahced "purl mkl.rar":
build.bat -- script to build the sample
Example_with_exporttable.cpp -- source code that use the dynamic library with its export library (no problem)
Example_with_dynamic_load_free.cpp -- source code that use LoadLibrary/FreeLibrary to call the dynamic library (crash)

 503091

0 Kudos
3 Replies
Maria_K_Intel
Employee
164 Views

Hello Jerome,

When you are using DLL with static MKL, you need to clean memory after DLL unloading.

To clean memory please use mkl_free_buffers and  mkl_finalize (or mkl_finalize only for MKL 2017b1) when the process is detached via DllMain that you should add to your DLL.

e.g.

BOOL WINAPI DllMain(HINSTANCE hInst, DWORD fdwReason, LPVOID lpvReserved) {

    switch(fdwReason) {

        case DLL_PROCESS_ATTACH:

        case DLL_THREAD_ATTACH:

        break;

 

        case DLL_THREAD_DETACH:

            mkl_thread_free_buffers();   //for multithreading

        break;

 

        case DLL_PROCESS_DETACH:

            if (NULL == lpvReserved) {

                mkl_free_buffers();

                MKLFreeTls(fdwReason); // this one can be omitted if MKL VML/VSL is not used

                mkl_finalize();

            }

        break;

    }

    return TRUE;

}

Jerome_M_
Beginner
164 Views

Hi, Maria

Thanks for your reply, my problem is resolved as your suggestion.

BR

 

Maria_K_Intel
Employee
164 Views

I'm glad to hear it!

Reply