(@cej38: thanks for bringing that up to my radar ! However, I'd have
to check the fine prints because I like the "Open" in "OpenCL" and
dispise vendor lock-ins, no matter how shiny the shackles :) )


On Jul 24, 1:11 pm, Lee Spector <lspec...@hampshire.edu> wrote:
> On Jul 22, 2011, at 11:20 AM, bernardH wrote:
>
>
>
> > But there is a small catch : most of the time is spent in the Random
> > Number Generator [3] so it would be sub-optimal to just have worker
> > threads processing the output of a single threaded rng.
>
> I am not very confident in my solution to a similar problem, and my 
> application makes measurement difficult,
> but in case it's food for thought what I did was the following, using the 
> standard Java rng:
>
> ;; create a root binding for the "thread-local-random-generator", although 
> this won't be used in
> the distributed code:
>
> (def thread-local-random-generator (new java.util.Random))

Thank you for your anwser. I cannot comment much on your particular
choice wrt to java.Util.Random because I wanted to use MersenneTwister
and was contraint by some of it's implementation details (in parallel
colt).

I had though about going the same root of a thread local binding but
the colt implementation was not synchronized when using generator
objects (but the static member functions are synchronized).
So I first had a root binding to nil, and a rng that checked if the
binding was nil (calling the static synchronized member functions) or
not (calling the member functions).

However, I gave up on having a generic solution because I'd have to
give up half of the performance if I wanted generic generators (i.e.
not tied to mean, sd) as the Box-Muller algorithm comptes pairs of
numbers (and the colt implementation caches the number if possible
(mean and sd same as given upon generator construction).

This is an ugly implementation detail but I really wanted the best
performance, efficient rng being of utmost importance for my Monte-
Carlo code. Otherwise, I can't think of anything better that your
approach (but hey, that is why I called the gurus here for help :) ).

One should however investigated the thread-safety of the rng because
either the root binding is not safe to share, or your are paying for
useless synchro in your thread-local rng.

Best Regards,

Bernard

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to