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 221 by chuckv, Thu Jan 2 20:14:08 2003 UTC

# Line 3 | Line 3
3  
4   #include "randomSPRNG.hpp"
5   #include "simError.h"
6 + #ifdef IS_MPI
7 + #include "mpiSimulation.hpp"
8 + #endif
9  
7
10   /* randomStreamSPRNF creates a new SPRNG stream for random numbers
11   */
12  
13 < int ranStreamSPRNG::nSPRNGStreams;
13 > int randomSPRNG::nStreamsInitialized;
14  
15 < randomStreamSPRNG::randomStreamSPRNG(){
15 > randomSPRNG::randomSPRNG(iseed){
16   #ifdef IS_MPI
17 +  nStreamsInitialized++;
18 +  //Fix this
19 + #error "Fix instance of mpiSimulation in randomSPRNG"
20 +  nSPRNGStreams = getnumberProcessors();
21 +  myStreamNumber = nStreamsInitialized*(getMyNode() + nSPRNGStreams);
22  
16  
23  
24   #else
25 <  nSPRNGStreams++;
26 <
25 >  nStreamsInitialized++;
26 >  nSPRNGStreams = 1;
27    myStreamNumber = nSPRNGStreams;
28  
23  thisStream = init_sprng(GTYPE,streamnum,nstreams,SEED,SPRNG_DEFAULT);
24
25
29   #endif
30 +
31 +  thisStream = init_sprng(GTYPE,myStreamNumber,nSPRNGStreams,
32 +                          iseed,SPRNG_DEFAULT);
33   }
34  
35 < randomStreamSPRNG::~randomStreamSPRNG(){
35 > randomSPRNG::~randomSPRNG(){
36  
37    free_sprng(int *thisStream);
38 <  nSPRNGStreams--;
38 >  nStreamsInitialized--;
39  
34
40   }
41  
42  
43 < double getRanStreamSPRNG(){
43 > double randomSPRNG::getRandom(){
44    double ranNum;
45 <  nanNum = sprng(thisStream);
45 >  ranNum = sprng(thisStream);
46    return ranNum;
47   }
48 +
49 +
50 + // Gaussian SPRNG class...
51 +
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;
66 +
67 +  ranNum1 = getRandom();
68 +  ranNum2 = getRandom();
69 +
70 +  gaussianNumber = sqrt(-2.0 * log(ranNum1)) * cos(2 * M_PI * ranNum2);
71 +
72 +  return gaussianNumber;
73 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines