STXXL  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
block_alloc_interleaved.h
Go to the documentation of this file.
1 /***************************************************************************
2  * include/stxxl/bits/mng/block_alloc_interleaved.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2002, 2003 Roman Dementiev <[email protected]>
7  * Copyright (C) 2007-2009, 2011 Andreas Beckmann <[email protected]>
8  *
9  * Distributed under the Boost Software License, Version 1.0.
10  * (See accompanying file LICENSE_1_0.txt or copy at
11  * http://www.boost.org/LICENSE_1_0.txt)
12  **************************************************************************/
13 
14 #ifndef STXXL_MNG_BLOCK_ALLOC_INTERLEAVED_HEADER
15 #define STXXL_MNG_BLOCK_ALLOC_INTERLEAVED_HEADER
16 
17 #include <vector>
18 
20 #include <stxxl/bits/common/rand.h>
21 
22 
24 
25 #define CHECK_RUN_BOUNDS(pos)
26 
28 {
29 protected:
33 
35  : nruns(nruns), begindisk(begindisk), diff(diff)
36  { }
37 
38 public:
39  interleaved_striping(int_type _nruns, const striping& strategy)
40  : nruns(_nruns), begindisk(strategy.begin), diff(strategy.diff)
41  { }
42 
43  unsigned_type operator () (unsigned_type i) const
44  {
45  return begindisk + (i / nruns) % diff;
46  }
47 };
48 
50 {
53 
54  interleaved_FR(int_type _nruns, const FR& strategy)
55  : interleaved_striping(_nruns, strategy.begin, strategy.diff)
56  { }
57 
58  unsigned_type operator () (unsigned_type /*i*/) const
59  {
60  return begindisk + rnd(rnd_type::value_type(diff));
61  }
62 };
63 
65 {
67  std::vector<int> offsets;
68 
69  interleaved_SR(int_type _nruns, const SR& strategy)
70  : interleaved_striping(_nruns, strategy.begin, strategy.diff)
71  {
72  rnd_type rnd;
73  for (int_type i = 0; i < nruns; i++)
74  offsets.push_back(rnd(rnd_type::value_type(diff)));
75  }
76 
77  unsigned_type operator () (unsigned_type i) const
78  {
79  return begindisk + (i / nruns + offsets[i % nruns]) % diff;
80  }
81 };
82 
83 
85 {
86  std::vector<std::vector<unsigned_type> > perms;
87 
88  interleaved_RC(int_type _nruns, const RC& strategy)
89  : interleaved_striping(_nruns, strategy.begin, strategy.diff),
90  perms(nruns, std::vector<unsigned_type>(diff))
91  {
92  for (int_type i = 0; i < nruns; i++)
93  {
94  for (unsigned_type j = 0; j < diff; j++)
95  perms[i][j] = j;
96 
98  std::random_shuffle(perms[i].begin(), perms[i].end(), rnd _STXXL_FORCE_SEQUENTIAL);
99  }
100  }
101 
102  unsigned_type operator () (unsigned_type i) const
103  {
104  return begindisk + perms[i % nruns][(i / nruns) % diff];
105  }
106 };
107 
109 {
110  first_disk_only(int_type _nruns, const single_disk& strategy)
111  : interleaved_striping(_nruns, strategy.disk, 1)
112  { }
113 
114  unsigned_type operator () (unsigned_type) const
115  {
116  return begindisk;
117  }
118 };
119 
120 template <typename scheme>
122 { };
123 
124 template <>
126 {
128 };
129 
130 template <>
132 {
134 };
135 
136 template <>
138 {
140 };
141 
142 template <>
144 {
146 };
147 
148 template <>
150 {
151  // FIXME! HACK!
153 };
154 
155 template <>
157 {
158  // FIXME! HACK!
160 };
161 
162 template <>
164 {
166 };
167 
169 
170 #endif // !STXXL_MNG_BLOCK_ALLOC_INTERLEAVED_HEADER
171 // vim: et:ts=4:sw=4
Fully randomized disk allocation scheme functor.
Definition: block_alloc.h:68
void random_shuffle(ExtIterator_ first, ExtIterator_ last, RandomNumberGenerator_ &rand, unsigned_type M, AllocStrategy_ AS=STXXL_DEFAULT_ALLOC_STRATEGY())
External equivalent of std::random_shuffle.
interleaved_SR(int_type _nruns, const SR &strategy)
random_number< random_uniform_fast > rnd_type
std::vector< std::vector< unsigned_type > > perms
&#39;Single disk&#39; disk allocation scheme functor.
Definition: block_alloc.h:197
External vector container. Introduction to vector container: see STXXL Vector tutorial. Design and Internals of vector container: see Vector.
Definition: vector.h:255
Randomized cycling disk allocation scheme functor.
Definition: block_alloc.h:131
choose_int_types< my_pointer_size >::int_type int_type
Definition: types.h:66
first_disk_only(int_type _nruns, const single_disk &strategy)
Striping disk allocation scheme functor.
Definition: block_alloc.h:42
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
interleaved_RC(int_type _nruns, const RC &strategy)
Simple randomized disk allocation scheme functor.
Definition: block_alloc.h:94
random_number< random_uniform_fast > rnd_type
interleaved_FR(int_type _nruns, const FR &strategy)
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
Definition: types.h:67
interleaved_striping(int_type nruns, unsigned_type begindisk, unsigned_type diff)
#define _STXXL_FORCE_SEQUENTIAL
Definition: parallel.h:51
interleaved_striping(int_type _nruns, const striping &strategy)
#define STXXL_END_NAMESPACE
Definition: namespace.h:17