<?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 Vlad, in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-VSL-Routines-ThreadSafe/m-p/1073378#M22405</link>
    <description>&lt;P&gt;Hi Vlad,&lt;/P&gt;

&lt;P&gt;Thanks for your reply.&lt;/P&gt;

&lt;P&gt;Best regards,&lt;/P&gt;

&lt;P&gt;Pierpaolo&lt;/P&gt;</description>
    <pubDate>Thu, 28 Jul 2016 14:29:59 GMT</pubDate>
    <dc:creator>Pierpaolo_M_</dc:creator>
    <dc:date>2016-07-28T14:29:59Z</dc:date>
    <item>
      <title>Are VSL Routines ThreadSafe?</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-VSL-Routines-ThreadSafe/m-p/1073376#M22403</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have written a simple code to generate Random Numbers using VSL Routines. It is an OpenMP code written in Fortran:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;INCLUDE "mkl_vsl.f90"
program vsl_ex
use omp_lib
use mkl_vsl_type
use mkl_vsl
implicit none
integer :: k,errcode
integer, parameter :: nvp=48, n=10, brng=VSL_BRNG_MT2203
integer, parameter :: method=VSL_RNG_METHOD_GAUSSIAN_ICDF
TYPE (VSL_STREAM_STATE),DIMENSION(nvp) :: stream
double precision,dimension(n), save :: r
double precision, parameter :: a=0.0, sigma=1.0
!$OMP THREADPRIVATE (r)

CALL MKL_SET_NUM_THREADS(nvp)
DO k=1,nvp
  errcode=vslNewStream(stream(k),brng+k-1,777)
END DO

!$OMP PARALLEL DO PRIVATE(k,errcode) SHARED(stream)
DO k=1,nvp
!  errcode=k
!!$OMP CRITICAL 
  errcode=vdRngGaussian(method, stream(k), n, r, a, sigma )
  
!!$OMP END CRITICAL
END DO
!$OMP END PARALLEL DO

END program vsl_ex&lt;/PRE&gt;

&lt;P&gt;When i run it i receive exit code equal to zero, so it seems that everything is fine, but when i use Intel Inspector i receive a race condition:&lt;/P&gt;

&lt;PRE class="brush:plain;"&gt;P1: Error: Data race: New
 P1.27: Error: Data race: New
  /home/pierpaolo/PIC/NIS/Hybrid/DOUBLEINT/PROVA/pluto.f90(24): Error X54: Write: Function MAIN__$omp$parallel_for@20: Module /home/pierpaolo/PIC/NIS/Hybrid/DOUBLEINT/PROVA/pluto
  Code snippet:
   22  !  errcode=k
   23  !!$OMP CRITICAL 
  &amp;gt;24    errcode=vdRngGaussian(method, stream(k), n, r, a, sigma )
   25    
   26  !!$OMP END CRITICAL

  Stack (1 of 1 instance(s))
  &amp;gt;libmkl_intel_lp64.so!vdrnggaussian_ - /opt/intel/composer_xe_2015.2.164/mkl/lib/intel64/libmkl_intel_lp64.so:0x5432c6
   pluto!MAIN__$omp$parallel_for@20 - /home/pierpaolo/PIC/NIS/Hybrid/DOUBLEINT/PROVA/pluto.f90:24
   pluto!vsl_ex - /home/pierpaolo/PIC/NIS/Hybrid/DOUBLEINT/PROVA/pluto.f90:20
   pluto!main - /home/pierpaolo/PIC/NIS/Hybrid/DOUBLEINT/PROVA/pluto:0xca9
   pluto!_start - /home/pierpaolo/PIC/NIS/Hybrid/DOUBLEINT/PROVA/pluto:0xbb4

  /home/pierpaolo/PIC/NIS/Hybrid/DOUBLEINT/PROVA/pluto.f90(24): Error X55: Read: Function MAIN__$omp$parallel_for@20: Module /home/pierpaolo/PIC/NIS/Hybrid/DOUBLEINT/PROVA/pluto
  Code snippet:
   22  !  errcode=k
   23  !!$OMP CRITICAL 
  &amp;gt;24    errcode=vdRngGaussian(method, stream(k), n, r, a, sigma )
   25    
   26  !!$OMP END CRITICAL

  Stack (1 of 1 instance(s))
  &amp;gt;libmkl_intel_lp64.so!vdrnggaussian_ - /opt/intel/composer_xe_2015.2.164/mkl/lib/intel64/libmkl_intel_lp64.so:0x54327b
   pluto!MAIN__$omp$parallel_for@20 - /home/pierpaolo/PIC/NIS/Hybrid/DOUBLEINT/PROVA/pluto.f90:24



