Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Pierpaolo_M_
New Contributor I
78 Views

Are VSL Routines ThreadSafe?

Jump to solution

Hi,

I have written a simple code to generate Random Numbers using VSL Routines. It is an OpenMP code written in Fortran:

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

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:

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 
  >24    errcode=vdRngGaussian(method, stream(k), n, r, a, sigma )
   25    
   26  !!$OMP END CRITICAL

  Stack (1 of 1 instance(s))
  >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 
  >24    errcode=vdRngGaussian(method, stream(k), n, r, a, sigma )
   25    
   26  !!$OMP END CRITICAL

  Stack (1 of 1 instance(s))
  >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



I compile this program in this way:

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

The only way to overcome this is if i use $OMP CRITICAL when i call vdRngGaussian

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?

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.

Thanks in advance

Pierpaolo

0 Kudos

Accepted Solutions
78 Views

Hi Pierpaolo,
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.

Best regards,
Vlad V.

 

 

View solution in original post

2 Replies
79 Views

Hi Pierpaolo,
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.

Best regards,
Vlad V.

 

 

View solution in original post

Pierpaolo_M_
New Contributor I
78 Views

Hi Vlad,

Thanks for your reply.

Best regards,

Pierpaolo

Reply