libfoedus-core
FOEDUS Core Library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
foedus::assorted::UniformRandom Class Reference

A very simple and deterministic random generator that is more aligned with standard benchmark such as TPC-C. More...

Detailed Description

A very simple and deterministic random generator that is more aligned with standard benchmark such as TPC-C.

Actually this is exactly from TPC-C spec.

Definition at line 35 of file uniform_random.hpp.

#include <uniform_random.hpp>

Public Member Functions

 UniformRandom ()
 
 UniformRandom (uint64_t seed)
 
uint32_t uniform_within (uint32_t from, uint32_t to)
 In TPCC terminology, from=x, to=y. More...
 
uint32_t uniform_within_except (uint32_t from, uint32_t to, uint32_t except)
 Same as uniform_within() except it avoids the "except" value. More...
 
uint32_t non_uniform_within (uint32_t A, uint32_t from, uint32_t to)
 Non-Uniform random (NURand) in TPCC spec (see Sec 2.1.6). More...
 
uint64_t get_current_seed () const
 
void set_current_seed (uint64_t seed)
 
void fill_memory (foedus::memory::AlignedMemory *memory)
 Fill up the give memory with random data. More...
 
uint64_t next_uint64 ()
 
uint32_t next_uint32 ()
 

Constructor & Destructor Documentation

foedus::assorted::UniformRandom::UniformRandom ( )
inline

Definition at line 37 of file uniform_random.hpp.

37 : seed_(0) {}
foedus::assorted::UniformRandom::UniformRandom ( uint64_t  seed)
inlineexplicit

Definition at line 38 of file uniform_random.hpp.

38 : seed_(seed) {}

Member Function Documentation

void foedus::assorted::UniformRandom::fill_memory ( foedus::memory::AlignedMemory memory)

Fill up the give memory with random data.

Call this to pre-calculate many random numbers. When the function we test is very fast, generating random numbers might become the bottleneck. This method is to avoid it. Use this like following:

UniformRandom random(context->get_thread_id()); // or any other random seed
AlignedMemory memory;
CHECK_ERROR(context->get_thread_memory()->get_node_memory()->allocate_numa_memory(
(1 << 16) * sizeof(uint32_t), &memory));
random.fill_memory(&memory);
const uint32_t *randoms = reinterpret_cast<const uint32_t*>(memory.get_block());
<start the experiment timer>
for (int i = 0; i < TRIALS; ++i) {
uint32_t value = randoms[i & 0xFFFF];
...

Definition at line 23 of file uniform_random.cpp.

References foedus::memory::AlignedMemory::get_block(), foedus::memory::AlignedMemory::get_size(), and next_uint32().

23  {
24  uint32_t* ints = reinterpret_cast<uint32_t*>(memory->get_block());
25  uint64_t count = memory->get_size() / sizeof(uint32_t);
26  for (uint64_t i = 0; i < count; ++i) {
27  ints[i] = next_uint32();
28  }
29 }
void * get_block() const
Returns the memory block.
uint64_t get_size() const
Returns the byte size of the memory block.

Here is the call graph for this function:

uint64_t foedus::assorted::UniformRandom::get_current_seed ( ) const
inline

Definition at line 75 of file uniform_random.hpp.

Referenced by foedus::assorted::ZipfianRandom::get_current_seed().

75  {
76  return seed_;
77  }

Here is the caller graph for this function:

uint32_t foedus::assorted::UniformRandom::next_uint32 ( )
inline

Definition at line 106 of file uniform_random.hpp.

Referenced by foedus::storage::masstree::design_partition_first_parallel_recurse(), fill_memory(), foedus::assorted::ProbCounter::increment(), next_uint64(), uniform_within(), and foedus::assorted::SpinlockStat::yield_backoff().

106  {
107  seed_ = seed_ * 0xD04C3175 + 0x53DA9022;
108  return (seed_ >> 32) ^ (seed_ & 0xFFFFFFFF);
109  }

Here is the caller graph for this function:

uint64_t foedus::assorted::UniformRandom::next_uint64 ( )
inline

Definition at line 103 of file uniform_random.hpp.

References next_uint32().

103  {
104  return (static_cast<uint64_t>(next_uint32()) << 32) | next_uint32();
105  }

Here is the call graph for this function:

uint32_t foedus::assorted::UniformRandom::non_uniform_within ( uint32_t  A,
uint32_t  from,
uint32_t  to 
)
inline

Non-Uniform random (NURand) in TPCC spec (see Sec 2.1.6).

In TPCC terminology, from=x, to=y. NURand(A, x, y) = (((random(0, A) | random(x, y)) + C) % (y - x + 1)) + x

Definition at line 70 of file uniform_random.hpp.

References uniform_within().

70  {
71  uint32_t C = get_c(A);
72  return (((uniform_within(0, A) | uniform_within(from, to)) + C) % (to - from + 1)) + from;
73  }
uint32_t uniform_within(uint32_t from, uint32_t to)
In TPCC terminology, from=x, to=y.

Here is the call graph for this function:

void foedus::assorted::UniformRandom::set_current_seed ( uint64_t  seed)
inline

Definition at line 78 of file uniform_random.hpp.

Referenced by foedus::assorted::ZipfianRandom::init(), foedus::assorted::ZipfianRandom::set_current_seed(), foedus::thread::Thread::Thread(), and foedus::assorted::SpinlockStat::yield_backoff().

78  {
79  seed_ = seed;
80  }

Here is the caller graph for this function:

uint32_t foedus::assorted::UniformRandom::uniform_within ( uint32_t  from,
uint32_t  to 
)
inline

In TPCC terminology, from=x, to=y.

NOTE both from and to are inclusive.

Definition at line 44 of file uniform_random.hpp.

References ASSERT_ND, and next_uint32().

Referenced by foedus::storage::masstree::SplitBorder::decide_strategy(), foedus::assorted::ZipfianRandom::next(), non_uniform_within(), and uniform_within_except().

44  {
45  ASSERT_ND(from <= to);
46  if (from == to) {
47  return from;
48  }
49  return from + (next_uint32() % (to - from + 1));
50  }
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t foedus::assorted::UniformRandom::uniform_within_except ( uint32_t  from,
uint32_t  to,
uint32_t  except 
)
inline

Same as uniform_within() except it avoids the "except" value.

Make sure from!=to.

Definition at line 55 of file uniform_random.hpp.

References uniform_within().

55  {
56  while (true) {
57  uint32_t val = uniform_within(from, to);
58  if (val != except) {
59  return val;
60  }
61  }
62  }
uint32_t uniform_within(uint32_t from, uint32_t to)
In TPCC terminology, from=x, to=y.

Here is the call graph for this function:


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