<?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 Must be a programming error in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-the-trigonometric-transforms-thread-safe/m-p/974975#M17015</link>
    <description>&lt;P&gt;&lt;BR /&gt;
	Must be a programming error on my part then.&lt;/P&gt;

&lt;P&gt;My sequence of MKL calls is made by calling the following function.&lt;/P&gt;

&lt;P&gt;void dct1(double * data, MKL_INT num_cols, int direction) {&lt;/P&gt;

&lt;P&gt;DFTI_DESCRIPTOR_HANDLE handle;&lt;BR /&gt;
	MKL_INT stat = 0;&lt;BR /&gt;
	MKL_INT ipar[128];&lt;/P&gt;

&lt;P&gt;double * par = new double[(3*num_cols/2) + 2]();&lt;/P&gt;

&lt;P&gt;// use function pointers to handle whether float is a float or double&lt;/P&gt;

&lt;P&gt;// and direction of the transform&lt;/P&gt;

&lt;P&gt;void (*d_trig_transform)(double *, DFTI_DESCRIPTOR_HANDLE *, MKL_INT *, double *, MKL_INT *);&lt;/P&gt;

&lt;P&gt;if(direction &amp;lt; 0)&lt;BR /&gt;
	d_trig_transform = d_forward_trig_transform;&lt;BR /&gt;
	else&lt;BR /&gt;
	d_trig_transform = d_backward_trig_transform;&lt;/P&gt;

&lt;P&gt;MKL_INT tt_type = MKL_STAGGERED_COSINE_TRANSFORM;&lt;/P&gt;

&lt;P&gt;d_init_trig_transform(&amp;amp;num_cols, &amp;amp;tt_type, ipar, par, &amp;amp;stat);&lt;/P&gt;

&lt;P&gt;if(stat != 0){&lt;BR /&gt;
	cerr &amp;lt;&amp;lt; "Error initializing row transform: " &amp;lt;&amp;lt; stat &amp;lt;&amp;lt; endl;&lt;BR /&gt;
	return;&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;d_commit_trig_transform(data, &amp;amp;handle, ipar, par, &amp;amp;stat);&lt;BR /&gt;
	if(stat != 0){&lt;BR /&gt;
	cerr &amp;lt;&amp;lt; "Error committing row transform: " &amp;lt;&amp;lt; stat &amp;lt;&amp;lt; endl;&lt;BR /&gt;
	return;&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;d_trig_transform(data, &amp;amp;handle, ipar, par, &amp;amp;stat);&lt;BR /&gt;
	if(stat != 0){&lt;BR /&gt;
	cerr &amp;lt;&amp;lt; "Error in row transform: " &amp;lt;&amp;lt; stat &amp;lt;&amp;lt; endl;&lt;BR /&gt;
	return;&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;free_trig_transform(&amp;amp;handle, ipar, &amp;amp;stat);&lt;BR /&gt;
	if(stat != 0){&lt;BR /&gt;
	cerr &amp;lt;&amp;lt; "Error freeing row transform: " &amp;lt;&amp;lt; stat &amp;lt;&amp;lt; endl;&lt;BR /&gt;
	return;&lt;/P&gt;

&lt;P&gt;}&lt;BR /&gt;
	　delete[] par;&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Each OpenMP thread calls it like this, Q is the size of the data&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	double * temp = new double[Q+1]();&lt;/P&gt;

&lt;P&gt;for(int n1 = 0; n1 &amp;lt; Q; ++n1){&lt;BR /&gt;
	temp[n1]=transdata[n1]*2.0/((double)Q);&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;dct1(temp, Q, 1);&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;I'm using MKL 11.1&amp;nbsp; Update 1 on Windows 7 64-bit installed with C++ 2013.1.1.139, compiling under 64 bit mode on an Intel Core i7 laptop.&lt;/P&gt;

&lt;P&gt;If I use more than one OpenMP thread, then the program behaves unpredictably. Sometimes it runs, often fails around calling the trig transform, as far as I can tell a heap corruption error occurs.&lt;/P&gt;

&lt;P&gt;If I surround the call as follows, it runs OK.&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; #pragma omp critical (DCT)&lt;BR /&gt;
	{&lt;BR /&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; dct1(temp, Q, 1);&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	If I substitute a different DCT function, for example if I call the DCT from the code at &lt;A href="http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html"&gt;http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html&lt;/A&gt;, and call it in the same manner, then my program runs fine with multiple openMP threads.&lt;/P&gt;

&lt;P&gt;Note that I'm trying to get each thread to run it's own single-threaded DCT on it's own data, not run a DCT in parallel on one set of data.&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 03 Feb 2014 10:53:00 GMT</pubDate>
    <dc:creator>Rodney_H_</dc:creator>
    <dc:date>2014-02-03T10:53:00Z</dc:date>
    <item>
      <title>Are the trigonometric transforms thread-safe?</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-the-trigonometric-transforms-thread-safe/m-p/974973#M17013</link>
      <description>&lt;P&gt;I'm using the trig transforms (MKL_STAGGERED_COSINE_TRANSFORM) within an OpenMP parallel region on Windows.&lt;/P&gt;

&lt;P&gt;Each OpenMP thread has it's own array of data to be transformed.&lt;/P&gt;

&lt;P&gt;When I use one OpenMP thread my program works perfectly. When I use more than one, results are unpredictable.&lt;/P&gt;

&lt;P&gt;If I enclose the trig transform code within a #pragma omp critical{} it's OK.&lt;/P&gt;

&lt;P&gt;It seems to me that the trigonometric transforms are not thread-safe. Results are similar with sequential and parallel MKL libraries.&lt;/P&gt;

&lt;P&gt;My code is a bit too complex to post it all here.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Rodney&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Feb 2014 07:25:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-the-trigonometric-transforms-thread-safe/m-p/974973#M17013</guid>
      <dc:creator>Rodney_H_</dc:creator>
      <dc:date>2014-02-03T07:25:40Z</dc:date>
    </item>
    <item>
      <title>Dear Rodney H.,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-the-trigonometric-transforms-thread-safe/m-p/974974#M17014</link>
      <description>&lt;P&gt;Dear Rodney H.,&lt;/P&gt;

&lt;P&gt;Trigonometric transforms are thread-safe. Please let us know which version of MKL you are using and the sequence of MKL calls related to trigonometric transforms.&lt;/P&gt;

&lt;P&gt;Thank you.&lt;/P&gt;

&lt;P&gt;Evgueni.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Feb 2014 08:56:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-the-trigonometric-transforms-thread-safe/m-p/974974#M17014</guid>
      <dc:creator>Evgueni_P_Intel</dc:creator>
      <dc:date>2014-02-03T08:56:00Z</dc:date>
    </item>
    <item>
      <title>Must be a programming error</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-the-trigonometric-transforms-thread-safe/m-p/974975#M17015</link>
      <description>&lt;P&gt;&lt;BR /&gt;
	Must be a programming error on my part then.&lt;/P&gt;

&lt;P&gt;My sequence of MKL calls is made by calling the following function.&lt;/P&gt;

&lt;P&gt;void dct1(double * data, MKL_INT num_cols, int direction) {&lt;/P&gt;

&lt;P&gt;DFTI_DESCRIPTOR_HANDLE handle;&lt;BR /&gt;
	MKL_INT stat = 0;&lt;BR /&gt;
	MKL_INT ipar[128];&lt;/P&gt;

&lt;P&gt;double * par = new double[(3*num_cols/2) + 2]();&lt;/P&gt;

&lt;P&gt;// use function pointers to handle whether float is a float or double&lt;/P&gt;

&lt;P&gt;// and direction of the transform&lt;/P&gt;

&lt;P&gt;void (*d_trig_transform)(double *, DFTI_DESCRIPTOR_HANDLE *, MKL_INT *, double *, MKL_INT *);&lt;/P&gt;

&lt;P&gt;if(direction &amp;lt; 0)&lt;BR /&gt;
	d_trig_transform = d_forward_trig_transform;&lt;BR /&gt;
	else&lt;BR /&gt;
	d_trig_transform = d_backward_trig_transform;&lt;/P&gt;

&lt;P&gt;MKL_INT tt_type = MKL_STAGGERED_COSINE_TRANSFORM;&lt;/P&gt;

&lt;P&gt;d_init_trig_transform(&amp;amp;num_cols, &amp;amp;tt_type, ipar, par, &amp;amp;stat);&lt;/P&gt;

&lt;P&gt;if(stat != 0){&lt;BR /&gt;
	cerr &amp;lt;&amp;lt; "Error initializing row transform: " &amp;lt;&amp;lt; stat &amp;lt;&amp;lt; endl;&lt;BR /&gt;
	return;&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;d_commit_trig_transform(data, &amp;amp;handle, ipar, par, &amp;amp;stat);&lt;BR /&gt;
	if(stat != 0){&lt;BR /&gt;
	cerr &amp;lt;&amp;lt; "Error committing row transform: " &amp;lt;&amp;lt; stat &amp;lt;&amp;lt; endl;&lt;BR /&gt;
	return;&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;d_trig_transform(data, &amp;amp;handle, ipar, par, &amp;amp;stat);&lt;BR /&gt;
	if(stat != 0){&lt;BR /&gt;
	cerr &amp;lt;&amp;lt; "Error in row transform: " &amp;lt;&amp;lt; stat &amp;lt;&amp;lt; endl;&lt;BR /&gt;
	return;&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;free_trig_transform(&amp;amp;handle, ipar, &amp;amp;stat);&lt;BR /&gt;
	if(stat != 0){&lt;BR /&gt;
	cerr &amp;lt;&amp;lt; "Error freeing row transform: " &amp;lt;&amp;lt; stat &amp;lt;&amp;lt; endl;&lt;BR /&gt;
	return;&lt;/P&gt;

&lt;P&gt;}&lt;BR /&gt;
	　delete[] par;&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Each OpenMP thread calls it like this, Q is the size of the data&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	double * temp = new double[Q+1]();&lt;/P&gt;

&lt;P&gt;for(int n1 = 0; n1 &amp;lt; Q; ++n1){&lt;BR /&gt;
	temp[n1]=transdata[n1]*2.0/((double)Q);&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;dct1(temp, Q, 1);&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;I'm using MKL 11.1&amp;nbsp; Update 1 on Windows 7 64-bit installed with C++ 2013.1.1.139, compiling under 64 bit mode on an Intel Core i7 laptop.&lt;/P&gt;

&lt;P&gt;If I use more than one OpenMP thread, then the program behaves unpredictably. Sometimes it runs, often fails around calling the trig transform, as far as I can tell a heap corruption error occurs.&lt;/P&gt;

&lt;P&gt;If I surround the call as follows, it runs OK.&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; #pragma omp critical (DCT)&lt;BR /&gt;
	{&lt;BR /&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; dct1(temp, Q, 1);&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	If I substitute a different DCT function, for example if I call the DCT from the code at &lt;A href="http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html"&gt;http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html&lt;/A&gt;, and call it in the same manner, then my program runs fine with multiple openMP threads.&lt;/P&gt;

&lt;P&gt;Note that I'm trying to get each thread to run it's own single-threaded DCT on it's own data, not run a DCT in parallel on one set of data.&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Feb 2014 10:53:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-the-trigonometric-transforms-thread-safe/m-p/974975#M17015</guid>
      <dc:creator>Rodney_H_</dc:creator>
      <dc:date>2014-02-03T10:53:00Z</dc:date>
    </item>
    <item>
      <title>Dear Rodney H.,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-the-trigonometric-transforms-thread-safe/m-p/974976#M17016</link>
      <description>&lt;P&gt;Dear Rodney H.,&lt;/P&gt;

&lt;P&gt;Please check MKL documentation -- par should be (5*num_cols/2) + 2 elements long (you allocate only (3*num_cols/2) + 2 elements.)&lt;/P&gt;

&lt;P&gt;Thank you,&lt;/P&gt;

&lt;P&gt;Evgueni.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2014 04:52:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-the-trigonometric-transforms-thread-safe/m-p/974976#M17016</guid>
      <dc:creator>Evgueni_P_Intel</dc:creator>
      <dc:date>2014-02-05T04:52:44Z</dc:date>
    </item>
    <item>
      <title>Dear Evgueni,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-the-trigonometric-transforms-thread-safe/m-p/974977#M17017</link>
      <description>&lt;P&gt;Dear Evgueni,&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;I don't think it makes much difference. From MKL documentation: "If &lt;SPAN class="parmname"&gt;tt_type&lt;/SPAN&gt;=&lt;SPAN style="font-style: normal;"&gt;MKL_STAGGERED_COSINE_TRANSFORM&lt;/SPAN&gt;, the transform uses only the first 3&lt;SPAN class="parmname"&gt;n&lt;/SPAN&gt;/2 elements, which contain tabulated sine and cosine values. "&lt;/P&gt;

&lt;P&gt;I tried your suggestion and still get heap corruption problems when calling from multiple threads.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Rodney&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2014 07:48:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-the-trigonometric-transforms-thread-safe/m-p/974977#M17017</guid>
      <dc:creator>Rodney_H_</dc:creator>
      <dc:date>2014-02-05T07:48:20Z</dc:date>
    </item>
    <item>
      <title>Hi, Rodney,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-the-trigonometric-transforms-thread-safe/m-p/974978#M17018</link>
      <description>&lt;P&gt;Hi, Rodney,&lt;/P&gt;

&lt;P&gt;I want to know if you have solved the problem, because I have met exactly the same issue, and suspect that the TT in Intel MKL is not thread-safe.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Can any maester&amp;nbsp;from Intel help look at the problem? At least, what are the appropriate options should we set to make TT thread-safe when used with OpenMP?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jul 2018 05:51:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-the-trigonometric-transforms-thread-safe/m-p/974978#M17018</guid>
      <dc:creator>Kai1</dc:creator>
      <dc:date>2018-07-03T05:51:35Z</dc:date>
    </item>
    <item>
      <title>and below is my TT routines:</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-the-trigonometric-transforms-thread-safe/m-p/974979#M17019</link>
      <description>&lt;P&gt;and below is my TT routines:&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;DIV&gt;
	&lt;PRE class="brush:fortran;"&gt;        call s_init_trig_transform(m, transform_type, ipar, spar, dct_status)
        call s_commit_trig_transform(w, handle, ipar, spar, dct_status)
        call s_backward_trig_transform(w, handle, ipar, spar, dct_status)
        call free_trig_transform(handle, ipar, dct_status)&lt;/PRE&gt;
&lt;/DIV&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;where m = size(w), w is a 1D real array, spar has length&amp;nbsp;nint(3*m/2.0). trasnform_type = mkl_staggered_cosine_transform.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jul 2018 05:55:18 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-the-trigonometric-transforms-thread-safe/m-p/974979#M17019</guid>
      <dc:creator>Kai1</dc:creator>
      <dc:date>2018-07-03T05:55:18Z</dc:date>
    </item>
    <item>
      <title>that's not enough to</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-the-trigonometric-transforms-thread-safe/m-p/974980#M17020</link>
      <description>&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;that's not enough to reproduce the issue. You may submit the issue to&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://supporttickets.intel.com/?lang=en-US" style="font-size: 12px;"&gt;https://supporttickets.intel.com/?lang=en-US&lt;/A&gt;&lt;SPAN style="font-size: 1em;"&gt;&amp;nbsp; and&amp;nbsp; provide us the reproducer of the problem.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jul 2018 04:50:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-the-trigonometric-transforms-thread-safe/m-p/974980#M17020</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2018-07-04T04:50:52Z</dc:date>
    </item>
  </channel>
</rss>

