Commit 9a476f7b authored by Martin Perdacher's avatar Martin Perdacher

update random number generator

parent 70ba6f69
......@@ -57,7 +57,7 @@ int main(int argc, char** argv) {
if ( strcmp(filename,"" ) == 0) {
// printf("random_init\n");
random_init(x,N,D);
random_init_unif(x,N,D);
}else{
// printf("read_file\n");
read_file(x, N, D, filename, isBinary);
......
#include "dataIo.h"
void random_init(double *array, const int N, const int D){
void random_init_unif(double *array, const int N, const int D){
#pragma omp parallel
{
int tId = omp_get_thread_num();
short unsigned seed[3];
seed[0]=(((tId*tId + 15) * 3)/7);
seed[1]=(((tId*tId + 13) * 2)/3);
seed[2]=tId;
VSLStreamStatePtr stream;
const int SEED=(tId + 15) * 3;
const double LOWER_BOUND=0.0;
const double UPPER_BOUND=1.0;
int errcode = vslNewStream( &stream, VSL_BRNG_MCG31, SEED);
if ( errcode != VSL_ERROR_OK && errcode != VSL_STATUS_OK ){
printf("vslNewStream error. dataIo.cpp line 9.\n");
exit(1);
}
#pragma omp for collapse(2)
#pragma ivdep
#pragma omp for
for (int i = 0; i < N; i++){
for (int j = 0; j < D; j++)
array[i*N+j] = erand48(seed);
// generate D uniform distributed values
errcode = vdRngUniform(VSL_RNG_METHOD_UNIFORM_STD, stream, D, &array[i*N], LOWER_BOUND, UPPER_BOUND);
if ( errcode != VSL_ERROR_OK && errcode != VSL_STATUS_OK ){
printf("vslNewStream error. dataIo.cpp line 20.\n");
exit(1);
}
}
}
}
......
......@@ -8,9 +8,11 @@
#include <omp.h>
#include "mkl_vsl.h"
#define MAX_LINE_LENGTH 2049
void random_init(double *array, const int N, const int D);
void random_init_unif(double *array, const int N, const int D);
void read_file(double *array, const int N, const int D, char filename[], const bool IS_BINARY);
void save_binary_file(double *array, const int N, const int D, char filename[]);
void save_text_file(double *array, const int N, const int D, char filename[]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment