37 namespace async_schedule_local {
47 struct sim_event_cmp :
public std::binary_function<sim_event, sim_event, bool>
49 inline bool operator () (
const sim_event& a,
const sim_event& b)
const
51 return a.timestamp > b.timestamp;
56 struct write_time_cmp :
public std::binary_function<write_time_pair, write_time_pair, bool>
60 return a.second > b.second;
67 if (disk == (
int_type)file::DEFAULT_DEVICE_ID)
69 assert(0 <= disk && disk <= D);
78 std::pair<int_type, int_type>* o_time)
80 typedef std::priority_queue<sim_event, std::vector<sim_event>, sim_event_cmp> event_queue_type;
81 typedef std::queue<int_type> disk_queue_type;
84 event_queue_type event_queue;
94 disk_queues[disk].push(i);
100 if (!disk_queues[ii].empty())
102 int_type j = disk_queues[ii].front();
103 disk_queues[ii].pop();
104 event_queue.push(sim_event(1, j));
108 while (!event_queue.empty())
110 sim_event cur = event_queue.top();
112 if (oldtime != cur.timestamp)
116 disk_busy[j] =
false;
118 oldtime = cur.timestamp;
121 STXXL_VERBOSE1(
"Block " << cur.iblock <<
" put out, time " << cur.timestamp <<
" disk: " << disks[cur.iblock]);
122 o_time[cur.iblock] = std::pair<int_type, int_type>(cur.iblock, cur.timestamp);
129 disk_queues[disk].push(i--);
133 if (!disk_queues[disk].empty())
135 STXXL_VERBOSE1(
"c Block " << disk_queues[disk].front() <<
" scheduled for time " << cur.timestamp + 1);
136 event_queue.push(sim_event(cur.timestamp + 1, disk_queues[disk].front()));
137 disk_queues[disk].pop();
141 STXXL_VERBOSE1(
"a Block " << i <<
" scheduled for time " << cur.timestamp + 1);
142 event_queue.push(sim_event(cur.timestamp + 1, i--));
144 disk_busy[disk] =
true;
150 if (!disk_busy[disk] && !disk_queues[disk].empty())
152 STXXL_VERBOSE1(
"b Block " << disk_queues[disk].front() <<
" scheduled for time " << cur.timestamp + 1);
153 event_queue.push(sim_event(cur.timestamp + 1, disk_queues[disk].front()));
154 disk_queues[disk].pop();
155 disk_busy[disk] =
true;
161 assert(disk_queues[j].empty());
163 return (oldtime - 1);
175 typedef std::pair<int_type, int_type> pair_type;
184 pair_type* write_order =
new pair_type[L];
191 STXXL_VERBOSE1(first[i] <<
" " << write_order[i].first <<
" " << write_order[i].second);
193 std::stable_sort(write_order, write_order + L, async_schedule_local::write_time_cmp()
_STXXL_FORCE_SEQUENTIAL);
197 out_first[i] = write_order[i].first;
202 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)
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)
Simpler non-growing vector without initialization.
double timestamp()
Returns number of seconds since the epoch, high resolution.
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