<?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 You would compile your in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/Problem-using-MKL-random-number-generation-in-offloaded-code/m-p/940659#M16971</link>
    <description>&lt;P&gt;You would compile your example as follows:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;ifort -offload-attribute-target=mic -openmp -mkl example.f90&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;This decorates the subprogram definitions within the mkl_vsl.f90 include.&lt;/P&gt;

&lt;P&gt;I'm not 100% certain about the correctness of calling the MKL routines within the OpenMP region. At least &lt;STRONG&gt;stream, seed,&amp;nbsp;&lt;/STRONG&gt;and &lt;STRONG&gt;r &lt;/STRONG&gt;appear to need to be private and then the example at least compiles and executes. I’ll contact someone more knowledgeable about MKL to assist with using the MKL routines w/OpenMP.&lt;/P&gt;</description>
    <pubDate>Wed, 18 Dec 2013 11:52:00 GMT</pubDate>
    <dc:creator>Kevin_D_Intel</dc:creator>
    <dc:date>2013-12-18T11:52:00Z</dc:date>
    <item>
      <title>Problem using MKL random number generation in offloaded code</title>
      <link>https://community.intel.com/t5/Software-Archive/Problem-using-MKL-random-number-generation-in-offloaded-code/m-p/940658#M16970</link>
      <description>&lt;P&gt;I am trying to create a separate random number generator for each thread in a parallel section of code.&lt;/P&gt;

&lt;P&gt;.The following is a simple toy example of what is desired. However it does not work.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; include 'mkl_vsl.f90'&lt;BR /&gt;
	&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; program uniform&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; USE MKL_VSL_TYPE&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; USE MKL_VSL&lt;BR /&gt;
	&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real(kind=4) r(1000)&amp;nbsp; ! buffer for random numbers&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real(kind=4) a, b&lt;BR /&gt;
	&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TYPE (VSL_STREAM_STATE) :: stream&lt;BR /&gt;
	&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(kind=4) errcode&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(kind=4) i,tid&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer brng,method,seed,n&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n = 1000&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a = 0.0&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b = 1.0&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brng=VSL_BRNG_MT19937&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; method=VSL_RNG_METHOD_UNIFORM_STD&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; !dir$ attributes offload:mic :: omp_get_thread_num,errcode&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; !dir$ omp offload target(mic)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; !$omp parallel private(errcode,tid,n,i)&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tid = omp_get_thread_num()&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; seed=777 * tid&lt;BR /&gt;
	&amp;nbsp;&lt;BR /&gt;
	!&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ***** Initializing *****&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; errcode=vslnewstream(stream, brng, seed)&lt;BR /&gt;
	&amp;nbsp;&lt;BR /&gt;
	!&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ***** Generating *****&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; errcode=vsrnguniform( method, stream, n, r, a, b )&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1,10&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; print *, tid, r(i)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end do&lt;BR /&gt;
	&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&lt;BR /&gt;
	!&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ***** Deinitialize *****&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; errcode=vsldeletestream( stream )&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; !$omp end parallel&lt;BR /&gt;
	&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;These errors are reported by the compliler&lt;/P&gt;

&lt;P&gt;Error&amp;nbsp;&amp;nbsp; &amp;nbsp;1&amp;nbsp;&amp;nbsp; &amp;nbsp; error #8535: A procedure called in an OFFLOAD region must have the OFFLOAD:TARGET attribute.&amp;nbsp;&amp;nbsp; [VSLNEWSTREAM]&amp;nbsp;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Error&amp;nbsp;&amp;nbsp; &amp;nbsp;2&amp;nbsp;&amp;nbsp; &amp;nbsp; error #8535: A procedure called in an OFFLOAD region must have the OFFLOAD:TARGET attribute.&amp;nbsp;&amp;nbsp; [VSRNGUNIFORM]&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Error&amp;nbsp;&amp;nbsp; &amp;nbsp;3&amp;nbsp;&amp;nbsp; &amp;nbsp; error #8535: A procedure called in an OFFLOAD region must have the OFFLOAD:TARGET attribute.&amp;nbsp;&amp;nbsp; [VSLDELETESTREAM]&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;However I can not find a way to set the offload target attribute for these functions.&lt;BR /&gt;
	.Presumably this would need to be done in the associated module(s), but I do not have access to their source.&lt;/P&gt;

&lt;P&gt;Any ideas on how to accomplish this?&lt;/P&gt;

&lt;P&gt;Thanks, Dean&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>Tue, 17 Dec 2013 22:50:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Problem-using-MKL-random-number-generation-in-offloaded-code/m-p/940658#M16970</guid>
      <dc:creator>Dean_B_</dc:creator>
      <dc:date>2013-12-17T22:50:37Z</dc:date>
    </item>
    <item>
      <title>You would compile your</title>
      <link>https://community.intel.com/t5/Software-Archive/Problem-using-MKL-random-number-generation-in-offloaded-code/m-p/940659#M16971</link>
      <description>&lt;P&gt;You would compile your example as follows:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;ifort -offload-attribute-target=mic -openmp -mkl example.f90&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;This decorates the subprogram definitions within the mkl_vsl.f90 include.&lt;/P&gt;

