<?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 Is it safe to call mkl_thread_free_buffers() as first MKL funct in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829621#M5442</link>
    <description>Daniel, why are linkingmkl_intel_s.lib instead ofmkl_intel_c.lib? please try with the recommendedmkl_intel_c library first.</description>
    <pubDate>Tue, 10 May 2011 16:49:13 GMT</pubDate>
    <dc:creator>Gennady_F_Intel</dc:creator>
    <dc:date>2011-05-10T16:49:13Z</dc:date>
    <item>
      <title>Is it safe to call mkl_thread_free_buffers() as first MKL function on a thread?</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829617#M5438</link>
      <description>Hi there,&lt;BR /&gt;&lt;BR /&gt;I use MKL 10.3.0 on mulitple threads on Windows. Right before a thread finishes I invoke mkl_thread_free_buffers() in order to release all buffers MKL has allocated for this thread.&lt;BR /&gt;Sometimes I get the following error from application verifier&lt;BR /&gt; vrfcore.dll!VerifierStopMessageEx(_AVRF_LAYER_DESCRIPTOR * LayerDescriptor=0x00396060, unsigned long StopCode=769, unsigned long Param1=4294967295, unsigned long Param2=43962, unsigned long Param3=0, unsigned long Param4=0, _AVRF_STOP_EXTRA * StopExtra=0x00000000, ...) Line 551 C++&lt;BR /&gt; vfbasics.dll!CheckTlsIndex(unsigned long Index=4294967295) Line 222 + 0x14 bytes C&lt;BR /&gt; vfbasics.dll!AVrfpTlsGetValue(unsigned long dwTlsIndex=4294967295) Line 417 C&lt;BR /&gt; mydll.dll!_mkl_serv_mkl_thread_free_buffers() + 0x32 bytes&lt;BR /&gt; mydll.dll!_callthreadstartex() Line 348 + 0x6 bytes C&lt;BR /&gt; mydll.dll!_threadstartex(void * ptd=0x0809ede8) Line 326 + 0x5 bytes&lt;BR /&gt;It seems like this happens when mkl_thread_free_buffers() is the first MKL function I invoke, i.e. when I did not use any MKL function before.&lt;BR /&gt;I checked the documentation but did not find any explicit answer, so I wonder whether it is safe to call mkl_thread_free_buffers() as first MKL function? Or will that attempt to access some thread management information that is not set up yet?&lt;BR /&gt;&lt;BR /&gt;Thanks a lot,&lt;BR /&gt;&lt;BR /&gt;Daniel</description>
      <pubDate>Thu, 05 May 2011 10:06:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829617#M5438</guid>
      <dc:creator>djunglas</dc:creator>
      <dc:date>2011-05-05T10:06:59Z</dc:date>
    </item>
    <item>
      <title>Is it safe to call mkl_thread_free_buffers() as first MKL funct</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829618#M5439</link>
      <description>Hi Daniel,&lt;BR /&gt;&lt;BR /&gt;Thanks for your questions. It looks like it's an unknown problem with mkl_thread_free_buffers().&lt;BR /&gt;Could you please create some small testcase to reproduce the problem on our side?</description>
      <pubDate>Thu, 05 May 2011 13:43:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829618#M5439</guid>
      <dc:creator>barragan_villanueva_</dc:creator>
      <dc:date>2011-05-05T13:43:02Z</dc:date>
    </item>
    <item>
      <title>Is it safe to call mkl_thread_free_buffers() as first MKL funct</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829619#M5440</link>
      <description>Thank you, Daniel for your sample program. But I still can't reproduce the issue. Could you please provide more details about your problem: which compiler do you use, how do you link with MKL?&lt;BR /&gt;&lt;BR /&gt;Thanks, Julia&lt;BR /&gt;</description>
      <pubDate>Tue, 10 May 2011 11:35:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829619#M5440</guid>
      <dc:creator>Julia_S_Intel1</dc:creator>
      <dc:date>2011-05-10T11:35:51Z</dc:date>
    </item>
    <item>
      <title>Is it safe to call mkl_thread_free_buffers() as first MKL funct</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829620#M5441</link>
      <description>Here is how I compile/link (I use .bat script under cygwin):&lt;BR /&gt;&lt;PRE&gt;[bash]@echo off

SET MKL=&lt;PATH-TO-MKL&gt;/mkl/ia32/lib/

echo "Compile"
cl -D_CRT_SECURE_NO_DEPRECATE -Gz -MT -W3 -Od -c mklproblem.c

