38 namespace async_schedule_local {
48 struct sim_event_cmp :
public std::binary_function<sim_event, sim_event, bool>
50 inline bool operator () (
const sim_event& a,
const sim_event& b)
const
52 return a.timestamp > b.timestamp;
57 struct write_time_cmp :
public std::binary_function<write_time_pair, write_time_pair, bool>
61 return a.second > b.second;
69 if (disk == file::NO_ALLOCATOR)
71 assert(0 <= disk && disk <= D);
80 std::pair<int_type, int_type>* o_time)
82 typedef std::priority_queue<sim_event, std::vector<sim_event>, sim_event_cmp> event_queue_type;
83 typedef std::queue<int_type> disk_queue_type;
85 disk_queue_type*
disk_queues =
new disk_queue_type[D + 1];
86 event_queue_type event_queue;
91 bool* disk_busy =
new bool[D + 1];
96 disk_queues[disk].push(i);
101 for (
int_type ii = 0; ii <= D; ii++)
102 if (!disk_queues[ii].empty())
104 int_type j = disk_queues[ii].front();
105 disk_queues[ii].pop();
106 event_queue.push(sim_event(1, j));
110 while (!event_queue.empty())
112 sim_event cur = event_queue.top();
114 if (oldtime != cur.timestamp)
118 disk_busy[i] =
false;
120 oldtime = cur.timestamp;
124 STXXL_VERBOSE1(
"Block " << cur.iblock <<
" put out, time " << cur.timestamp <<
" disk: " << disks[cur.iblock]);
125 o_time[cur.iblock] = std::pair<int_type, int_type>(cur.iblock, cur.timestamp);
132 disk_queues[disk].push(i--);
136 if (!disk_queues[disk].empty())
138 STXXL_VERBOSE1(
"c Block " << disk_queues[disk].front() <<
" scheduled for time " << cur.timestamp + 1);
139 event_queue.push(sim_event(cur.timestamp + 1, disk_queues[disk].front()));
140 disk_queues[disk].pop();
144 STXXL_VERBOSE1(
"a Block " << i <<
" scheduled for time " << cur.timestamp + 1);
145 event_queue.push(sim_event(cur.timestamp + 1, i--));
147 disk_busy[disk] =
true;
153 if (!disk_busy[disk] && !disk_queues[disk].empty())
155 STXXL_VERBOSE1(
"b Block " << disk_queues[disk].front() <<
" scheduled for time " << cur.timestamp + 1);
156 event_queue.push(sim_event(cur.timestamp + 1, disk_queues[disk].front()));
157 disk_queues[disk].pop();
158 disk_busy[disk] =
true;
164 assert(disk_queues[i].empty());
168 delete[] disk_queues;
170 return (oldtime - 1);
183 typedef std::pair<int_type, int_type> pair_type;
192 pair_type* write_order =
new pair_type[L];
199 STXXL_VERBOSE1(first[i] <<
" " << write_order[i].first <<
" " << write_order[i].second);
201 std::stable_sort(write_order, write_order + L, async_schedule_local::write_time_cmp()
_STXXL_FORCE_SEQUENTIAL);
205 out_first[i] = write_order[i].first;
210 delete[] write_order;
std::pair< int_type, int_type > write_time_pair
Encapsulates disk queues.
static int_type get_disk(int_type i, const int_type *disks, int_type D)
double timestamp()
Returns number of seconds since the epoch, high resolution.
choose_int_types< my_pointer_size >::int_type int_type
#define STXXL_BEGIN_NAMESPACE
void STXXL_UNUSED(const U &)
#define STXXL_VERBOSE1(x)
int_type simulate_async_write(const int_type *disks, const int_type L, const int_type m_init, const int_type D, std::pair< int_type, int_type > *o_time)
void compute_prefetch_schedule(const int_type *first, const int_type *last, int_type *out_first, int_type m, int_type D)
#define _STXXL_FORCE_SEQUENTIAL
#define STXXL_END_NAMESPACE