imate
C++/CUDA Reference
|
A static class to generate random set of vectors. This class acts as a templated namespace, where all member methods are public and static. More...
#include <random_array_generator.h>
Static Public Member Functions | |
static void | generate_random_array (RandomNumberGenerator &random_number_generator, DataType *array, const LongIndexType array_size, const IndexType num_threads) |
Generates a pseudo-random array with Rademacher distribution where elements are either +1 or -1 . More... | |
A static class to generate random set of vectors. This class acts as a templated namespace, where all member methods are public and static.
Definition at line 37 of file random_array_generator.h.
|
static |
Generates a pseudo-random array with Rademacher distribution where elements are either +1
or -1
.
The Rademacher distribution is obtained from the Bernoulli distribution consisting of 0
and 1
. To generate such distribution, a sequence of array_size/64
intergers, each with 64-bit, is generated using Xoshiro256** algorithm. The 64 bits of each integer are used to fill 64 elements of the array as follows. If the bit is 0
, the array element is set to -1
, and if the bit is 1
, the array element is set to +1
.
Thus, in this function, we use Xoshiro256** algorithm to generate 64 bits and use bits, not the integer itself. This approach is about ten times faster than convertng the random integer to double between [0,1] and then map them to
+1
and -1
.
Also, this function is more than a hundered times faster than using rand()
function.
[in] | random_number_generator | The random number generator object. This object should be initialized with num_threads by its constructor. On each parallel thread, an independent sequence of random numbers are generated. |
[out] | array | 1D array of the size array_size . |
[out] | array_size | The size of the array. |
[in] | num_threads | Number of OpenMP parallel threads. If num_threads is zero then no paralel thread is created inside this function, rather it is assumed that this functon is called inside a parallel region from the caller. |
Definition at line 63 of file random_array_generator.cpp.
References RandomNumberGenerator::next().
Referenced by cTraceEstimator< DataType >::_c_stochastic_lanczos_quadrature(), cuTraceEstimator< DataType >::_cu_stochastic_lanczos_quadrature(), cuOrthogonalization< DataType >::orthogonalize_vectors(), and cOrthogonalization< DataType >::orthogonalize_vectors().