Stxxl  1.3.2
async_schedule.h
1 /***************************************************************************
2  * include/stxxl/bits/algo/async_schedule.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2002 Roman Dementiev <[email protected]>
7  * Copyright (C) 2009 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 // Implements the "prudent prefetching" as described in
15 // D. Hutchinson, P. Sanders, J. S. Vitter: Duality between prefetching
16 // and queued writing on parallel disks, 2005
17 // DOI: 10.1137/S0097539703431573
18 
19 
20 #ifndef STXXL_ASYNC_SCHEDULE_HEADER
21 #define STXXL_ASYNC_SCHEDULE_HEADER
22 
23 #include <stxxl/bits/common/types.h>
24 
25 
26 __STXXL_BEGIN_NAMESPACE
27 
28 void compute_prefetch_schedule(
29  const int_type * first,
30  const int_type * last,
31  int_type * out_first,
32  int_type m,
33  int_type D);
34 
35 inline void compute_prefetch_schedule(
36  int_type * first,
37  int_type * last,
38  int_type * out_first,
39  int_type m,
40  int_type D)
41 {
42  compute_prefetch_schedule(static_cast<const int_type *>(first), last, out_first, m, D);
43 }
44 
45 template <typename run_type>
46 void compute_prefetch_schedule(
47  const run_type & input,
48  int_type * out_first,
49  int_type m,
50  int_type D)
51 {
52  const int_type L = input.size();
53  int_type * disks = new int_type[L];
54  for (int_type i = 0; i < L; ++i)
55  disks[i] = input[i].bid.storage->get_physical_device_id();
56  compute_prefetch_schedule(disks, disks + L, out_first, m, D);
57  delete[] disks;
58 }
59 
60 template <typename bid_iterator_type>
61 void compute_prefetch_schedule(
62  bid_iterator_type input_begin,
63  bid_iterator_type input_end,
64  int_type * out_first,
65  int_type m,
66  int_type D)
67 {
68  const int_type L = input_end - input_begin;
69  int_type * disks = new int_type[L];
70  int_type i = 0;
71  for (bid_iterator_type it = input_begin; it != input_end; ++it, ++i)
72  disks[i] = it->storage->get_physical_device_id();
73  compute_prefetch_schedule(disks, disks + L, out_first, m, D);
74  delete[] disks;
75 }
76 
77 __STXXL_END_NAMESPACE
78 
79 #endif // !STXXL_ASYNC_SCHEDULE_HEADER
80 // vim: et:ts=4:sw=4