Newer
Older
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
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define MB 262144
typedef struct { uint64_t state; uint64_t inc; } pcg32_random_t;
uint32_t pcg32_random_r(pcg32_random_t* rng)
{
uint64_t oldstate = rng->state;
// Advance internal state
rng->state = oldstate * 6364136223846793005ULL + (rng->inc|1);
// Calculate output function (XSH RR), uses old state for max ILP
uint32_t xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u;
uint32_t rot = oldstate >> 59u;
return (xorshifted >> rot) | (xorshifted << ((-rot) & 31));
}
int main(int argc, char **argv)
{
int j,jmax=0;
if (argc >1) jmax = atoi(argv[1]);
#pragma omp parallel for default(none) shared(jmax,stdout) private(j) schedule(dynamic,1)
for (j=0; j<jmax; j++)
{
uint32_t rndval[MB];
int i;
pcg32_random_t rng;
for(i=0; i<MB; i+=1)
rndval[i]=pcg32_random_r(&rng);
#pragma omp critical
fwrite(rndval,4,MB,stdout);
}
return(0);
}