<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic dynamic load/free library who used mkl will result in the main program crash in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/dynamic-load-free-library-who-used-mkl-will-result-in-the-main/m-p/1108559#M24232</link>
    <description>&lt;P&gt;Dear Team,&lt;/P&gt;

&lt;P&gt;Hope you are doing well!　I has a &amp;nbsp;dynamic library sample used some simple MKL code, if &amp;nbsp;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" &amp;nbsp;and vs2010.&lt;/P&gt;

&lt;P&gt;The dynamic library's source code and main program's source code could be find in the attahced "purl mkl.rar":&lt;BR /&gt;
	&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;build.bat -- script to build the sample&lt;/SPAN&gt;&lt;BR /&gt;
	Example_with_exporttable.cpp&amp;nbsp;-- source code that use the dynamic library with its export library (no problem)&lt;BR /&gt;
	Example_with_dynamic_load_free.cpp -- source code that use LoadLibrary/FreeLibrary to call the dynamic library (crash)&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.intel.com/legacyfs/online/drupal_files/503091"&gt;503091&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Apr 2016 06:07:04 GMT</pubDate>
    <dc:creator>Jerome_M_</dc:creator>
    <dc:date>2016-04-28T06:07:04Z</dc:date>
    <item>
      <title>dynamic load/free library who used mkl will result in the main program crash</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/dynamic-load-free-library-who-used-mkl-will-result-in-the-main/m-p/1108559#M24232</link>
      <description>&lt;P&gt;Dear Team,&lt;/P&gt;

&lt;P&gt;Hope you are doing well!　I has a &amp;nbsp;dynamic library sample used some simple MKL code, if &amp;nbsp;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" &amp;nbsp;and vs2010.&lt;/P&gt;

&lt;P&gt;The dynamic library's source code and main program's source code could be find in the attahced "purl mkl.rar":&lt;BR /&gt;
	&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;build.bat -- script to build the sample&lt;/SPAN&gt;&lt;BR /&gt;
	Example_with_exporttable.cpp&amp;nbsp;-- source code that use the dynamic library with its export library (no problem)&lt;BR /&gt;
	Example_with_dynamic_load_free.cpp -- source code that use LoadLibrary/FreeLibrary to call the dynamic library (crash)&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.intel.com/legacyfs/online/drupal_files/503091"&gt;503091&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2016 06:07:04 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/dynamic-load-free-library-who-used-mkl-will-result-in-the-main/m-p/1108559#M24232</guid>
      <dc:creator>Jerome_M_</dc:creator>
      <dc:date>2016-04-28T06:07:04Z</dc:date>
    </item>
    <item>
      <title>Hello Jerome,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/dynamic-load-free-library-who-used-mkl-will-result-in-the-main/m-p/1108560#M24233</link>
      <description>&lt;P&gt;Hello Jerome,&lt;/P&gt;

&lt;P&gt;When you are using DLL with static MKL, you need to clean memory after DLL unloading.&lt;/P&gt;

&lt;P&gt;To clean memory please use mkl_free_buffers and&amp;nbsp; mkl_finalize (or mkl_finalize only for MKL 2017b1) when the process is detached via DllMain that you should add to your DLL.&lt;/P&gt;

&lt;P&gt;e.g.&lt;/P&gt;

&lt;P&gt;BOOL WINAPI DllMain(HINSTANCE hInst, DWORD fdwReason, LPVOID lpvReserved) {&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; switch(fdwReason) {&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case DLL_PROCESS_ATTACH:&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case DLL_THREAD_ATTACH:&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case DLL_THREAD_DETACH:&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mkl_thread_free_buffers();&amp;nbsp;&amp;nbsp; //for multithreading&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case DLL_PROCESS_DETACH:&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (NULL == lpvReserved) {&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mkl_free_buffers();&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MKLFreeTls(fdwReason); // this one can be omitted if MKL VML/VSL is not used&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mkl_finalize();&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return TRUE;&lt;/P&gt;

&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2016 11:27:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/dynamic-load-free-library-who-used-mkl-will-result-in-the-main/m-p/1108560#M24233</guid>
      <dc:creator>Maria_K_Intel</dc:creator>
      <dc:date>2016-04-28T11:27:54Z</dc:date>
    </item>
    <item>
      <title>Hi, Maria</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/dynamic-load-free-library-who-used-mkl-will-result-in-the-main/m-p/1108561#M24234</link>
      <description>&lt;P&gt;Hi, Maria&lt;/P&gt;

&lt;P&gt;Thanks for your reply, my problem is resolved as your suggestion.&lt;/P&gt;

&lt;P&gt;BR&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 06:58:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/dynamic-load-free-library-who-used-mkl-will-result-in-the-main/m-p/1108561#M24234</guid>
      <dc:creator>Jerome_M_</dc:creator>
      <dc:date>2016-04-29T06:58:19Z</dc:date>
    </item>
    <item>
      <title>I'm glad to hear it!</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/dynamic-load-free-library-who-used-mkl-will-result-in-the-main/m-p/1108562#M24235</link>
      <description>&lt;P&gt;I'm glad to hear it!&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 10:49:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/dynamic-load-free-library-who-used-mkl-will-result-in-the-main/m-p/1108562#M24235</guid>
      <dc:creator>Maria_K_Intel</dc:creator>
      <dc:date>2016-04-29T10:49:00Z</dc:date>
    </item>
  </channel>
</rss>

