STXXL  1.4.1
 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 
23 
24 #define CHECK_RUN_BOUNDS(pos)
25 
27 {
28 protected:
32 
34  : nruns(nruns), begindisk(begindisk), diff(diff)
35  { }
36 
37 public:
38  interleaved_striping(int_type _nruns, const striping& strategy)
39  : nruns(_nruns), begindisk(strategy.begin), diff(strategy.diff)
40  { }
41 
42  unsigned_type operator () (unsigned_type i) const
43  {
44  return begindisk + (i / nruns) % diff;
45  }
46 };
47 
49 {
52 
53  interleaved_FR(int_type _nruns, const FR& strategy)
54  : interleaved_striping(_nruns, strategy.begin, strategy.diff)
55  { }
56 
57  unsigned_type operator () (unsigned_type /*i*/) const
58  {
59  return begindisk + rnd(rnd_type::value_type(diff));
60  }
61 };
62 
64 {
66  std::vector<int> offsets;
67 
68  interleaved_SR(int_type _nruns, const SR& strategy)
69  : interleaved_striping(_nruns, strategy.begin, strategy.diff)
70  {
71  rnd_type rnd;
72  for (int_type i = 0; i < nruns; i++)
73  offsets.push_back(rnd(rnd_type::value_type(diff)));
74  }
75 
76  unsigned_type operator () (unsigned_type i) const
77  {
78  return begindisk + (i / nruns + offsets[i % nruns]) % diff;
79  }
80 };
81 
83 {
84  std::vector<std::vector<unsigned_type> > perms;
85 
86  interleaved_RC(int_type _nruns, const RC& strategy)
87  : interleaved_striping(_nruns, strategy.begin, strategy.diff),
88  perms(nruns, std::vector<unsigned_type>(diff))
89  {
90  for (int_type i = 0; i < nruns; i++)
91  {
92  for (unsigned_type j = 0; j < diff; j++)
93  perms[i][j] = j;
94 
96  std::random_shuffle(perms[i].begin(), perms[i].end(), rnd _STXXL_FORCE_SEQUENTIAL);
97  }
98  }
99 
100  unsigned_type operator () (unsigned_type i) const
101  {
102  return begindisk + perms[i % nruns][(i / nruns) % diff];
103  }
104 };
105 
107 {
108  first_disk_only(int_type _nruns, const single_disk& strategy)
109  : interleaved_striping(_nruns, strategy.disk, 1)
110  { }
111 
112  unsigned_type operator () (unsigned_type) const
113  {
114  return begindisk;
115  }
116 };
117 
118 template <typename scheme>
120 { };
121 
122 template <>
124 {
126 };
127 
128 template <>
130 {
132 };
133 
134 template <>
136 {
138 };
139 
140 template <>
142 {
144 };
145 
146 template <>
148 {
149  // FIXME! HACK!
151 };
152 
153 template <>
155 {
156  // FIXME! HACK!
158 };
159 
160 template <>
162 {
164 };
165 
167 
168 #endif // !STXXL_MNG_BLOCK_ALLOC_INTERLEAVED_HEADER
169 // vim: et:ts=4:sw=4
Fully randomized disk allocation scheme functor.
Definition: block_alloc.h:67
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:196
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:130
choose_int_types< my_pointer_size >::int_type int_type
Definition: types.h:63
void random_shuffle(ExtIterator first, ExtIterator last, RandomNumberGenerator &rand, unsigned_type M, AllocStrategy AS=STXXL_DEFAULT_ALLOC_STRATEGY())
External equivalent of std::random_shuffle.
first_disk_only(int_type _nruns, const single_disk &strategy)
Striping disk allocation scheme functor.
Definition: block_alloc.h:41
#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:93
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:64
interleaved_striping(int_type nruns, unsigned_type begindisk, unsigned_type diff)
#define _STXXL_FORCE_SEQUENTIAL
Definition: parallel.h:50
interleaved_striping(int_type _nruns, const striping &strategy)
#define STXXL_END_NAMESPACE
Definition: namespace.h:17