echo "Link"
cl -D_CRT_SECURE_NO_DEPRECATE -Femklproblem.exe mklproblem.obj %MKL%mkl_intel_s.lib %MKL%mkl_sequential.lib %MKL%mkl_core.lib

echo "Run"
mklproblem[/bash]&lt;/PATH-TO-MKL&gt;&lt;/PRE&gt; and here is the output&lt;BR /&gt;&lt;PRE&gt;[bash]"Compile"
Microsoft  32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

mklproblem.c
mklproblem.c(22) : warning C4007: 'main' : must be '__cdecl'
"Link"
Microsoft  32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

Microsoft  Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:mklproblem.exe
mklproblem.obj
&lt;PATH-TO-MKL&gt;/ia32/lib/mkl_intel_s.lib
&lt;PATH-TO-MKL&gt;/ia32/lib/mkl_sequential.lib
&lt;PATH-TO-MKL&gt;/ia32/lib/mkl_core.lib
"Run"

[/bash]&lt;/PATH-TO-MKL&gt;&lt;/PATH-TO-MKL&gt;&lt;/PATH-TO-MKL&gt;&lt;/PRE&gt; When I run without application verifier then everything is fine. When I run with application verifier I get this backtrace:&lt;BR /&gt;&lt;PRE&gt;[bash]&amp;gt;    ntdll.dll!7c81a251()     
     [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]    
     kernel32.dll!77e424fd()     
     mklproblem.exe!004013a0()     
     vfbasics.dll!AVrfpStandardThreadFunction(void * Context=0x01cd3fe0)  Line 656 + 0x6 bytes    C
     kernel32.dll!77e6482f()     
[/bash]&lt;/PRE&gt; When I add -DNO_PROBLEM to the compile command then everything is fine.</description>
      <pubDate>Tue, 10 May 2011 15:20:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829620#M5441</guid>
      <dc:creator>djunglas</dc:creator>
      <dc:date>2011-05-10T15:20:41Z</dc:date>
    </item>
    <item>
      <title>Is it safe to call mkl_thread_free_buffers() as first MKL funct</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829621#M5442</link>
      <description>Daniel, why are linkingmkl_intel_s.lib instead ofmkl_intel_c.lib? please try with the recommendedmkl_intel_c library first.</description>
      <pubDate>Tue, 10 May 2011 16:49:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829621#M5442</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2011-05-10T16:49:13Z</dc:date>
    </item>
    <item>
      <title>Is it safe to call mkl_thread_free_buffers() as first MKL funct</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829622#M5443</link>
      <description>Linking with mkl_intel_c.lib instead of mkl_intel_s.lib gives me&lt;BR /&gt;&lt;PRE&gt;[bash]mklproblem.obj: error LNK2019: unresolved external symbol _MKL_Thread_Free_Buffers@0 referenced in function _threadfunc@4[/bash]&lt;/PRE&gt; My link command is now&lt;BR /&gt;&lt;PRE&gt;[bash]cl -D_CRT_SECURE_NO_DEPRECATE -Femklproblem.exe mklproblem.obj %MKL%mkl_intel_c.lib %MKL%mkl_sequential.lib %MKL%mkl_core.lib[/bash]&lt;/PRE&gt; Is that what you wanted me to do or did I mess up?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;Daniel</description>
      <pubDate>Tue, 10 May 2011 17:29:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829622#M5443</guid>
      <dc:creator>djunglas</dc:creator>
      <dc:date>2011-05-10T17:29:19Z</dc:date>
    </item>
    <item>
      <title>Is it safe to call mkl_thread_free_buffers() as first MKL funct</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829623#M5444</link>
      <description>OK, I am sorry. It seems like I have messed up. Using mkl_intel_c.lib seems to work.&lt;BR /&gt;I have slightly modified my example. It now looks like this:&lt;BR /&gt;&lt;PRE&gt;[cpp]#include &lt;STDIO.H&gt;
#include &lt;PROCESS.H&gt;
#include &lt;WINDOWS.H&gt;
#include &lt;MKL_SERVICE.H&gt;
#include &lt;MKL_BLAS.H&gt;

