Changeset 26514
- Timestamp:
- 10/27/21 21:43:46 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/solutionsequences/solutionsequence_sampling.cpp
r26512 r26514 10 10 #include <random> 11 11 12 #undef M_PI 13 #define M_PI 3.141592653589793238462643 14 15 double lcg(long long* seed){/*{{{*/ 16 17 18 int N = 5; 19 long long M = 1LL<<32; 20 long long a = 1812433253; 21 long long c = 1; 22 23 for(int i=0;i<N;i++){ 24 *seed = a * *seed + c; 25 *seed = *seed%M; 26 } 27 28 return ((double) *seed) / ((double) M); 29 30 } 31 32 double BoxMuller(long long* pseed){ 33 34 double u1 = lcg(pseed); 35 double u2 = lcg(pseed); 36 37 double R = sqrt(-2*log(u1)); 38 double theta = 2*M_PI*u2; 39 40 return R*cos(theta); 41 42 } 43 12 44 void GaussianVector(Vector<IssmDouble>* ppf,int seed){/*{{{*/ 45 13 46 14 47 /*Intermediaries*/ 15 48 double rdnumber; 16 49 17 /*Define random number generator*/ 18 std::normal_distribution<double> distribution(0.0,1.0); // Define probability distribution as the standard normal distribution 50 /*Define seed*/ 19 51 if(seed<0){ 20 52 std::random_device rd; … … 27 59 seed = seed + 783728*my_rank; // change default seed for parallel simulations (by considering an arbitrary shif based on the rank number) 28 60 } 29 //std::default_random_engine generator(seed); 30 std::mt19937 generator(seed); 61 62 long long seedbis; 63 seedbis = (long long) seed; 31 64 32 65 int *local_indices = NULL; … … 37 70 ppf->GetLocalSize(&M); 38 71 for(int i=0;i<M;i++){ 39 rdnumber = distribution(generator);72 rdnumber = BoxMuller(&seedbis); 40 73 ppf->SetValue(local_indices[i],rdnumber,INS_VAL); 41 74 }
Note:
See TracChangeset
for help on using the changeset viewer.