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 220 by chuckv, Mon Dec 30 16:20:42 2002 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 ranStreamSPRNG::nSPRNGStreams;
17 > int randomSPRNG::nStreamsInitialized = 0;
18  
19 < randomStreamSPRNG::randomStreamSPRNG(){
19 > randomSPRNG::randomSPRNG(int iseed){
20 >  int newSeed;
21 >  nStreamsInitialized++;
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
19  nSPRNGStreams++;
34  
35 <  myStreamNumber = nSPRNGStreams;
35 >  nSPRNGStreams = 1;
36 >  myStreamNumber = 0;
37  
38 <  thisStream = init_sprng(GTYPE,streamnum,nstreams,SEED,SPRNG_DEFAULT);
38 > #endif
39  
40  
41 < #endif
41 >  thisStream = init_sprng(GTYPE,myStreamNumber,nSPRNGStreams,
42 >                         newSeed,SPRNG_DEFAULT);
43   }
44  
45 < randomStreamSPRNG::~randomStreamSPRNG(){
45 > randomSPRNG::~randomSPRNG(){
46 >  if ( thisStream != NULL){
47 >    free_sprng(thisStream);
48 >    nStreamsInitialized--;
49 >  }
50 > }
51  
31  free_sprng(int *thisStream);
32  nSPRNGStreams--;
52  
53 <
53 > double randomSPRNG::getRandom(){
54 >  return sprng(thisStream);
55   }
56  
57  
58 < double getRanStreamSPRNG(){
59 <  double ranNum;
60 <  nanNum = sprng(thisStream);
61 <  return ranNum;
58 > // Gaussian SPRNG class...
59 >
60 > double gaussianSPRNG::getGaussian(){
61 >  double ranNum1;
62 >  double ranNum2;
63 >  double gaussianNumber;
64 >
65 >  ranNum1 = getRandom();
66 >  ranNum2 = getRandom();
67 >
68 >  gaussianNumber = sqrt(-2.0 * log(ranNum1)) * cos(2 * M_PI * ranNum2);
69 >
70 >  return gaussianNumber;
71   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines