43 const char funcname[] =
"Par_psread";
46 if(!(dest = fopen(filename,
"rb"))){
47 fprintf(stderr,
"Error %i in %s: Failed to open %s.\nExiting...\n\n",
OPENERROR, funcname, filename);
55 fread(&ranval,
sizeof(ranval), 1, dest);
69 const char funcname[] =
"Par_ranset";
72 printf(
"Master seed: %lu\t",*
seed);
77 printf(
"Rank: %i\tSeed %lu\n",
rank, *
seed);
88 const char funcname[] =
"Par_granf";
94 ran_val = ran2(&
seed);
103 const char funcname[] =
"Gauss_z";
105 fprintf(stderr,
"Error %i in %s: Array cannot have length %i.\nExiting...\n\n",
114 for(
int i=0;i<n;i++){
126 double r =sigma*sqrt(-2*log(gsl_rng_uniform(
ranlux_instd)));
129 double r =sigma*sqrt(-2*log(ran2(&
seed)));
132 ps[i]=r*(cos(theta)+sin(theta)*
I)+mu;
137 const char funcname[] =
"Gauss_z";
139 fprintf(stderr,
"Error %i in %s: Array cannot have length %i.\nExiting...\n\n",
148 for(
int i=0;i<n;i++){
160 float r =sigma*sqrt(-2*log(gsl_rng_uniform(
ranlux_instd)));
163 float r =sigma*sqrt(-2*log(ran2(&
seed)));
166 ps[i]=r*(cos(theta)+mu+sin(theta)*
I)+mu;
170int Gauss_d(
double *ps,
unsigned int n,
const double mu,
const double sigma){
171 const char funcname[] =
"Gauss_z";
176 fprintf(stderr,
"Error %i in %s: Array cannot have length %i.\nExiting...\n\n",
191 ps[n]=sqrt(-2*log(gsl_rng_uniform(
ranlux_instd)))*cos(r);
194 ps[n]=sqrt(-2*log(ran2(&
seed)))*cos(r);
213 u=sqrt(-2*log(ran2(&
seed)))*sigma;
221int Gauss_f(
float *ps,
unsigned int n,
const float mu,
const float sigma){
222 const char funcname[] =
"Gauss_z";
227 fprintf(stderr,
"Error %i in %s: Array cannot have length %i.\nExiting...\n\n",
242 ps[n]=sqrt(-2*log(gsl_rng_uniform(
ranlux_instd)))*cos(r);
245 ps[n]=sqrt(-2*log(ran2(&
seed)))*cos(r);
250 ps[n]=sqrt(-2*log(gsl_rng_uniform(
ranlux_instd)))*cos(r);
253 ps[n]=sqrt(-2*log(ran2(&
seed)))*cos(r);
271 u=sqrt(-2*log(ran2(&
seed)))*sigma;
280double ran2(
long *idum) {
283 static long idum2=123456789;
285 static long iv[NTAB];
287#pragma omp threadprivate(idum2, iy, iv)
292 if (-(*idum) < 1) *idum=1;
293 else *idum = -(*idum);
297 for(j=NTAB+7;j>=0;j--) {
299 *idum=IA1*(*idum-k*IQ1)-k*IR1;
300 if (*idum < 0) *idum += IM1;
308 *idum=IA1*(*idum-k*IQ1)-k*IR1;
309 if (*idum < 0) *idum += IM1;
311 idum2=IA2*(idum2-k*IQ2)-k*IR2;
313 if (idum2 < 0) idum2 += IM2; j=iy/NDIV;
316 if (iy < 1) iy += IMM1;
317 if ((temp=AM*iy) > RNMX)
#define ARRAYLEN
Impossible value for array length.
#define OPENERROR
Error opening file.
int Par_dcopy(double *dval)
Broadcasts a double to the other processes.
int Gauss_f(float *ps, unsigned int n, const float mu, const float sigma)
Generates a vector of normally distributed random single precision numbers using the Box-Muller Metho...
int Par_ranread(char *filename, double *ranval)
Reads ps from a file Since this function is very similar to Par_sread, I'm not really going to commen...
int Gauss_z(Complex *ps, unsigned int n, const Complex mu, const double sigma)
Generates a vector of normally distributed random double precision complex numbers using the Box-Mull...
int Gauss_c(Complex_f *ps, unsigned int n, const Complex_f mu, const float sigma)
Generates a vector of normally distributed random single precision complex numbers using the Box-Mull...
int Gauss_d(double *ps, unsigned int n, const double mu, const double sigma)
Generates a vector of normally distributed random double precision numbers using the Box-Muller Metho...
int Par_ranset(unsigned long *seed, int iread)
Uses the rank to get a new seed. Copying from the FORTRAN description here c create new seeds in rang...
double Par_granf()
Generates a random double which is then sent to the other ranks.
int ranset(unsigned long *seed)
Seed the ranlux generator from GSL.
int size
The number of MPI ranks in total.
#define M_PI
if not defined elsewhere
Header for random number configuration.
unsigned long seed
RANLUX seed.
gsl_rng * ranlux_instd
RANLUX instance.
#define Complex
Double precision complex number.
#define Complex_f
Single precision complex number.
#define I
Define I in double precision using C standard notation.