su2hmc
Loading...
Searching...
No Matches
random.h
Go to the documentation of this file.
1
7#ifndef RANDOM
8#define RANDOM
9//Need two cases here. MKL/CUDA or not for BLAS and CUDA or not for complex
10#ifdef __USE_MKL__
11#include <mkl.h>
12#include <mkl_vsl.h>
13#define M_PI 3.14159265358979323846 /* pi */
14#endif
15#ifdef __RANLUX__
16#include <gsl/gsl_rng.h>
17#endif
18#if (defined__INTEL_COMPILER || __INTEL_LLVM_COMPILER)
19#include <mathimf.h>
20#endif
21#include <par_mpi.h>
22//Configuration for existing generators if called
23//===============================================
24#if (defined USE_RAN2||(!defined __USE_MKL__&&!defined __RANLUX__))
26extern long seed;
27#ifdef __cplusplus
28extern "C"
29{
30#endif
39 int ranset(long *seed);
54 int Par_ranset(long *seed, int iread);
65 double ran2(long *idum);
66#ifdef __cplusplus
67}
68#endif
69#elif defined __RANLUX__
71extern gsl_rng *ranlux_instd;
72//Need to get a float version that uses a different seed for performance reasons.
73//Otherwise we get two generators (one float, one double) starting from the same seed. Not good
74//For now, the float generator will be a cast of the double one.
75//gsl_rng *ranlux_instf;
76extern unsigned long seed;
77#ifdef __cplusplus
78extern "C"
79{
80#endif
89 int ranset(unsigned long *seed);
104 int Par_ranset(unsigned long *seed, int iread);
105#ifdef __cplusplus
106}
107#endif
108#elif defined __USE_MKL__
109extern VSLStreamStatePtr stream;
110extern unsigned int seed;
111#ifdef __cplusplus
112extern "C"
113{
114#endif
123 int ranset(unsigned int *seed);
138 int Par_ranset(unsigned int *seed, int iread);
139#ifdef __cplusplus
140}
141#endif
142#else
143extern int seed;
144#ifdef __cplusplus
145extern "C"
146{
147#endif
148 //Mersenne Twister
149 int ranset(int *seed);
150 int Par_ranset(int *seed);
151#ifdef __cplusplus
152}
153#endif
154#endif
155#ifdef __cplusplus
156extern "C"
157{
158#endif
159 //Generators:
160 //==========
161 //Distributions
162 //=============
163 //Use Box-Müller to generate an array of complex numbers
175 int Gauss_z(Complex *ps, unsigned int n, const Complex mu, const double sigma);
187 int Gauss_d(double *ps, unsigned int n, const double mu, const double sigma);
199 int Gauss_c(Complex_f *ps, unsigned int n, const Complex_f mu, const float sigma);
211 int Gauss_f(float *ps, unsigned int n, const float mu, const float sigma);
212
213 //MPI
214 //===
226 int Par_ranread(char *filename, double *ranval);
233 double Par_granf();
234
235#ifdef __cplusplus
236}
237#endif
238//RAN2 stuff treat it separately so as to avoid any accidents
239#if !(defined RAN2) && !(defined __RANLUX__)
240#define RAN2
241#define IM1 2147483563
242#define IM2 2147483399
243#define AM (1.0/IM1)
244#define IMM1 (IM1-1)
245#define IA1 40014
246#define IA2 40692
247#define IQ1 53668
248#define IQ2 52774
249#define IR1 12211
250#define IR2 3791
251#define NTAB 32
252#define NDIV (1+IMM1/NTAB)
253#define EPS 1.2e-7
254#define RNMX (1.0-EPS)
255#endif
256#endif
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...
Definition random.c:221
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...
Definition random.c:42
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...
Definition random.c:102
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...
Definition random.c:136
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...
Definition random.c:170
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...
Definition random.c:64
double Par_granf()
Generates a random double which is then sent to the other ranks.
Definition random.c:87
int ranset(unsigned long *seed)
Seed the ranlux generator from GSL.
Definition random.c:29
MPI headers.
unsigned long seed
RANLUX seed.
Definition random.c:18
gsl_rng * ranlux_instd
RANLUX instance.
Definition random.c:16
#define Complex
Double precision complex number.
Definition sizes.h:64
#define Complex_f
Single precision complex number.
Definition sizes.h:62