ASCOT5
Loading...
Searching...
No Matches
random.h
Go to the documentation of this file.
1
5#ifndef RANDOM_H
6#define RANDOM_H
7
8#if defined(RANDOM_MKL)
9
10#include <mkl_vsl.h>
11
12/* Use Mersenne Twister as default RNG in MKL */
13#ifndef RANDOM_MKL_RNG
14#define RANDOM_MKL_RNG VSL_BRNG_SFMT19937
15#endif
16
17typedef struct {
18 VSLStreamStatePtr r;
20
21void random_mkl_init(random_data* rdata, int seed);
22double random_mkl_uniform(random_data* rdata);
23double random_mkl_normal(random_data* rdata);
24void random_mkl_uniform_simd(random_data* rdata, int n, double* r);
25void random_mkl_normal_simd(random_data* rdata, int n, double* r);
26
27#define random_init(data, seed) random_mkl_init(data, seed)
28#define random_uniform(data) random_mkl_uniform(data)
29#define random_normal(data) random_mkl_normal(data)
30#define random_uniform_simd(data, n, r) random_mkl_uniform_simd(data, n, r)
31#define random_normal_simd(data, n, r) random_mkl_normal_simd(data, n, r)
32
33
34#elif defined(RANDOM_GSL)
35
36#include <gsl/gsl_rng.h>
37
38typedef struct {
39 gsl_rng* r;
41
42void random_gsl_init(random_data* rdata, int seed);
43double random_gsl_uniform(random_data* rdata);
44double random_gsl_normal(random_data* rdata);
45void random_gsl_uniform_simd(random_data* rdata, int n, double* r);
46void random_gsl_normal_simd(random_data* rdata, int n, double* r);
47
48#define random_init(data, seed) random_gsl_init(data, seed)
49#define random_uniform(data) random_gsl_uniform(data)
50#define random_normal(data) random_gsl_normal(data)
51#define random_uniform_simd(data, n, r) random_gsl_uniform_simd(data, n, r)
52#define random_normal_simd(data, n, r) random_gsl_normal_simd(data, n, r)
53
54
55#elif defined(RANDOM_LCG)
56
57#include <stdint.h>
58#include "offload_acc_omp.h"
59
60typedef struct {
61 uint64_t r;
63
64void random_lcg_init(random_data* rdata, uint64_t seed);
65uint64_t random_lcg_integer(random_data* rdata);
66DECLARE_TARGET
67double random_lcg_uniform(random_data* rdata);
68DECLARE_TARGET_END
69double random_lcg_normal(random_data* rdata);
70DECLARE_TARGET
71void random_lcg_uniform_simd(random_data* rdata, int n, double* r);
72DECLARE_TARGET_END
73void random_lcg_normal_simd(random_data* rdata, int n, double* r);
74
75#define random_init(data, seed) random_lcg_init(data, seed)
76#define random_uniform(data) random_lcg_uniform(data)
77#define random_normal(data) random_lcg_normal(data)
78#define random_uniform_simd(data, n, r) random_lcg_uniform_simd(data, n, r)
79#define random_normal_simd(data, n, r) random_lcg_normal_simd(data, n, r)
80
81#else /* No RNG lib defined, use drand48 */
82
83//#define _XOPEN_SOURCE 500
84#include <stdlib.h>
85
87typedef void* random_data;
88
90void random_drand48_uniform_simd(int n, double* r);
91void random_drand48_normal_simd(int n, double* r);
92
94#define random_init(data, seed) srand48(seed)
96#define random_uniform(data) drand48()
98#define random_normal(data) random_drand48_normal()
100#define random_uniform_simd(data, n, r) random_drand48_uniform_simd(n, r)
102#define random_normal_simd(data, n, r) random_drand48_normal_simd(n, r)
103
104#endif // drand48
105
106#endif
random_data rdata
Definition afsi.c:22
void * random_data
Definition random.h:87
void random_drand48_uniform_simd(int n, double *r)
Vectorised sampling from uniform distribution.
Definition random.c:180
double random_drand48_normal()
Initialize random generator which uses the linear congruential algorithm and 48-bit integer arithmeti...
Definition random.c:166
void random_drand48_normal_simd(int n, double *r)
Vectorised sampling from normal distribution.
Definition random.c:195