Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
302 Views

parallel random number generation

Jump to solution
I would like to use the vsl random number generators in a parallel monte carlo simulation, ie the possibility to distribute the simulation on all processor cores. Regarding this I have 2 different cases:
- In the first case I would like to accelerate a simulation by distributing it on multiple processor cores. For example, let s say I need to simulate 10000 runs with each run containing 5000 timesteps. That means that I need to generate 10000*5000 random variates.
My simulation would look something like this:

#define SEED 1

#define BRNG VSL_BRNG_MCG31

#define METHOD VSL_RNG_METHOD_GAUSSIAN_ICDF

// initialize vsl random generator stream

VSLStreamStatePtr stream;

double a=0.0,sigma=0.3;

errcode = vslNewStream( &stream, BRNG, SEED );

for(int i=0; i<9999; i++){

// simulate one path by generating 5000 variates.

double r[5000];

vdRngGaussian( METHOD, stream, N, r, a, sigma );

for (int j=0;j<4999;j++){

// simulate random walk using the variates

}

}

I would like to parallelize the outer loop. My question is: is it safe to call vdRngGaussian from multiple threads? And am I guaranteed to have independant variates?


The second scenario would be to parallelize multiple simulations. In this case I would like to do one full simulation per thread and I need to to generate independant variates for all simulations. In this case my question would be what is the approach to generating the random variates? Should I use one rng per thread and initialize them with different seeds? I have been told that this is not the best way of getting independant variates. Another method would be to use the leapfrog method. What is best?



anwar

0 Kudos
46 Replies
Highlighted
Beginner
23 Views

Hi Genaddy,

Now, I'm using composer_xe_2015.0.090. This is most recent version that I have on my machine. Trying to compile the code I seethe following error:

pi_mont.cpp(10): error: identifier "VSL_METHOD_DUNIFORM_STD" is undefined

      vdRngUniform(VSL_METHOD_DUNIFORM_STD, stream[sid], 1024, buff, -1.0, 1.0);

                                  ^

compilation aborted for pi_mont.cpp (code 2)

 

I have changed VSL_METHOD_DUNIFORM_STD to 0 and compile it. The ldd command shows following dependencies:

        linux-vdso.so.1 =>  (0x00007fff8cfbe000)

        libmkl_intel_lp64.so => /opt/intel/composer_xe_2015.0.090/mkl/lib/intel64/libmkl_intel_lp64.so (0x00007f08f2db3000)

        libmkl_intel_thread.so => /opt/intel/composer_xe_2015.0.090/mkl/lib/intel64/libmkl_intel_thread.so (0x00007f08f1a18000)

        libmkl_core.so => /opt/intel/composer_xe_2015.0.090/mkl/lib/intel64/libmkl_core.so (0x00007f08eff73000)

        libiomp5.so => /opt/intel/composer_xe_2015.0.090/compiler/lib/intel64/libiomp5.so (0x00007f08efc48000)

        libm.so.6 => /lib64/libm.so.6 (0x00007f08ef9b5000)

        libcilkrts.so.5 => /opt/intel/composer_xe_2015.0.090/compiler/lib/intel64/libcilkrts.so.5 (0x00007f08ef776000)

        libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f08ef470000)

        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f08ef259000)

        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f08ef03c000)

        libc.so.6 => /lib64/libc.so.6 (0x00007f08eeca8000)

        libdl.so.2 => /lib64/libdl.so.2 (0x00007f08eeaa3000)

        /lib64/ld-linux-x86-64.so.2 (0x00007f08f36c1000)

 

I have printed INTEL_MKL_VERSION and it shows 110200.

 

Inspxe-cl output is:

0 new problem(s) found

 

I have also tried Cilkscreen. The output still shows race condition:

Cilkscreen Race Detector V2.0.0, Build 4225

 

Race condition on location 0x7f7f7e21e040

  write access at 0x7f7f7de4cef3: (vdRngUniform+0xf3)

  read access at 0x7f7f7de4ce71: (vdRngUniform+0x71)

    called by 0x40164c: (/localstore/theorie/amirsol/paralleluct/pi_mont.cpp:11, cal+0x60)

    called by 0x401914: (/localstore/theorie/amirsol/paralleluct/pi_mont.cpp:22, main+0x2b7)

1 error found by Cilkscreen

Cilkscreen suppressed 1 duplicate error messages

 

Which one should I thrust? I do not have MKL 11.3 to check it.

 

Ali

0 Kudos
Highlighted
Employee
23 Views

Hi Ali,

on your observation "pi_mont.cpp(10): error: identifier "VSL_METHOD_DUNIFORM_STD" is undefined": this method was deprecated and removed from the library. Use VSL_RNG_METHOD_UNIFORM_STD instead of it. Please, consult with the table in the section "New method names" available at https://software.intel.com/en-us/node/521870 that maps the legacy names into new ones.

Thanks,

Andrey

0 Kudos
Highlighted
Beginner
23 Views

Hi Andrey,

What do you think about my observation on different outputs between Cilkscreen and inspxe-cl?

Thanks

Ali

0 Kudos
Highlighted
Employee
23 Views

Hi Ali, I have nothing to add to Gennady's suggestion. Thanks, Andrey

0 Kudos
Highlighted
Beginner
23 Views

Hello, Andrey!

Thank you for the detailed explanations in this forum! I have a question on parallel random generation in an MPI based application.

There is an application based on Microsoft MPI that performs calculation on multiple hosts. I'd like to add Mersenne Twsiter MT2203 independent random stream (your option #3) to each of this application MPI process using Intel MKL.

What would be the most optimal place in the code to start the streams? Should it be done before setting up all MPI processes or at the beginning of each MPI process?

Thanks much in advance,

Dmitry

0 Kudos
Highlighted
Employee
23 Views

Hi Dmitry, I would start with initialization of MT2203 streams at the beginning of each MPI process. Thanks, Andrey

0 Kudos
Highlighted
Beginner
23 Views

Andrey, thank you for the quick response!

0 Kudos