Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
block_alloc_strategy_interleaved.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * foxxll/mng/block_alloc_strategy_interleaved.hpp
3  *
4  * include/foxxll/mng/block_alloc_interleaved.h
5  *
6  * Part of FOXXLL. See http://foxxll.org
7  *
8  * Copyright (C) 2002, 2003 Roman Dementiev <[email protected]>
9  * Copyright (C) 2007-2009, 2011 Andreas Beckmann <[email protected]>
10  *
11  * Distributed under the Boost Software License, Version 1.0.
12  * (See accompanying file LICENSE_1_0.txt or copy at
13  * http://www.boost.org/LICENSE_1_0.txt)
14  **************************************************************************/
15 
16 #ifndef FOXXLL_MNG_BLOCK_ALLOC_STRATEGY_INTERLEAVED_HEADER
17 #define FOXXLL_MNG_BLOCK_ALLOC_STRATEGY_INTERLEAVED_HEADER
18 
19 #include <random>
20 #include <vector>
21 
23 
24 namespace foxxll {
25 
26 #define CHECK_RUN_BOUNDS(pos)
27 
29 {
30 protected:
31  int nruns_;
32  size_t begin_disk_;
33  size_t diff_;
34 
35  interleaved_striping(int nruns, size_t begin_disk, size_t diff)
36  : nruns_(nruns), begin_disk_(begin_disk), diff_(diff)
37  { }
38 
39 public:
40  interleaved_striping(int nruns, const striping& strategy)
41  : nruns_(nruns), begin_disk_(strategy.begin_), diff_(strategy.diff_)
42  { }
43 
44  size_t operator () (size_t i) const
45  {
46  return begin_disk_ + (i / nruns_) % diff_;
47  }
48 };
49 
51 {
52  mutable std::default_random_engine rng_ { std::random_device { } () };
53 
54  interleaved_fully_random(int nruns, const fully_random& strategy)
55  : interleaved_striping(nruns, strategy.begin_, strategy.diff_)
56  { }
57 
58  size_t operator () (size_t /* i */) const
59  {
60  return begin_disk_ + rng_() % diff_;
61  }
62 };
63 
65 {
66  std::vector<size_t> offsets_;
67 
68  interleaved_simple_random(int nruns, const simple_random& strategy)
69  : interleaved_striping(nruns, strategy.begin_, strategy.diff_)
70  {
71  std::default_random_engine rng { std::random_device { } () };
72  for (int i = 0; i < nruns; i++)
73  offsets_.push_back(rng() % diff_);
74  }
75 
76  size_t operator () (size_t i) const
77  {
78  return begin_disk_ + (i / nruns_ + offsets_[i % nruns_]) % diff_;
79  }
80 };
81 
83 {
84  std::vector<std::vector<size_t> > perms_;
85 
86  interleaved_random_cyclic(int nruns, const random_cyclic& strategy)
87  : interleaved_striping(nruns, strategy.begin_, strategy.diff_),
88  perms_(nruns, std::vector<size_t>(diff_))
89  {
90  for (int i = 0; i < nruns; i++)
91  {
92  for (size_t j = 0; j < diff_; j++)
93  perms_[i][j] = j;
94 
95  std::random_shuffle(perms_[i].begin(), perms_[i].end());
96  }
97  }
98 
99  size_t operator () (size_t i) const
100  {
101  return begin_disk_ + perms_[i % nruns_][(i / nruns_) % diff_];
102  }
103 };
104 
106 {
107  first_disk_only(int nruns, const single_disk& strategy)
108  : interleaved_striping(nruns, strategy.disk_, 1)
109  { }
110 
111  size_t operator () (size_t) const
112  {
113  return begin_disk_;
114  }
115 };
116 
117 template <typename scheme>
119 { };
120 
121 template <>
123 {
125 };
126 
127 template <>
129 {
131 };
132 
133 template <>
135 {
137 };
138 
139 template <>
141 {
143 };
144 
145 template <>
147 {
148  // FIXME! HACK!
150 };
151 
152 template <>
154 {
155  // FIXME! HACK!
157 };
158 
159 template <>
161 {
163 };
164 
165 } // namespace foxxll
166 
167 #endif // !FOXXLL_MNG_BLOCK_ALLOC_STRATEGY_INTERLEAVED_HEADER
168 
169 /**************************************************************************/
interleaved_striping(int nruns, const striping &strategy)
interleaved_random_cyclic(int nruns, const random_cyclic &strategy)
first_disk_only(int nruns, const single_disk &strategy)
interleaved_fully_random(int nruns, const fully_random &strategy)
std::vector< T, Allocator< T > > vector
vector with Manager tracking
Definition: allocator.hpp:228
std::vector< std::vector< size_t > > perms_
interleaved_simple_random(int nruns, const simple_random &strategy)
interleaved_striping(int nruns, size_t begin_disk, size_t diff)