<?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 Avoiding unnecessary OpenMP synchronization in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Avoiding-unnecessary-OpenMP-synchronization/m-p/928810#M13574</link>
    <description>&lt;P&gt;Say I wish to add a number of vectors:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;cblas_daxpy(n, 1.0, a, 1, b, 1);&lt;/P&gt;
&lt;P&gt;cblas_daxpy(n, 1.2, c, 1, d, 1);&lt;/P&gt;
&lt;P&gt;cblas_daxpy(n, 1.4, e, 1, f, 1);&lt;/P&gt;
&lt;P&gt;cblas_daxpy(n, 1.6, g, 1, h, 1);&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;MKL will use OpenMP to parallelize each of these vector additions internally. However all of the OpenMP threads will sync up between each daxpy call, adding overhead. Since I know that the functions are independent of each other, this synchronization is unnecessary.&lt;/P&gt;
&lt;P&gt;I could do&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;#pragma omp parallel sections&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;#pragma omp section&lt;/P&gt;
&lt;P&gt;cblas_daxpy(n, 1.0, a, 1, b, 1);&lt;/P&gt;
&lt;P&gt;#pragma omp section&lt;/P&gt;
&lt;P&gt;cblas_daxpy(n, 1.2, c, 1, d, 1);&lt;/P&gt;
&lt;P&gt;#pragma omp section&lt;/P&gt;
&lt;P&gt;cblas_daxpy(n, 1.4, e, 1, f, 1);&lt;/P&gt;
&lt;P&gt;#pragma omp section&lt;/P&gt;
&lt;P&gt;cblas_daxpy(n, 1.6, g, 1, h, 1);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;which will parallelize the functions externally, but then I might not use all of my cores, and I won't be able to take advantage of any work balancing if the vectors weren't all the same size, for example.&lt;/P&gt;
&lt;P&gt;What's the recommended way to achieve maximum performance for code like this? Is the best practise the same on Phi?&lt;/P&gt;</description>
    <pubDate>Fri, 13 Sep 2013 20:47:12 GMT</pubDate>
    <dc:creator>Peter_B_9</dc:creator>
    <dc:date>2013-09-13T20:47:12Z</dc:date>
    <item>
      <title>Avoiding unnecessary OpenMP synchronization</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Avoiding-unnecessary-OpenMP-synchronization/m-p/928810#M13574</link>
      <description>&lt;P&gt;Say I wish to add a number of vectors:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;cblas_daxpy(n, 1.0, a, 1, b, 1);&lt;/P&gt;
&lt;P&gt;cblas_daxpy(n, 1.2, c, 1, d, 1);&lt;/P&gt;
&lt;P&gt;cblas_daxpy(n, 1.4, e, 1, f, 1);&lt;/P&gt;
&lt;P&gt;cblas_daxpy(n, 1.6, g, 1, h, 1);&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;MKL will use OpenMP to parallelize each of these vector additions internally. However all of the OpenMP threads will sync up between each daxpy call, adding overhead. Since I know that the functions are independent of each other, this synchronization is unnecessary.&lt;/P&gt;
&lt;P&gt;I could do&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;#pragma omp parallel sections&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;#pragma omp section&lt;/P&gt;
&lt;P&gt;cblas_daxpy(n, 1.0, a, 1, b, 1);&lt;/P&gt;
&lt;P&gt;#pragma omp section&lt;/P&gt;
&lt;P&gt;cblas_daxpy(n, 1.2, c, 1, d, 1);&lt;/P&gt;
&lt;P&gt;#pragma omp section&lt;/P&gt;
&lt;P&gt;cblas_daxpy(n, 1.4, e, 1, f, 1);&lt;/P&gt;
&lt;P&gt;#pragma omp section&lt;/P&gt;
&lt;P&gt;cblas_daxpy(n, 1.6, g, 1, h, 1);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;which will parallelize the functions externally, but then I might not use all of my cores, and I won't be able to take advantage of any work balancing if the vectors weren't all the same size, for example.&lt;/P&gt;
&lt;P&gt;What's the recommended way to achieve maximum performance for code like this? Is the best practise the same on Phi?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2013 20:47:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Avoiding-unnecessary-OpenMP-synchronization/m-p/928810#M13574</guid>
      <dc:creator>Peter_B_9</dc:creator>
      <dc:date>2013-09-13T20:47:12Z</dc:date>
    </item>
    <item>
      <title>I would suppose your expected</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Avoiding-unnecessary-OpenMP-synchronization/m-p/928811#M13575</link>
      <description>&lt;P&gt;I would suppose your expected gain by running multiple MKL calls in parallel depends on n being small enough that your platform performance doesn't scale linearly to all cores when running them individually.&amp;nbsp; Then you would want to divide your cores among the MKL instances and pin each instance to its own group of cores.&amp;nbsp; This may be easier to accomplish by MPI than by nested OpenMP parallel.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That can be a fairly effective scheme for MIC.&amp;nbsp; Note that daxpy isn't among the MKL functions set up for automatic offload, as it's unlikely you could overcome the burden of copying the data between MIC and host.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2013 19:59:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Avoiding-unnecessary-OpenMP-synchronization/m-p/928811#M13575</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2013-09-17T19:59:35Z</dc:date>
    </item>
  </channel>
</rss>

