If your goal is that each call to rand(), regardless of process, 
sequentially pulls a number from the RNG stream, then perhaps you just need 
to create a MersenneTwister([seed]) object.

mystream = MersenneTwister(1)
 ## Parallel execution
    srand(1)
    parfor = @parallel (vcat) for i=1:4
        rand(mystream)
    end

Intuitively, this seems like it must come with some communication overhead.

It seems likely that there should be a way to avoid this overhead with 
pmap().

Jim


On Tuesday, July 15, 2014 6:25:11 PM UTC-4, Gray Calhoun wrote:
>
> Hi everyone, I'm trying to start using Julia for some Monte Carlo 
> simulations
> (not MCMC) which I'd like to parallelize. I haven't found any documentation
> for setting the RNG's seed for parallelization. The naive approach gives
> different results than non-parallel execution (which is not surprising).
>
> Starting with `julia -p 4` and executing:
>
>     ## Sequential execution
>     srand(1)
>     seqfor = Array(Float64,4)
>     for i=1:4
>         seqfor[i] = rand()
>     end
>
>     ## Parallel execution
>     srand(1)
>     parfor = @parallel (vcat) for i=1:4
>         rand()
>     end
>
>     [sort(parfor) sort(seqfor)]
>
> gives
>
>     4x2 Array{Float64,2}:
>      0.346517  0.00790928
>      0.346517  0.236033
>      0.662369  0.312707
>      0.914194  0.346517
>
> and re-running the parallel code can give different results even after
> re-seeding. If we start julia without `-p 4` then both loops give the
> same results. If it matters, I'm using Julia version 0.3.0-rc1+28
> from source (commit 79e4771).
>
> Is there documentation on the right way to parallelize simulations in
> Julia? If not, should my next step be to carefully read the "parallel
> computing" documentation?
>

Reply via email to