Jaroslav Hajek wrote: > On Thu, Jun 10, 2010 at 7:24 PM, Robert Patterson <ri...@cam.ac.uk> 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 dbate...@dbateman.org 35 rue Gambetta +33 1 46 04 02 18 (Home) 92100 Boulogne-Billancourt FRANCE +33 6 72 01 06 33 (Mob) ------------------------------------------------------------------------------ ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo _______________________________________________ Octave-dev mailing list Octave-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/octave-dev