Randomness Generation

Header file: <libs/superdrops/urbg.hpp> [source]

template<class DeviceType>
struct URBG

Struct wrapping Kokkos random number generator.

Generates random numbers in the range [start, end]. Result equivalent to std::uniform_int_distribution with parameters [a, b] = [start, end], where g = C++11 UniformRandomBitGenerator (URBG). Useful e.g. for using urand(start, end) function of Kokkos random number generator ‘gen’ to generate random numbers for shuffling super-droplets array by swapping elements in range [start, end] (e.g, for linear sampling of super-droplet pairs in SDM collision algorithm).

Template Parameters:

DeviceType – The Kokkos device type.

Public Functions

inline uint64_t operator()(const uint64_t start, const uint64_t end)

Draws a random 64-bit unsigned integer (uint64_t) from a uniform distribution in the range [start, end].

Parameters:
  • start – The lower bound of the range.

  • end – The upper bound of the range.

Returns:

The random 8-byte unsigned integer.

inline double drand(const double start, const double end)

Draws a random number (double) from a uniform distribution in the range [start, end].

Parameters:
  • start – The lower bound of the range.

  • end – The upper bound of the range.

Returns:

The random double.

Public Members

Kokkos::Random_XorShift64<DeviceType> gen

Kokkos random number generator

inline void device_swap(Superdrop &a, Superdrop &b)

Swaps the values of two super-droplets.

Equivalent to C++98 std::swap but works on device as well as host (gpu compatible).

Note: Involves a copy construction and two assignment operations, which may not be efficient if Superdrop class stores large quantities of data.

Parameters:
  • a – The first super-droplet.

  • b – The second super-droplet.

template<class DeviceType>
inline viewd_supers shuffle_supers(const viewd_supers supers, URBG<DeviceType> urbg)

Shuffles the order of super-droplets in a view.

Randomly shuffles the order of super-droplets using the URBG (Uniform Random Bit Generator) struct (on device).

Template Parameters:

DeviceType – The Kokkos device type.

Parameters:
  • supers – The view of super-droplets to shuffle.

  • urbg – The random number generator.

Returns:

The shuffled view of super-droplets.

inline viewd_supers one_shuffle_supers(const TeamMember &team_member, const viewd_supers supers, const GenRandomPool genpool)

Randomly shuffles the order of super-droplet objects in a view using a single thread in a Kokkos team (i.e. a single team member).

Uses only one member of a Kokkos team to randomly shuffle the order of super-droplet objects in the ‘supers’ view. Then synchronizes the team and returns the view of shuffled super-droplets. Uses Kokkos thread safe random number generator from pool.

Parameters:
  • team_member – The Kokkos team member.

  • supers – The view of superdroplets to shuffle.

  • genpool – The random number generator pool.

Returns:

The shuffled view of superdroplets.