#ifdef WITH_DGEMM
/* Invoke dgemm with a very simple problem. */
static void
call_dgemm(void)
{
#define ROWS 2
	int m = ROWS, n = ROWS, k = ROWS;
	char transa = 'N';
	char transb = 'N';
	double alpha = 1.0;
	double a[ROWS * ROWS];
	int lda = ROWS;
	double b[ROWS * ROWS];
	int ldb = ROWS;
	double beta = 1.0;
	double c[ROWS * ROWS];
	int ldc = ROWS;
	int i, j;
	for (i = 0; i &amp;lt; ROWS; ++i) {
		for (j = 0; j &amp;lt; ROWS; ++j) {
			a[i * ROWS + j] = (i == j) ? 1.0 : 0.0;
			b[i * ROWS + j] = (i == j) ? 1.0 : 0.0;
			c[i * ROWS + j] = (i == j) ? 1.0 : 0.0;
		}
	}
	printf("Calling dgemm...n");
	dgemm(&amp;amp;transa, &amp;amp;transb, &amp;amp;m, &amp;amp;n, &amp;amp;k, α, a, &amp;amp;lda, b, &amp;amp;ldb, β, c, &amp;amp;ldc);
	printf("dgemm finishedn");
}
#endif /* WITH_DGEMM */

/* Thread worker function. */
static unsigned __stdcall
threadfunc(void *arg)
{
	unsigned int const *action = arg;
	if ( *action ) {
#ifdef WITH_DGEMM
		call_dgemm();
#endif /* WITH_DGEMM */
	} else {
		Sleep(5000);
	}
#ifndef NO_PROBLEM
	mkl_thread_free_buffers();
#endif
	return 0;
}

#define NUM_THREADS 10

int main(void)
{
	HANDLE threads[NUM_THREADS];
	unsigned int action[NUM_THREADS];
	int i;

#ifdef WITH_DGEMM
	call_dgemm();
#endif /* WITH_DGEMM */

	printf("Forking threads ...n");
	for (i = 0; i &amp;lt; NUM_THREADS; ++i) {
		action&lt;I&gt; = i == 0;
		threads&lt;I&gt; = (HANDLE)_beginthreadex(NULL, 0, threadfunc, &amp;amp;action&lt;I&gt;, 0, NULL);
	}
	printf("%d threads forked.n", NUM_THREADS);

	printf("Waiting for threads ...n");
	for (i = 0; i &amp;lt; NUM_THREADS; ++i) {
		WaitForSingleObject(threads&lt;I&gt;, INFINITE);
		CloseHandle(threads&lt;I&gt;);
	}
	printf("%d threads complete.n", NUM_THREADS);
	return 0;
}
[/cpp]&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/MKL_BLAS.H&gt;&lt;/MKL_SERVICE.H&gt;&lt;/WINDOWS.H&gt;&lt;/PROCESS.H&gt;&lt;/STDIO.H&gt;&lt;/PRE&gt; The script I use for building is (the script is still run under cygwin)&lt;BR /&gt;&lt;PRE&gt;[plain]@echo off

del mklproblem.obj
del mklproblem.exe

SET MKL=&lt;PATH-TO-MKL&gt;

echo "Compile"
cl -D_CRT_SECURE_NO_DEPRECATE -arch:SSE2 -MT -Zi -W3 -EHsc -Od -Zm500 -c mklproblem.c

echo "Link"
cl -D_CRT_SECURE_NO_DEPRECATE -Femklproblem.exe mklproblem.obj %MKL%mkl_intel_c.lib %MKL%mkl_sequential.lib %MKL%mkl_core.lib

echo "Run"
mklproblem.exe
[/plain]&lt;/PATH-TO-MKL&gt;&lt;/PRE&gt; I first thought that enabling the code controlled by WITH_DGEMM would make a difference but it does not. I get the same message from application verifier no matter whether I define WITH_DGEMM or not.&lt;BR /&gt;When I run the build script I get the following backtrace from application verifier&lt;BR /&gt;&lt;PRE&gt;[bash]&amp;gt;	ntdll.dll!7c81a251() 	
 	[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]	
 	vrfcore.dll!VerifierStopMessageEx(_AVRF_LAYER_DESCRIPTOR * LayerDescriptor=0x00396060, unsigned long StopCode=769, unsigned long Param1=4294967295, unsigned long Param2=43962, unsigned long Param3=0, unsigned long Param4=0, _AVRF_STOP_EXTRA * StopExtra=0x00000000, ...)  Line 551	C++
 	vfbasics.dll!CheckTlsIndex(unsigned long Index=4294967295)  Line 222 + 0x14 bytes	C
 	vfbasics.dll!AVrfpTlsGetValue(unsigned long dwTlsIndex=4294967295)  Line 417	C
 	mklproblem.exe!00401142() 	
 	vfbasics.dll!AVrfpTlsGetValue(unsigned long dwTlsIndex=4)  Line 437 + 0x5 bytes	C
 	mklproblem.exe!00401be2() 	
 	mklproblem.exe!004013c0() 	
 	vfbasics.dll!AVrfpStandardThreadFunction(void * Context=0x01cd3fe0)  Line 656 + 0x6 bytes	C
 	kernel32.dll!77e6482f() 	
