--- trunk/src/math/ParallelRandNumGen.cpp 2005/03/01 23:02:33 388 +++ trunk/src/math/ParallelRandNumGen.cpp 2005/03/07 22:39:33 398 @@ -51,10 +51,25 @@ 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_; - mtRand_ = new MTRand(newSeed, nProcessors, worldRank); + MPI_Comm_rank( MPI_COMM_WORLD, &myRank_); + //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, myRank_); ++nCreatedRNG_; } @@ -65,10 +80,10 @@ ParallelRandNumGen::ParallelRandNumGen() { const int masterNode = 0; int nProcessors; MPI_Comm_size(MPI_COMM_WORLD, &nProcessors); - mtRand_ = new MTRand(nProcessors, worldRank); + MPI_Comm_rank( MPI_COMM_WORLD, &myRank_); + mtRand_ = new MTRand(nProcessors, myRank_); - seed(); - ++nCreatedRNG_; + seed(); /** @todo calling virtual function in constructor is not a good design */ }