Gray, thanks for the update. 

Just fwiw, I did put the MersenneTwister.state.val::Array(Int32,1) in a 
SharedArray so that it could be referenced by all of the processes in your 
original parfor implementation.  This method seemed to require writing a 
new wrapper to the call to dsfmt_genrand_close_open() in libdSFMT.  

Doing this ultimately gets the results you were looking for, but seems to 
be far less elegant and less efficient than your pmap() implementation.

Since I also agree that Monte Carlo in parallel seems like it is 
unavoidably "distributed", you should require each process to work on 
non-overlapping substreams of the same stream.  I wonder (mainly for my own 
purposes) if this pmap() implementation is all that "safe", in the 
meantime, before a SFMT Jump is implemented.  

That is, if you end up generating more than one rand() in a process, you 
are not guaranteed that just by setting the seed will give you the same 
results in each time you run it.

In the meantime, might it be preferable to just generate all the rand()s 
you are ever going to need, serially, ahead of time, put them in a 
distributed array, and have your parallel processes work on their separate 
pieces of the distributed array?

Jim


On Saturday, July 19, 2014 3:53:14 PM UTC-4, Gray Calhoun wrote:
>
> On Friday, July 18, 2014 5:36:11 PM UTC-4, Viral Shah wrote:
>>
>> One thing we can do is use SFMT Jump. It's dependencies are not so 
>> straightforward to build, and I am not sure how well supported this is, but 
>> it may be the best way to get parallel streams.
>>
>> http://www.math.sci.hiroshima-u.ac.jp/~%20m-mat/MT/SFMT/JUMP/index.html
>>
>
> That's probably the right approach long-term; I know that R uses an RNG 
> developed by L'Ecuyer [1] that might be easier to implement and would 
> probably be worth including on its own. (For reproducibility of results 
> that depend on this RNG, if nothing else.) If the pmap method I mentioned 
> in an earlier email turns out to be too slow [2], I might look into these 
> other approaches.
>
> [1] See section 6 of <
> https://stat.ethz.ch/R-manual/R-devel/library/parallel/doc/parallel.pdf>,
> this package is included in R 3.0+ by default.
> [2] https://groups.google.com/d/msg/julia-users/AydkFR7mJqo/_bu4S2W-x90J
>

Reply via email to