- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, Maria
Thanks for your reply, my problem is resolved as your suggestion.
BR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm glad to hear it!

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page