&lt;/PRE&gt;

&lt;P&gt;I compile this program in this way:&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-variant-ligatures: no-common-ligatures"&gt;ifort -O0 -g -debug inline-debug-info -mcmodel medium -shared-intel -qopenmp -I/opt/intel/composer_xe_2015.2.164/mkl/include -o pluto pluto.f90 -L/opt/intel/composer_xe_2015.2.164/mkl/lib/intel64 -lmkl_intel_lp64 -lmkl_core -lmkl_intel_thread -lpthread -lm -ldl&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;The only way to overcome this is if i use $OMP CRITICAL when i call vdRngGaussian&lt;/P&gt;

&lt;P&gt;Is there a problem in my code or is it normal that i have to use CRITICAL directive to avoid race condition as Intel Inspector says?&lt;/P&gt;

&lt;P&gt;If i understood well, VSL routines are thredsafe, so why am i seeing a data race when different threads call a VSL routine? I have tried also other distributions with same results.&lt;/P&gt;

&lt;P&gt;Thanks in advance&lt;/P&gt;

&lt;P&gt;Pierpaolo&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2016 09:40:42 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-VSL-Routines-ThreadSafe/m-p/1073376#M22403</guid>
      <dc:creator>Pierpaolo_M_</dc:creator>
      <dc:date>2016-07-27T09:40:42Z</dc:date>
    </item>
    <item>
      <title>Hi Pierpaolo,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-VSL-Routines-ThreadSafe/m-p/1073377#M22404</link>
      <description>&lt;P&gt;&lt;SPAN lang="EN-US" style="color: rgb(31, 73, 125); font-family: &amp;quot;Calibri&amp;quot;,sans-serif; font-size: 11pt; mso-ansi-language: EN-US; mso-fareast-language: EN-US;"&gt;Hi Pierpaolo,&lt;/SPAN&gt;&lt;BR /&gt;
	&lt;SPAN lang="EN-US" style="color: rgb(31, 73, 125); font-family: &amp;quot;Calibri&amp;quot;,sans-serif; font-size: 11pt; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA;"&gt;Your code is fine and there is no need to add $OMP CRITICAL. These reports are known false positives when profiling MKL applications with Inspector.&lt;BR /&gt;
	&lt;BR /&gt;
	Best regards,&lt;BR /&gt;
	Vlad V.&lt;/SPAN&gt;&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 07:55:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-VSL-Routines-ThreadSafe/m-p/1073377#M22404</guid>
      <dc:creator>Vladislav_V_Intel</dc:creator>
      <dc:date>2016-07-28T07:55:51Z</dc:date>
    </item>
    <item>
      <title>Hi Vlad,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-VSL-Routines-ThreadSafe/m-p/1073378#M22405</link>
      <description>&lt;P&gt;Hi Vlad,&lt;/P&gt;

&lt;P&gt;Thanks for your reply.&lt;/P&gt;

&lt;P&gt;Best regards,&lt;/P&gt;

&lt;P&gt;Pierpaolo&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 14:29:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Are-VSL-Routines-ThreadSafe/m-p/1073378#M22405</guid>
      <dc:creator>Pierpaolo_M_</dc:creator>
      <dc:date>2016-07-28T14:29:59Z</dc:date>
    </item>
  </channel>
</rss>

