<?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 Hi Keren, in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Multi-thread-MKL-cblas-sgemm-with-g-problem/m-p/1112493#M24451</link>
    <description>&lt;P&gt;Hi Keren,&lt;/P&gt;

&lt;P&gt;Thanks for raise the question here.&amp;nbsp;&amp;nbsp;&amp;nbsp; the problem looks be here.&lt;/P&gt;

&lt;P&gt;mkl_rt is Intel MKL Single Dynamic Library (SDL).&amp;nbsp;&amp;nbsp;&amp;nbsp; As mkl user guide explained : the&amp;nbsp; SDL enables you to select the interface and threading library for Intel MKL at run time. By default, linking&lt;BR /&gt;
	with SDL provides:&lt;BR /&gt;
	• Intel LP64 interface on systems based on the Intel® 64 architecture&lt;BR /&gt;
	• Intel interface on systems based on the IA-32 architecture&lt;BR /&gt;
	• Intel threading&lt;BR /&gt;
	To use other interfaces or change threading preferences, including use of the sequential version of Intel MKL,&lt;BR /&gt;
	you need to specify your choices using functions or environment variables as explained in section&lt;BR /&gt;
	Dynamically Selecting the Interface and Threading Layer.&lt;/P&gt;

&lt;P&gt;So if you compiler it with GNU G++ and GNU openmp threading,&amp;nbsp; Could you please try to&amp;nbsp; export :&lt;/P&gt;

&lt;P&gt;export MKL_INTERFACE_LAYER = GNU&lt;/P&gt;

&lt;P&gt;MKL_THREADING_LAYER = GNU&lt;/P&gt;

&lt;P&gt;then run your exe and see if it can get&amp;nbsp; expected result.&lt;/P&gt;

&lt;P&gt;Best Regards,&lt;BR /&gt;
	Ying&lt;/P&gt;

&lt;P&gt;Other related On-line article about&lt;/P&gt;

&lt;P&gt;&lt;A href="https://software.intel.com/en-us/articles/a-new-linking-model-single-dynamic-library-mkl_rt-since-intel-mkl-103/"&gt;https://software.intel.com/en-us/articles/a-new-linking-model-single-dynamic-library-mkl_rt-since-intel-mkl-103/&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Jul 2016 06:50:36 GMT</pubDate>
    <dc:creator>Ying_H_Intel</dc:creator>
    <dc:date>2016-07-05T06:50:36Z</dc:date>
    <item>
      <title>Multi-thread MKL cblas_sgemm with g++ problem</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Multi-thread-MKL-cblas-sgemm-with-g-problem/m-p/1112492#M24450</link>
      <description>&lt;P&gt;Here's an example of sgemm program.&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include &amp;lt;mkl.h&amp;gt;
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;cstdlib&amp;gt;
#define ITERATION 1

int main()
{
  int ra = 128;
  int lda = 75;
  int ldb = 55;
  float* left = (float*)calloc(ra * lda, sizeof(float));
  float* right = (float*)calloc(ldb * lda, sizeof(float));
  float* ans = (float*)calloc(ra * ldb, sizeof(float));
  std::cout &amp;lt;&amp;lt; "left " &amp;lt;&amp;lt; std::endl;
  for (int i = 0; i &amp;lt; ra; ++i) {
    for (int j = 0; j &amp;lt; lda; ++j) {
      left[i * lda + j] = static_cast &amp;lt;float&amp;gt; (rand()) / static_cast &amp;lt;float&amp;gt; (RAND_MAX);
      std::cout &amp;lt;&amp;lt; left[i * lda + j] &amp;lt;&amp;lt; " ";
    }
    std::cout &amp;lt;&amp;lt; std::endl;
  }

  std::cout &amp;lt;&amp;lt; "right " &amp;lt;&amp;lt; std::endl;
  for (int i = 0; i &amp;lt; lda; ++i) {
    for (int j = 0; j &amp;lt; ldb; ++j) {
      right[i * ldb + j] = static_cast &amp;lt;float&amp;gt; (rand()) / static_cast &amp;lt;float&amp;gt; (RAND_MAX);
      std::cout &amp;lt;&amp;lt; right[i * ldb + j] &amp;lt;&amp;lt; " ";
    }
    std::cout &amp;lt;&amp;lt; std::endl;
  }

  for (int i = 0; i &amp;lt; ITERATION; ++i) {
    cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, ra, ldb, lda, 1.0f, left, lda,
      right, ldb, 0.0f, ans, ldb);
  }

  std::cout &amp;lt;&amp;lt; "ans " &amp;lt;&amp;lt; std::endl;
  for (int i = 0; i &amp;lt; ra; ++i) {
    for (int j = 0; j &amp;lt; ldb; ++j) {
      std::cout &amp;lt;&amp;lt; ans[i * ldb + j] &amp;lt;&amp;lt; " ";
    }
    std::cout &amp;lt;&amp;lt; std::endl;
  }

  return 0;
}
&lt;/PRE&gt;

&lt;P&gt;I compile this program with g++ by options `-fopenmp -lmkl_rt`, where `OMP_NUM_THREADS` has been set to 16.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;After running the program, I figure out that the answer is exactly wrong comparing to the matlab result. I wouldn't say wrong if there's only few accuracy errors. Further, I observe that the program performs well under these conditions:&lt;/P&gt;