[/bash]&lt;/PRE&gt; Like before, if I compile with -DNO_PROBLEM (and therefore do not invoke mkl_thread_free_buffers()) then I do not get any complaints from application verifier. Moreover, when I change the call to mkl_thread_free_buffers() to&lt;BR /&gt;&lt;PRE&gt;[cpp]int buffers = 0;
if ( mkl_mem_stat(&amp;amp;buffers) &amp;gt; 0 || buffers &amp;gt; 0 )
   mkl_thread_free_buffers();[/cpp]&lt;/PRE&gt; Then again everything is fine (again no matter whether I compile with -DWITH_DGEMM or not).&lt;BR /&gt;So I am pretty sure that the problem is somewhere inside mkl_thread_free_buffers().&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;BR /&gt;PS: Sorry for the messy way I in which I describe how to reproduce the problem. I am not too familiar with building stuff on Windows.</description>
      <pubDate>Tue, 10 May 2011 19:31:46 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829623#M5444</guid>
      <dc:creator>djunglas</dc:creator>
      <dc:date>2011-05-10T19:31:46Z</dc:date>
    </item>
    <item>
      <title>Is it safe to call mkl_thread_free_buffers() as first MKL funct</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829624#M5445</link>
      <description>Thank you Daniel for your detailed description. I reproduced the problem, working on it now.</description>
      <pubDate>Wed, 11 May 2011 11:47:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829624#M5445</guid>
      <dc:creator>Julia_S_Intel1</dc:creator>
      <dc:date>2011-05-11T11:47:56Z</dc:date>
    </item>
    <item>
      <title>Is it safe to call mkl_thread_free_buffers() as first MKL funct</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829625#M5446</link>
      <description>Daniel -the problem has been escalated. &lt;SPAN style="font-family: verdana, sans-serif;"&gt;Here is a bug tracking number for your reference&lt;SPAN style="font-family: Verdana, Arial, Helvetica, sans-serif; padding: 0px; margin: 0px;"&gt;#DPD200214530&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;DIV&gt;We will let you know when the fix would available.&lt;DIV&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 12 May 2011 13:04:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829625#M5446</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2011-05-12T13:04:59Z</dc:date>
    </item>
    <item>
      <title>Is it safe to call mkl_thread_free_buffers() as first MKL funct</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829626#M5447</link>
      <description>Thanks a lot.&lt;BR /&gt;What about the workaround I described: First test with mkl_mem_stat() whether there is anything to free and only then call mkl_thread_free_buffers()? Is this a valid workaround or was I just lucky?&lt;BR /&gt;</description>
      <pubDate>Fri, 13 May 2011 08:26:39 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829626#M5447</guid>
      <dc:creator>djunglas</dc:creator>
      <dc:date>2011-05-13T08:26:39Z</dc:date>
    </item>
    <item>
      <title>Is it safe to call mkl_thread_free_buffers() as first MKL funct</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829627#M5448</link>
      <description>&lt;P&gt;Thats the valid workaround. The problem rises only if you call mkl_thread_free_buffers() when theres no memory used by MKL to free.&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2011 16:18:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829627#M5448</guid>
      <dc:creator>Julia_S_Intel1</dc:creator>
      <dc:date>2011-05-13T16:18:15Z</dc:date>
    </item>
    <item>
      <title>Is it safe to call mkl_thread_free_buffers() as first MKL funct</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829628#M5449</link>
      <description>Hello Daniel,&lt;DIV&gt;&lt;SPAN style="font-family: Verdana, Arial, Helvetica, sans-serif;"&gt;Please check the fix of the problem you reported with the latest Update 5 ( Intel MKL v.10.3.5).&lt;BR /&gt;&lt;/SPAN&gt;&lt;DIV&gt;--Gennady&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 24 Aug 2011 14:10:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Is-it-safe-to-call-mkl-thread-free-buffers-as-first-MKL-function/m-p/829628#M5449</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2011-08-24T14:10:54Z</dc:date>
    </item>
  </channel>
</rss>

