add seed to random number initialization

This commit is contained in:
Uldis Locans
2017-03-17 10:43:41 +01:00
parent c4e7029b5d
commit 1606b641d4
4 changed files with 7 additions and 6 deletions

View File

@ -41,14 +41,15 @@ CudaBase::~CudaBase() {
/* /*
create curandStates create curandStates
*/ */
int CudaBase::cuda_createCurandStates(int size) { int CudaBase::cuda_createCurandStates(int size, int seed) {
if (defaultRndSet == 1) if (defaultRndSet == 1)
cuda_deleteCurandStates(); cuda_deleteCurandStates();
int threads = 128; int threads = 128;
int blocks = size / threads + 1; int blocks = size / threads + 1;
int seed = time(NULL); if (seed == -1)
seed = time(NULL);
//std::cout << "sizeof: " << sizeof(curandState) << std::endl; //std::cout << "sizeof: " << sizeof(curandState) << std::endl;
cudaMalloc(&defaultRndState, sizeof(curandState)*size); cudaMalloc(&defaultRndState, sizeof(curandState)*size);

View File

@ -41,7 +41,7 @@ public:
* and create a curandState with different seed for each array entry. * and create a curandState with different seed for each array entry.
* Return success or error code * Return success or error code
*/ */
int cuda_createCurandStates(int size); int cuda_createCurandStates(int size, int seed = -1);
/** /**
* Delete curandState. * Delete curandState.

View File

@ -807,9 +807,9 @@ int DKSBase::callCollimatorPhysicsSortSoA(void *label_ptr, void *localID_ptr,
} }
int DKSBase::callInitRandoms(int size) { int DKSBase::callInitRandoms(int size, int seed) {
if (apiCuda()) if (apiCuda())
return CUDA_SAFECALL(cbase->cuda_createCurandStates(size)); return CUDA_SAFECALL(cbase->cuda_createCurandStates(size, seed));
else if (apiOpenCL()) else if (apiOpenCL())
return OPENCL_SAFECALL(oclbase->ocl_createRndStates(size)); return OPENCL_SAFECALL(oclbase->ocl_createRndStates(size));
else if (apiOpenMP()) else if (apiOpenMP())

View File

@ -1074,7 +1074,7 @@ public:
* Init random number states and save for reuse on device. * Init random number states and save for reuse on device.
* TODO: opencl and mic implementations. * TODO: opencl and mic implementations.
*/ */
int callInitRandoms(int size); int callInitRandoms(int size, int seed = -1);
/** /**
* Integration code from ParallelTTracker from OPAL. * Integration code from ParallelTTracker from OPAL.