|
GGEMS
1.1
GPU GEant4-based Monte Carlo Simulations
|
Go to the documentation of this file.
42 #include <sys/types.h>
52 : pseudo_random_numbers_(nullptr),
55 GGcout(
"GGEMSPseudoRandomGenerator",
"GGEMSPseudoRandomGenerator", 3) <<
"GGEMSPseudoRandomGenerator creating..." <<
GGendl;
57 GGcout(
"GGEMSPseudoRandomGenerator",
"GGEMSPseudoRandomGenerator", 3) <<
"GGEMSPseudoRandomGenerator created!!!" <<
GGendl;
66 GGcout(
"GGEMSPseudoRandomGenerator",
"~GGEMSPseudoRandomGenerator", 3) <<
"GGEMSPseudoRandomGenerator erasing..." <<
GGendl;
78 GGcout(
"GGEMSPseudoRandomGenerator",
"~GGEMSPseudoRandomGenerator", 3) <<
"GGEMSPseudoRandomGenerator erased!!!" <<
GGendl;
89 if (CryptAcquireContext(&seedWin32, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) ==
FALSE) {
90 std::ostringstream oss(std::ostringstream::out);
91 char buffer_error[256];
92 oss <<
"Error finding a seed: " << strerror_s(buffer_error, 256, errno) << std::endl;
95 return static_cast<uint32_t
>(seedWin32);
98 GGint file_descriptor = ::open(
"/dev/urandom", O_RDONLY | O_NONBLOCK);
99 if (file_descriptor < 0) {
100 std::ostringstream oss( std::ostringstream::out );
101 oss <<
"Error opening the file '/dev/urandom': " << strerror(errno) << std::endl;
106 char seedArray[
sizeof(
GGuint)];
107 ssize_t bytes_read = ::read(file_descriptor,
reinterpret_cast<GGuint*
>(seedArray),
sizeof(
GGuint));
108 if (bytes_read == -1) {
109 std::ostringstream oss( std::ostringstream::out );
110 oss <<
"Error reading the file '/dev/urandom': " << strerror(errno) << std::endl;
113 ::close(file_descriptor);
114 GGuint *seedUInt =
reinterpret_cast<GGuint*
>(seedArray);
125 GGcout(
"GGEMSPseudoRandomGenerator",
"Initialize", 1) <<
"Initialization of GGEMSPseudoRandomGenerator..." <<
GGendl;
142 GGcout(
"GGEMSPseudoRandomGenerator",
"InitializeSeeds", 1) <<
"Initialization of seeds for each particles..." <<
GGendl;
145 std::mt19937 mt_gen(
seed_);
156 for (
GGsize i = 0; i < MAXIMUM_PARTICLES; ++i) {
175 GGcout(
"GGEMSPseudoRandomGenerator",
"AllocateRandom", 1) <<
"Allocation of random numbers..." <<
GGendl;
196 GGcout(
"GGEMSPseudoRandomGenerator",
"PrintInfos", 0) <<
"Printing infos about random" <<
GGendl;
197 GGcout(
"GGEMSPseudoRandomGenerator",
"PrintInfos", 0) <<
"Seed: " <<
seed_ <<
GGendl;
228 GGcout(
"GGEMSPseudoRandomGenerator",
"PrintInfos", 0) <<
"Device: " << opencl_manager.
GetDeviceName(device_index) <<
GGendl;
229 GGcout(
"GGEMSPseudoRandomGenerator",
"PrintInfos", 0) <<
"-------" <<
GGendl;
230 GGcout(
"GGEMSPseudoRandomGenerator",
"PrintInfos", 0) <<
"Random state of two first particles for JKISS engine:" <<
GGendl;
231 GGcout(
"GGEMSPseudoRandomGenerator",
"PrintInfos", 0) <<
" * state 0: " << state[0][0] <<
" " << state[1][0] <<
GGendl;
232 GGcout(
"GGEMSPseudoRandomGenerator",
"PrintInfos", 0) <<
" * state 1: " << state[0][1] <<
" " << state[1][1] <<
GGendl;
233 GGcout(
"GGEMSPseudoRandomGenerator",
"PrintInfos", 0) <<
" * state 2: " << state[0][2] <<
" " << state[1][2] <<
GGendl;
234 GGcout(
"GGEMSPseudoRandomGenerator",
"PrintInfos", 0) <<
" * state 3: " << state[0][3] <<
" " << state[1][3] <<
GGendl;
235 GGcout(
"GGEMSPseudoRandomGenerator",
"PrintInfos", 0) <<
" * state 4: " << state[0][4] <<
" " << state[1][4] <<
GGendl;
GGEMS class handling RAM memory.
void PrintInfos(void) const
printing infos about random
GGsize GetNumberOfActivatedDevice(void) const
get the number of activated devices
void Deallocate(cl::Buffer *buffer, GGsize size, GGsize const &thread_index, std::string const &class_name="Undefined")
Deallocation of OpenCL memory.
void ReleaseDeviceBuffer(cl::Buffer *const device_ptr, T *host_ptr, GGsize const &thread_index)
Get the device pointer on host to write on it. Mandatory after a GetDeviceBufferWrite ou GetDeviceBuf...
GGEMSPseudoRandomGenerator(void)
GGEMSPseudoRandomGenerator constructor.
void InitializeSeeds(void)
Initialize seeds for random.
GGuint prng_state_4_[MAXIMUM_PARTICLES]
GGuint prng_state_3_[MAXIMUM_PARTICLES]
GGsize number_activated_devices_
cl::Buffer * Allocate(void *host_ptr, GGsize const &size, GGsize const &thread_index, cl_mem_flags flags, std::string const &class_name="Undefined")
Allocation of OpenCL memory.
~GGEMSPseudoRandomGenerator(void)
GGEMSPseudoRandomGenerator destructor.
Structure storing the random buffers for both OpenCL and GGEMS.
GGuint prng_state_1_[MAXIMUM_PARTICLES]
Structure storing informations about random.
void Initialize(GGuint const &seed)
Initialize the Random object.
struct GGEMSRandom_t GGEMSRandom
GGEMS class handling the source(s)
T * GetDeviceBuffer(cl::Buffer *device_ptr, GGsize const &size, GGsize const &thread_index)
Get the device pointer on host to write on it. ReleaseDeviceBuffer must be used after this method!...
#define GGendl
overload C++ std::endl
Singleton class storing all informations about OpenCL and managing GPU/CPU devices,...
GGuint prng_state_5_[MAXIMUM_PARTICLES]
std::string GetDeviceName(GGsize const &device_index) const
Get the name of the activated device.
cl::Buffer ** pseudo_random_numbers_
Class managing the random number in GGEMS.
GGsize GetIndexOfActivatedDevice(GGsize const &thread_index) const
get the index of activated device
GGuint prng_state_2_[MAXIMUM_PARTICLES]
void AllocateRandom(void)
Allocate memory for random numbers.
void ThrowException(std::string const &class_name, std::string const &method_name, std::string const &message)
Throw a C++ exception.
static GGEMSOpenCLManager & GetInstance(void)
Create at first time the Singleton.
GGuint GenerateSeed(void) const
generate a seed by GGEMS and return it