&lt;OL&gt;
	&lt;LI&gt;Use icc instead of g++,&lt;/LI&gt;
	&lt;LI&gt;Remove -fopenmp flag,&lt;/LI&gt;
	&lt;LI&gt;Use g++&amp;amp;atlas instead of icc&amp;amp;mkl&lt;/LI&gt;
	&lt;LI&gt;Set OMP_NUM_THREADS=1&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Therefore, I guess the problem may lay on the `-fopenmp` flag. Can you help me figure out the problem? Thank you!&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
	&lt;P&gt;g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-16)&lt;/P&gt;

	&lt;P&gt;icc (ICC) 16.0.3 20160415&lt;/P&gt;

	&lt;P&gt;Linux core&amp;nbsp;2.6.32-279.el6.x86_64&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 29 Jun 2016 12:47:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Multi-thread-MKL-cblas-sgemm-with-g-problem/m-p/1112492#M24450</guid>
      <dc:creator>Keren_Z_</dc:creator>
      <dc:date>2016-06-29T12:47:00Z</dc:date>
    </item>
    <item>
      <title>Hi Keren,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Multi-thread-MKL-cblas-sgemm-with-g-problem/m-p/1112493#M24451</link>
      <description>&lt;P&gt;Hi Keren,&lt;/P&gt;

&lt;P&gt;Thanks for raise the question here.&amp;nbsp;&amp;nbsp;&amp;nbsp; the problem looks be here.&lt;/P&gt;

&lt;P&gt;mkl_rt is Intel MKL Single Dynamic Library (SDL).&amp;nbsp;&amp;nbsp;&amp;nbsp; As mkl user guide explained : the&amp;nbsp; SDL enables you to select the interface and threading library for Intel MKL at run time. By default, linking&lt;BR /&gt;
	with SDL provides:&lt;BR /&gt;
	• Intel LP64 interface on systems based on the Intel® 64 architecture&lt;BR /&gt;
	• Intel interface on systems based on the IA-32 architecture&lt;BR /&gt;
	• Intel threading&lt;BR /&gt;
	To use other interfaces or change threading preferences, including use of the sequential version of Intel MKL,&lt;BR /&gt;
	you need to specify your choices using functions or environment variables as explained in section&lt;BR /&gt;
	Dynamically Selecting the Interface and Threading Layer.&lt;/P&gt;

&lt;P&gt;So if you compiler it with GNU G++ and GNU openmp threading,&amp;nbsp; Could you please try to&amp;nbsp; export :&lt;/P&gt;

&lt;P&gt;export MKL_INTERFACE_LAYER = GNU&lt;/P&gt;

&lt;P&gt;MKL_THREADING_LAYER = GNU&lt;/P&gt;

&lt;P&gt;then run your exe and see if it can get&amp;nbsp; expected result.&lt;/P&gt;

&lt;P&gt;Best Regards,&lt;BR /&gt;
	Ying&lt;/P&gt;

&lt;P&gt;Other related On-line article about&lt;/P&gt;

&lt;P&gt;&lt;A href="https://software.intel.com/en-us/articles/a-new-linking-model-single-dynamic-library-mkl_rt-since-intel-mkl-103/"&gt;https://software.intel.com/en-us/articles/a-new-linking-model-single-dynamic-library-mkl_rt-since-intel-mkl-103/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 06:50:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Multi-thread-MKL-cblas-sgemm-with-g-problem/m-p/1112493#M24451</guid>
      <dc:creator>Ying_H_Intel</dc:creator>
      <dc:date>2016-07-05T06:50:36Z</dc:date>
    </item>
    <item>
      <title>I tried to export MKL</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Multi-thread-MKL-cblas-sgemm-with-g-problem/m-p/1112494#M24452</link>
      <description>&lt;P&gt;I tried to export&amp;nbsp;&lt;SPAN style="font-size: 12px; line-height: 18px;"&gt;MKL_INTERFACE_LAYER=GNU, but it does not help.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;Alternatively, I choose to link `-lmkl_intel_lp64 -lmkl_core -lmkl_gnu_thread -lpthread -ldl` instead of the single dynamic library, and it turns out that problems are solve by doing this.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 08:45:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Multi-thread-MKL-cblas-sgemm-with-g-problem/m-p/1112494#M24452</guid>
      <dc:creator>Keren_Z_</dc:creator>
      <dc:date>2016-07-05T08:45:33Z</dc:date>
    </item>
    <item>
      <title>Hi Keren, </title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Multi-thread-MKL-cblas-sgemm-with-g-problem/m-p/1112495#M24453</link>
      <description>&lt;P&gt;Hi Keren,&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Glad you try them out.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Just add comments so other may understand&amp;nbsp;&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Export MKL_INTERFACE_LAYER = GNU + &amp;nbsp;export&amp;nbsp;&lt;SPAN style="line-height: 1.5;"&gt;MKL_THREADING_LAYER = GNU&lt;/SPAN&gt;&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;&lt;SPAN style="font-size: 12px; line-height: 18px;"&gt;-lmkl_intel_lp64 &amp;nbsp;-lmkl_gnu_thread -lmkl_core&amp;nbsp;-lpthread -ldl&lt;/SPAN&gt;&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Best Regards,&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Ying&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2016 04:29:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Multi-thread-MKL-cblas-sgemm-with-g-problem/m-p/1112495#M24453</guid>
      <dc:creator>Ying_H_Intel</dc:creator>
      <dc:date>2016-07-25T04:29:30Z</dc:date>
    </item>
  </channel>
</rss>

