su2hmc
Loading...
Searching...
No Matches
random.h
Go to the documentation of this file.
1
6#ifndef RANDOM
7#define RANDOM
8//Need two cases here. MKL/CUDA or not for BLAS and CUDA or not for complex
9#ifdef __NVCC__
10#include <cublas_v2.h>
11#endif
12#ifdef __INTEL_MKL__
13#include <mkl.h>
14#include <mkl_vsl.h>
15#define M_PI 3.14159265358979323846 /* pi */
16#endif
17#ifdef __RANLUX__
18#include <gsl/gsl_rng.h>
19#endif
20#include <math.h>
21#if (defined__INTEL_COMPILER || __INTEL_LLVM_COMPILER)
22#include <mathimf.h>
23#endif
24#include <par_mpi.h>
25#include <sizes.h>
26//Configuration for existing generators if called
27//===============================================
28#if (defined USE_RAN2||(!defined __INTEL_MKL__&&!defined __RANLUX__))
29extern long seed;
30#ifdef __cplusplus
31extern "C"
32{
33#endif
41 int ranset(long *seed);
55 int Par_ranset(long *seed, int iread);
65 double ran2(long *idum);
66#ifdef __cplusplus
67}
68#endif
69#elif defined __RANLUX__
70extern gsl_rng *ranlux_instd;
71//Need to get a float version that uses a different seed for performance reasons.
72//Otherwise we get two generators (one float, one double) starting from the same seed. Not good
73//For now, the float generator will be a cast of the double one.
74//gsl_rng *ranlux_instf;
75extern unsigned long seed;
76#ifdef __cplusplus
77extern "C"
78{
79#endif
87 int ranset(unsigned long *seed);
101 int Par_ranset(unsigned long *seed, int iread);
102#ifdef __cplusplus
103}
104#endif
105#elif defined __INTEL_MKL__
106extern VSLStreamStatePtr stream;
107extern unsigned int seed;
108#ifdef __cplusplus
109extern "C"
110{
111#endif
119 int ranset(unsigned int *seed);
133 int Par_ranset(unsigned int *seed, int iread);
134#ifdef __cplusplus
135}
136#endif
137#else
138extern int seed;
139#ifdef __cplusplus
140extern "C"
141{
142#endif
143 //Mersenne Twister
144 int ranset(int *seed);
145 int Par_ranset(int *seed);
146#ifdef __cplusplus
147}
148#endif
149#endif
150#ifdef __cplusplus
151extern "C"
152{
153#endif
154 //Generators:
155 //==========
156 //Distributions
157 //=============
158 //Use Box-Müller to generate an array of complex numbers
169 int Gauss_z(Complex *ps, unsigned int n, const Complex mu, const double sigma);
180 int Gauss_d(double *ps, unsigned int n, const double mu, const double sigma);
191 int Gauss_c(Complex_f *ps, unsigned int n, const Complex_f mu, const float sigma);
202 int Gauss_f(float *ps, unsigned int n, const float mu, const float sigma);
203
204 //MPI
205 //===
216 int Par_ranread(char *filename, double *ranval);
222 double Par_granf();
224 int ran_test();
225
226#ifdef __cplusplus
227}
228#endif
229//RAN2 stuff treat it separately so as to avoid any accidents
230#if !(defined RAN2) && !(defined __RANLUX__)
231#define RAN2
232#define IM1 2147483563
233#define IM2 2147483399
234#define AM (1.0/IM1)
235#define IMM1 (IM1-1)
236#define IA1 40014
237#define IA2 40692
238#define IQ1 53668
239#define IQ2 52774
240#define IR1 12211
241#define IR2 3791
242#define NTAB 32
243#define NDIV (1+IMM1/NTAB)
244#define EPS 1.2e-7
245#define RNMX (1.0-EPS)
246#endif
247#endif
MPI headers.
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:369
int ranset(long *seed)
Dummy seed the ran2 generator.
Definition random.c:74
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:88
int ran_test()
Test Functions.
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:214
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:260
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:306
int Par_ranset(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:135
double Par_granf()
Generates a random double which is then sent to the other ranks.
Definition random.c:190
double ran2(long *idum)
Generates uniformly distributed random double between zero and one as described in numerical recipes....
Definition random.c:440
long seed
RAN2 seed.
Definition random.c:27
Defines the constants of the code and other parameters for loop dimensions. Each subroutine includes ...
#define Complex
Double precision complex number.
Definition sizes.h:58
#define Complex_f
Single precision complex number.
Definition sizes.h:56