ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-2.0/src/math/randomSPRNG.cpp
(Generate patch)

Comparing branches/new_design/OOPSE-2.0/src/math/randomSPRNG.cpp (file contents):
Revision 1683, Thu Oct 28 22:34:02 2004 UTC vs.
Revision 1725 by tim, Wed Nov 10 22:01:06 2004 UTC

# Line 6 | Line 6
6   #include <sprng.h>
7  
8   #ifdef IS_MPI
9 < #include "brains/mpiSimulation.hpp"
9 >
10 > #include <mpi.h>
11   #endif
12  
13   using namespace std;
# Line 16 | Line 17 | randomSPRNG::randomSPRNG(int iseed){
17  
18   int randomSPRNG::nStreamsInitialized = 0;
19  
20 < randomSPRNG::randomSPRNG(int iseed){
21 <  int newSeed;
22 <  nStreamsInitialized++;
23 <  newSeed = abs(iseed) + nStreamsInitialized;  
23 <  if( newSeed < 0 ) newSeed = abs( newSeed );
20 > randomSPRNG::randomSPRNG( int iseed ) {
21 >    int newSeed;
22 >    nStreamsInitialized++;
23 >    newSeed = abs(iseed) + nStreamsInitialized;
24  
25 +    if (newSeed < 0)
26 +        newSeed = abs(newSeed);
27 +
28   #ifdef IS_MPI
29  
30 <  nSPRNGStreams = mpiSim->getNProcessors();
31 <
32 <  myStreamNumber = mpiSim->getMyNode();
30 >    //random number generator should not depend on MpiSimulation
31 >    MPI_Comm_size(MPI_COMM_WORLD, &nSPRNGStreams);
32 >    myStreamNumber = worldRank;
33  
31  
32
34   #else
35  
36 <  nSPRNGStreams = 1;
37 <  myStreamNumber = 0;
36 >    nSPRNGStreams = 1;
37 >    myStreamNumber = 0;
38  
39   #endif
40  
41 <
42 <  thisStream = init_sprng(GTYPE,myStreamNumber,nSPRNGStreams,
42 <                         newSeed,SPRNG_DEFAULT);
41 >    thisStream = init_sprng(GTYPE, myStreamNumber, nSPRNGStreams, newSeed,
42 >                            SPRNG_DEFAULT);
43   }
44  
45 < randomSPRNG::~randomSPRNG(){
46 <  if ( thisStream != NULL){
47 <    free_sprng(thisStream);
48 <    nStreamsInitialized--;
49 <  }
45 > randomSPRNG::~randomSPRNG() {
46 >    if (thisStream != NULL) {
47 >        free_sprng(thisStream);
48 >        nStreamsInitialized--;
49 >    }
50   }
51  
52 + double randomSPRNG::getRandom() { return sprng(thisStream); }
53  
53 double randomSPRNG::getRandom(){
54  return sprng(thisStream);
55 }
56
57
54   // Gaussian SPRNG class...
55  
56 < double gaussianSPRNG::getGaussian(){
57 <  double ranNum1;
58 <  double ranNum2;
59 <  double gaussianNumber;
56 > double gaussianSPRNG::getGaussian() {
57 >    double ranNum1;
58 >    double ranNum2;
59 >    double gaussianNumber;
60  
61 <  ranNum1 = getRandom();
62 <  ranNum2 = getRandom();
61 >    ranNum1 = getRandom();
62 >    ranNum2 = getRandom();
63  
64 <  gaussianNumber = sqrt(-2.0 * log(ranNum1)) * cos(2 * M_PI * ranNum2);
64 >    gaussianNumber = sqrt(-2.0 * log(ranNum1)) * cos(2 * M_PI * ranNum2);
65  
66 <  return gaussianNumber;
66 >    return gaussianNumber;
67   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines