forked from yanliu/pgap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysprng.c
48 lines (44 loc) · 1.48 KB
/
mysprng.c
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
/******************************************************************************
* mysprng.c: SPRNG wrapper *
* Author: Yan Y. Liu <[email protected]> *
* Date: 2014/08/17 *
* Copyright and license of this source file are specified in LICENSE.TXT *
* under the root directory of this software package. *
******************************************************************************/
#ifndef MYSPRNG_C
#define MYSPRNG_C
#include <stdio.h>
#include <stdlib.h>
#include "mysprng.h"
#ifdef PGAMODE
#include "mpi.h"
#endif
// global sprng stream
int * mysprng_stream;
// wrappers for sprng()
double mysprng() {
if (mysprng_stream == NULL) {
fprintf(stderr, "SPRNG stream is not initialized\n");
exit(0); // fatal error
} else {
return sprng(mysprng_stream);
}
}
// this func must be called after MPI_Init()
void mysprng_init() {
int gseed = make_sprng_seed();
#ifdef PGAMODE
int myrank, net_size;
MPI_Comm_rank( MPI_COMM_WORLD, &myrank );
MPI_Comm_size( MPI_COMM_WORLD, &net_size);
mysprng_stream = init_sprng(DEFAULT_RNG_TYPE, myrank, net_size, gseed, SPRNG_DEFAULT);
#else
mysprng_stream = init_sprng(DEFAULT_RNG_TYPE, 0, 1, gseed, SPRNG_DEFAULT);
#endif
return;
}
void mysprng_free() {
if (mysprng_stream == NULL) return;
free_sprng(mysprng_stream);
}
#endif