PSCF v1.2
Pscf::CudaRandom Class Reference

Random number generator on GPU. More...

#include <CudaRandom.h>

Public Member Functions

 CudaRandom ()
 Constructor.
 
virtual ~CudaRandom ()
 Destructor.
 
void setSeed (unsigned long long seed)
 Set value of random seed (private member variable seed_).
 
void uniform (DeviceArray< float > &data)
 Populate array on device with random floats in (0, 1], uniform dist.
 
void uniform (DeviceArray< double > &data)
 Populate array on device with random doubles in (0, 1], uniform dist.
 
void normal (DeviceArray< float > &data, float stddev, float mean=0.0)
 Populate array on device with normal-distributed random floats.
 
void normal (DeviceArray< double > &data, double stddev, double mean=0.0)
 Populate array on device with normal-distributed random doubles.
 
long seed ()
 Returns value of random seed (private member variable seed_).
 

Detailed Description

Random number generator on GPU.

The generator may be seeded either by reading a seed from file, using the readParam() method, or by using setSeed() to set or reset it explicitly. In either case, inputting a positive integer causes that value to be used as a seed, but inputting a value of 0 causes the use of a seed that is generated from the system clock.

Definition at line 29 of file CudaRandom.h.

Constructor & Destructor Documentation

◆ CudaRandom()

Pscf::CudaRandom::CudaRandom ( )

Constructor.

Definition at line 13 of file CudaRandom.cu.

◆ ~CudaRandom()

Pscf::CudaRandom::~CudaRandom ( )
virtual

Destructor.

Definition at line 27 of file CudaRandom.cu.

Member Function Documentation

◆ setSeed()

void Pscf::CudaRandom::setSeed ( unsigned long long seed)

Set value of random seed (private member variable seed_).

Parameters
seedvalue of random number generator seed.

Definition at line 35 of file CudaRandom.cu.

References seed().

Referenced by normal(), normal(), uniform(), and uniform().

◆ uniform() [1/2]

void Pscf::CudaRandom::uniform ( DeviceArray< float > & data)

Populate array on device with random floats in (0, 1], uniform dist.

Parameters
dataarray to populate

Definition at line 54 of file CudaRandom.cu.

References Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::cArray(), setSeed(), and UTIL_CHECK.

◆ uniform() [2/2]

void Pscf::CudaRandom::uniform ( DeviceArray< double > & data)

Populate array on device with random doubles in (0, 1], uniform dist.

Parameters
dataarray to populate

Definition at line 69 of file CudaRandom.cu.

References Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::cArray(), setSeed(), and UTIL_CHECK.

◆ normal() [1/2]

void Pscf::CudaRandom::normal ( DeviceArray< float > & data,
float stddev,
float mean = 0.0 )

Populate array on device with normal-distributed random floats.

Note: the input array must have an even number of elements. This is a requirement imposed by cuRAND, the random number generator software used by CudaRandom.

Parameters
dataarray to populate
stddevstandard deviation (input)
meanmean value (input, default = 0.0)

Definition at line 84 of file CudaRandom.cu.

References Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::cArray(), setSeed(), UTIL_CHECK, and UTIL_THROW.

◆ normal() [2/2]

void Pscf::CudaRandom::normal ( DeviceArray< double > & data,
double stddev,
double mean = 0.0 )

Populate array on device with normal-distributed random doubles.

Note: the input array must have an even number of elements. This is a requirement imposed by cuRAND, the random number generator software used by CudaRandom.

Parameters
dataarray to populate
stddevstandard deviation (input)
meanmean value (input, default = 0.0)

Definition at line 104 of file CudaRandom.cu.

References Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::cArray(), setSeed(), UTIL_CHECK, and UTIL_THROW.

◆ seed()

long Pscf::CudaRandom::seed ( )
inline

Returns value of random seed (private member variable seed_).

Returns
value of random number generator seed.

Definition at line 116 of file CudaRandom.h.

Referenced by setSeed().


The documentation for this class was generated from the following files: