Stxxl
1.4.0
|
00001 /*************************************************************************** 00002 * include/stxxl/bits/mng/block_alloc_interleaved.h 00003 * 00004 * Part of the STXXL. See http://stxxl.sourceforge.net 00005 * 00006 * Copyright (C) 2002, 2003 Roman Dementiev <dementiev@mpi-sb.mpg.de> 00007 * Copyright (C) 2007-2009, 2011 Andreas Beckmann <beckmann@cs.uni-frankfurt.de> 00008 * 00009 * Distributed under the Boost Software License, Version 1.0. 00010 * (See accompanying file LICENSE_1_0.txt or copy at 00011 * http://www.boost.org/LICENSE_1_0.txt) 00012 **************************************************************************/ 00013 00014 #ifndef STXXL_INTERLEAVED_ALLOC_HEADER 00015 #define STXXL_INTERLEAVED_ALLOC_HEADER 00016 00017 #include <vector> 00018 00019 #include <stxxl/bits/mng/mng.h> 00020 #include <stxxl/bits/common/rand.h> 00021 00022 00023 __STXXL_BEGIN_NAMESPACE 00024 00025 #define CHECK_RUN_BOUNDS(pos) 00026 00027 struct interleaved_striping 00028 { 00029 protected: 00030 int_type nruns; 00031 int begindisk; 00032 int diff; 00033 00034 interleaved_striping(int_type nruns, int begindisk, int diff) 00035 : nruns(nruns), begindisk(begindisk), diff(diff) 00036 { } 00037 00038 public: 00039 interleaved_striping(int_type _nruns, const striping & strategy) 00040 : nruns(_nruns), begindisk(strategy.begin), diff(strategy.diff) 00041 { } 00042 00043 int operator () (int_type i) const 00044 { 00045 return begindisk + (i / nruns) % diff; 00046 } 00047 }; 00048 00049 struct interleaved_FR : public interleaved_striping 00050 { 00051 random_number<random_uniform_fast> rnd; 00052 00053 interleaved_FR(int_type _nruns, const FR & strategy) 00054 : interleaved_striping(_nruns, strategy.begin, strategy.diff) 00055 { } 00056 00057 int operator () (int_type /*i*/) const 00058 { 00059 return begindisk + rnd(diff); 00060 } 00061 }; 00062 00063 struct interleaved_SR : public interleaved_striping 00064 { 00065 std::vector<int> offsets; 00066 00067 interleaved_SR(int_type _nruns, const SR & strategy) 00068 : interleaved_striping(_nruns, strategy.begin, strategy.diff) 00069 { 00070 random_number<random_uniform_fast> rnd; 00071 for (int_type i = 0; i < nruns; i++) 00072 offsets.push_back(rnd(diff)); 00073 } 00074 00075 int operator () (int_type i) const 00076 { 00077 return begindisk + (i / nruns + offsets[i % nruns]) % diff; 00078 } 00079 }; 00080 00081 00082 struct interleaved_RC : public interleaved_striping 00083 { 00084 std::vector<std::vector<int> > perms; 00085 00086 interleaved_RC(int_type _nruns, const RC & strategy) 00087 : interleaved_striping(_nruns, strategy.begin, strategy.diff), 00088 perms(nruns, std::vector<int>(diff)) 00089 { 00090 for (int_type i = 0; i < nruns; i++) 00091 { 00092 for (int j = 0; j < diff; j++) 00093 perms[i][j] = j; 00094 00095 random_number<random_uniform_fast> rnd; 00096 std::random_shuffle(perms[i].begin(), perms[i].end(), rnd _STXXL_FORCE_SEQUENTIAL); 00097 } 00098 } 00099 00100 int operator () (int_type i) const 00101 { 00102 return begindisk + perms[i % nruns][(i / nruns) % diff]; 00103 } 00104 }; 00105 00106 struct first_disk_only : public interleaved_striping 00107 { 00108 first_disk_only(int_type _nruns, const single_disk & strategy) 00109 : interleaved_striping(_nruns, strategy.disk, 1) 00110 { } 00111 00112 int operator () (int_type) const 00113 { 00114 return begindisk; 00115 } 00116 }; 00117 00118 template <typename scheme> 00119 struct interleaved_alloc_traits 00120 { }; 00121 00122 template <> 00123 struct interleaved_alloc_traits<striping> 00124 { 00125 typedef interleaved_striping strategy; 00126 }; 00127 00128 template <> 00129 struct interleaved_alloc_traits<FR> 00130 { 00131 typedef interleaved_FR strategy; 00132 }; 00133 00134 template <> 00135 struct interleaved_alloc_traits<SR> 00136 { 00137 typedef interleaved_SR strategy; 00138 }; 00139 00140 template <> 00141 struct interleaved_alloc_traits<RC> 00142 { 00143 typedef interleaved_RC strategy; 00144 }; 00145 00146 template <> 00147 struct interleaved_alloc_traits<RC_disk> 00148 { 00149 // FIXME! HACK! 00150 typedef interleaved_RC strategy; 00151 }; 00152 00153 template <> 00154 struct interleaved_alloc_traits<RC_flash> 00155 { 00156 // FIXME! HACK! 00157 typedef interleaved_RC strategy; 00158 }; 00159 00160 template <> 00161 struct interleaved_alloc_traits<single_disk> 00162 { 00163 typedef first_disk_only strategy; 00164 }; 00165 00166 __STXXL_END_NAMESPACE 00167 00168 #endif // !STXXL_INTERLEAVED_ALLOC_HEADER 00169 // vim: et:ts=4:sw=4