--- trunk/OOPSE-4/src/math/ParallelRandNumGen.cpp 2005/03/01 23:02:33 2072 +++ trunk/OOPSE-4/src/math/ParallelRandNumGen.cpp 2005/03/02 15:36:14 2076 @@ -51,9 +51,24 @@ ParallelRandNumGen::ParallelRandNumGen( const uint32& ParallelRandNumGen::ParallelRandNumGen( const uint32& oneSeed) { + const int masterNode = 0; + int seed = oneSeed; + MPI_Bcast(&seed, 1, MPI_UNSIGNED_LONG, masterNode, MPI_COMM_WORLD); + + if (seed != oneSeed) { + sprintf(painCave.errMsg, + "Using different seed to initialize ParallelRandNumGen.\n"); + painCave.isFatal = 1;; + simError(); + } + int nProcessors; MPI_Comm_size(MPI_COMM_WORLD, &nProcessors); - int newSeed = oneSeed +nCreatedRNG_; + + //In order to generate independent random number stream, the actual seed used by random + //number generator is the seed passed to the constructor plus the number of random number + //generators which are already created. + int newSeed = oneSeed + nCreatedRNG_; mtRand_ = new MTRand(newSeed, nProcessors, worldRank); ++nCreatedRNG_; @@ -67,8 +82,7 @@ ParallelRandNumGen::ParallelRandNumGen() { MPI_Comm_size(MPI_COMM_WORLD, &nProcessors); mtRand_ = new MTRand(nProcessors, worldRank); - seed(); - ++nCreatedRNG_; + seed(); /** @todo calling virtual function in constructor is not a good design */ }