&lt;P&gt;I'm not 100% certain about the correctness of calling the MKL routines within the OpenMP region. At least &lt;STRONG&gt;stream, seed,&amp;nbsp;&lt;/STRONG&gt;and &lt;STRONG&gt;r &lt;/STRONG&gt;appear to need to be private and then the example at least compiles and executes. I’ll contact someone more knowledgeable about MKL to assist with using the MKL routines w/OpenMP.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2013 11:52:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Problem-using-MKL-random-number-generation-in-offloaded-code/m-p/940659#M16971</guid>
      <dc:creator>Kevin_D_Intel</dc:creator>
      <dc:date>2013-12-18T11:52:00Z</dc:date>
    </item>
    <item>
      <title>The problem I was uncertain</title>
      <link>https://community.intel.com/t5/Software-Archive/Problem-using-MKL-random-number-generation-in-offloaded-code/m-p/940660#M16972</link>
      <description>&lt;P&gt;The problem I was uncertain about appears to be addressed by adding the declaration:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;integer :: omp_get_thread_num&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I also added an &lt;STRONG&gt;!$omp barrier &lt;/STRONG&gt;ahead of the &lt;STRONG&gt;do i=1,10&lt;/STRONG&gt; and forgot to mention in my previous reply that I removed &lt;STRONG&gt;n &lt;/STRONG&gt;from private.&lt;/P&gt;

&lt;P&gt;Here's the complete test case:&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; include 'mkl_vsl.f90'&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; program uniform&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; USE MKL_VSL_TYPE&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; USE MKL_VSL&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer :: omp_get_thread_num&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real(kind=4) r(1000)&amp;nbsp; ! buffer for random numbers&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real(kind=4) a, b&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TYPE (VSL_STREAM_STATE) :: stream&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(kind=4) errcode&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(kind=4) i,tid&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer brng,method,seed,n&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n = 1000&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a = 0.0&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b = 1.0&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brng=VSL_BRNG_MT19937&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; method=VSL_RNG_METHOD_UNIFORM_STD&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; !dir$ attributes offload:mic :: omp_get_thread_num,errcode&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; !dir$ omp offload target(mic)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; !$omp parallel private(errcode,tid,i,seed,r,stream)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tid = omp_get_thread_num()&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; seed=777 * tid&lt;/P&gt;

&lt;P&gt;!&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ***** Initializing *****&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; errcode=vslnewstream(stream, brng, seed)&lt;/P&gt;

&lt;P&gt;!&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ***** Generating *****&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; errcode=vsrnguniform( method, stream, n, r, a, b )&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; !$omp barrier&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1,10&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; print *, tid, r(i)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end do&lt;/P&gt;

&lt;P&gt;!&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ***** Deinitialize *****&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; errcode=vsldeletestream( stream )&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; !$omp end parallel&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2013 12:35:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Problem-using-MKL-random-number-generation-in-offloaded-code/m-p/940660#M16972</guid>
      <dc:creator>Kevin_D_Intel</dc:creator>
      <dc:date>2013-12-18T12:35:43Z</dc:date>
    </item>
    <item>
      <title>Additionally, it makes sense</title>
      <link>https://community.intel.com/t5/Software-Archive/Problem-using-MKL-random-number-generation-in-offloaded-code/m-p/940661#M16973</link>
      <description>&lt;P&gt;Additionally, it makes sense to have a quick look at Intel(R) MKL examples that demonstrate use of RNGs in the offload mode. The&amp;nbsp;examples&amp;nbsp;are available in the folder $MKLROOT/examples/mic_offload/vslc. While the examples are in C, they give the idea.&lt;/P&gt;

&lt;P&gt;We&amp;nbsp;do not recommend to use MT19937 in parallel computations in the format shown in the example above, as use of different seeds in different threads does not look the best approach. In the latest version of the library we support Skipahead feature for this generator which allows using MT19937 in parallel computations. Alternatively, Intel(R) MKL provides another MT algorithm which supports parallel computations, MT2203 BRNG. This generator allows creating up to 6024 independent random number streams. See VSL Notes at &lt;A href="http://software.intel.com/sites/products/documentation/doclib/mkl_sa/111/vslnotes/index.htm"&gt;http://software.intel.com/sites/products/documentation/doclib/mkl_sa/111/vslnotes/index.htm&lt;/A&gt; for additional details. I suggest to run experiments with MT2203.&lt;/P&gt;

&lt;P&gt;Another comment is about array of the results, r. Depending on how you are going to use the output of random number generation, you might want to save the results in the local buffers and process them locally as shown in the example above. Alternatively,&amp;nbsp;you can store random numbers&amp;nbsp;into the common buffer (different threads stores random numbers in the different areas of the memory r). In this case r would be shared between threads.&lt;/P&gt;

&lt;P&gt;Andrey&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>Wed, 18 Dec 2013 14:38:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Problem-using-MKL-random-number-generation-in-offloaded-code/m-p/940661#M16973</guid>
      <dc:creator>Andrey_N_Intel</dc:creator>
      <dc:date>2013-12-18T14:38:48Z</dc:date>
    </item>
  </channel>
</rss>

