ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/md_code/randomSPRNG.cpp
(Generate patch)

Comparing trunk/mdtools/md_code/randomSPRNG.cpp (file contents):
Revision 221 by chuckv, Thu Jan 2 20:14:08 2003 UTC vs.
Revision 253 by chuckv, Thu Jan 30 15:20:21 2003 UTC

# Line 3 | Line 3
3  
4   #include "randomSPRNG.hpp"
5   #include "simError.h"
6 + #include "sprng.h"
7 +
8   #ifdef IS_MPI
9   #include "mpiSimulation.hpp"
10   #endif
11  
12 + using namespace std;
13 +
14   /* randomStreamSPRNF creates a new SPRNG stream for random numbers
15   */
16  
17 < int randomSPRNG::nStreamsInitialized;
17 > int randomSPRNG::nStreamsInitialized = 0;
18  
19 < randomSPRNG::randomSPRNG(iseed){
20 < #ifdef IS_MPI
19 > randomSPRNG::randomSPRNG(int iseed){
20 >  int newSeed;
21    nStreamsInitialized++;
22 <  //Fix this
23 < #error "Fix instance of mpiSimulation in randomSPRNG"
20 <  nSPRNGStreams = getnumberProcessors();
21 <  myStreamNumber = nStreamsInitialized*(getMyNode() + nSPRNGStreams);
22 >  newSeed = abs(iseed) + nStreamsInitialized;  
23 >  if( newSeed < 0 ) newSeed = abs( newSeed );
24  
25 + #ifdef IS_MPI
26  
27 +  nSPRNGStreams = mpiSim->getNumberProcessors();
28 +
29 +  myStreamNumber = mpiSim->getMyNode();
30 +
31 +  
32 +
33   #else
34 <  nStreamsInitialized++;
34 >
35    nSPRNGStreams = 1;
36 <  myStreamNumber = nSPRNGStreams;
36 >  myStreamNumber = 0;
37  
38   #endif
39  
40 +
41    thisStream = init_sprng(GTYPE,myStreamNumber,nSPRNGStreams,
42 <                          iseed,SPRNG_DEFAULT);
42 >                         newSeed,SPRNG_DEFAULT);
43   }
44  
45   randomSPRNG::~randomSPRNG(){
46 <
47 <  free_sprng(int *thisStream);
48 <  nStreamsInitialized--;
49 <
46 >  if ( thisStream != NULL){
47 >    free_sprng(thisStream);
48 >    nStreamsInitialized--;
49 >  }
50   }
51  
52  
53   double randomSPRNG::getRandom(){
54 <  double ranNum;
45 <  ranNum = sprng(thisStream);
46 <  return ranNum;
54 >  return sprng(thisStream);
55   }
56  
57  
58   // Gaussian SPRNG class...
59  
52 gaussianSPRNG::gaussianSPRNG() : randomSPRNG()
53 {
54 }
55
56 gaussianSPRNG::~gaussianSPRNG() : ~randomSPRNG()
57 {
58 }
59
60   double gaussianSPRNG::getGaussian(){
61    double ranNum1;
62    double ranNum2;
63    double gaussianNumber;
64  double R1;
65  double R2;
64  
65    ranNum1 = getRandom();
66    ranNum2 = getRandom();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines