[MPICH] mpich2 & rand()

Brian Dobbins bdobbins at gmail.com
Sat Jun 23 09:39:42 CDT 2007


Hi Andras,

  If all the nodes are reaching that line at the same time (the same second,
essentially), they'll all get seeded with the same number in your srand()
call.  One simple (but not ideal) solution is for P processors, initialize
the random number generate on the master process as you are doing, then use
it to generate an array of P initial random numbers as seeds, and then
scatter these seeds out to the processes.  You then call srand() with these
values instead, which will pretty much make sure you have different seeds on
the nodes, giving you a quasi-random numbers on each process.

  Be aware, though, that while this might be suitable for
testing/developing, true random number generation is a pretty complex topic,
and you would be much better off using a library like SPRNG (
http://sprng.cs.fsu.edu/ ).  This adds complexity, but it's really the only
way to have 'real' random numbers.

  Hope that helps,
  - Brian


Brian Dobbins
Yale Engineering HPC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20070623/06580c41/attachment.htm>


More information about the mpich-discuss mailing list