ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/math/ParallelRandNumGen.cpp
(Generate patch)

Comparing trunk/OOPSE-4/src/math/ParallelRandNumGen.cpp (file contents):
Revision 2072 by tim, Tue Mar 1 23:02:33 2005 UTC vs.
Revision 2076 by tim, Wed Mar 2 15:36:14 2005 UTC

# Line 51 | Line 51 | ParallelRandNumGen::ParallelRandNumGen( const uint32&
51  
52   ParallelRandNumGen::ParallelRandNumGen( const uint32& oneSeed) {
53  
54 +    const int masterNode = 0;
55 +    int seed = oneSeed;
56 +    MPI_Bcast(&seed, 1, MPI_UNSIGNED_LONG, masterNode, MPI_COMM_WORLD);
57 +
58 +    if (seed != oneSeed) {
59 +        sprintf(painCave.errMsg,
60 +                "Using different seed to initialize ParallelRandNumGen.\n");
61 +        painCave.isFatal = 1;;
62 +        simError();
63 +    }
64 +
65      int nProcessors;
66      MPI_Comm_size(MPI_COMM_WORLD, &nProcessors);
67 <    int newSeed = oneSeed +nCreatedRNG_;
67 >
68 >    //In order to generate independent random number stream, the actual seed used by random
69 >    //number generator is the seed passed to the constructor plus the number of random number
70 >    //generators which are already created.    
71 >    int newSeed = oneSeed + nCreatedRNG_;
72      mtRand_ = new MTRand(newSeed, nProcessors, worldRank);
73  
74      ++nCreatedRNG_;
# Line 67 | Line 82 | ParallelRandNumGen::ParallelRandNumGen() {
82      MPI_Comm_size(MPI_COMM_WORLD, &nProcessors);
83      mtRand_ = new MTRand(nProcessors, worldRank);
84  
85 <    seed();        
71 <    ++nCreatedRNG_;
85 >    seed();       /** @todo calling virtual function in constructor is not a good design */
86   }
87  
88  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines