forked from ascot4fusion/ascot5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
random.h
99 lines (72 loc) · 2.92 KB
/
random.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* @file random.h
* @brief Header file for random.c
*/
#ifndef RANDOM_H
#define RANDOM_H
#if defined(RANDOM_MKL)
#include <mkl_vsl.h>
/* Use Mersenne Twister as default RNG in MKL */
#ifndef RANDOM_MKL_RNG
#define RANDOM_MKL_RNG VSL_BRNG_SFMT19937
#endif
typedef struct {
VSLStreamStatePtr r;
} random_data;
void random_mkl_init(random_data* rdata, int seed);
double random_mkl_uniform(random_data* rdata);
double random_mkl_normal(random_data* rdata);
void random_mkl_uniform_simd(random_data* rdata, int n, double* r);
void random_mkl_normal_simd(random_data* rdata, int n, double* r);
#define random_init(data, seed) random_mkl_init(data, seed)
#define random_uniform(data) random_mkl_uniform(data)
#define random_normal(data) random_mkl_normal(data)
#define random_uniform_simd(data, n, r) random_mkl_uniform_simd(data, n, r)
#define random_normal_simd(data, n, r) random_mkl_normal_simd(data, n, r)
#elif defined(RANDOM_GSL)
#include <gsl/gsl_rng.h>
typedef struct {
gsl_rng* r;
} random_data;
void random_gsl_init(random_data* rdata, int seed);
double random_gsl_uniform(random_data* rdata);
double random_gsl_normal(random_data* rdata);
void random_gsl_uniform_simd(random_data* rdata, int n, double* r);
void random_gsl_normal_simd(random_data* rdata, int n, double* r);
#define random_init(data, seed) random_gsl_init(data, seed)
#define random_uniform(data) random_gsl_uniform(data)
#define random_normal(data) random_gsl_normal(data)
#define random_uniform_simd(data, n, r) random_gsl_uniform_simd(data, n, r)
#define random_normal_simd(data, n, r) random_gsl_normal_simd(data, n, r)
#elif defined(RANDOM_LCG)
#include <stdint.h>
#pragma omp declare target
typedef struct {
uint64_t r;
} random_data;
void random_lcg_init(random_data* rdata, uint64_t seed);
uint64_t random_lcg_integer(random_data* rdata);
double random_lcg_uniform(random_data* rdata);
double random_lcg_normal(random_data* rdata);
void random_lcg_uniform_simd(random_data* rdata, int n, double* r);
void random_lcg_normal_simd(random_data* rdata, int n, double* r);
#define random_init(data, seed) random_lcg_init(data, seed)
#define random_uniform(data) random_lcg_uniform(data)
#define random_normal(data) random_lcg_normal(data)
#define random_uniform_simd(data, n, r) random_lcg_uniform_simd(data, n, r)
#define random_normal_simd(data, n, r) random_lcg_normal_simd(data, n, r)
#pragma omp end declare target
#else /* No RNG lib defined, use drand48 */
//#define _XOPEN_SOURCE 500
#include <stdlib.h>
typedef void* random_data;
double random_drand48_normal();
void random_drand48_uniform_simd(int n, double* r);
void random_drand48_normal_simd(int n, double* r);
#define random_init(data, seed) srand48(seed)
#define random_uniform(data) drand48()
#define random_normal(data) random_drand_normal()
#define random_uniform_simd(data, n, r) random_drand48_uniform_simd(n, r)
#define random_normal_simd(data, n, r) random_drand48_normal_simd(n, r)
#endif
#endif