help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cellfun and parcellfun


From: David Bateman
Subject: Re: cellfun and parcellfun
Date: Thu, 10 Jun 2010 21:52:25 +0200
User-agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706)

Jaroslav Hajek wrote:
On Thu, Jun 10, 2010 at 7:24 PM, Robert Patterson <address@hidden> wrote:
Hi,

I am writing some Monte Carlo simulation code.  The problem can be
broken down via domain decomposition (several different sub-problems
that only need to communicate occasionally).  I am implementing this
decomposition via cellfun, in order to avoid writing explicit loops.  I
hope to parallelise with parcellfun from the general package on
octaveforge.

Assuming I can reseed the random number generator with the same values
each time I run a calculation:

1. Will I get the same random number at each point in my code when using
cellfun as I would with a simple loop, or is the order at least stable
on any one implementation?


Yes. Cellfun evaluates sequentially upwards, just like a loop.

2. Is it safe to use parcellfun with the built in random number
generator?


Yes. parcellfun is not based on threads, but on process cloning
(fork). Using any function is therefore safe. However, all cloned
process will experience the same sequence of random numbers. The
easiest way to avoid this is to generate all number beforehand or
generate a seed for each input. Eventually, I could create a more
general approach to solve this.

If you call parcellfun once and before a call to rand, the state of the random generator will be undefined.. The first call to rand in the forked process should end up with a different state vector, either based on /dev/urandom if that entropy pool is available, or the lsb of the clock, which should still have enough difference too ensure that the forked processes have different random sequences.

It might be nice to add a feature like rand("state", "reset") or rand("state", []) that would reinitialize the state of the generator so that we could ensure that state is different in each forked process even if rand had been called previously

D.


--
David Bateman                                address@hidden
35 rue Gambetta                              +33 1 46 04 02 18 (Home)
92100 Boulogne-Billancourt FRANCE            +33 6 72 01 06 33 (Mob)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]