[go: up one dir, main page]

Menu

[dc7c28]: / algo / gen_file.cpp  Maximize  Restore  History

Download this file

63 lines (47 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "stxxl/mng"
#include "stxxl/ksort"
#include "stxxl/vector"
using namespace stxxl;
struct my_type
{
typedef unsigned key_type;
key_type _key;
char _data[128 - sizeof(key_type)];
key_type key() const
{
return _key;
}
my_type() { };
my_type(key_type __key) : _key(__key) { };
static my_type min_value()
{
return my_type(0);
}
static my_type max_value()
{
return my_type(0xffffffff);
}
};
bool operator < (const my_type & a, const my_type & b)
{
return a.key() < b.key();
}
int main()
{
my_type::key_type max_key = 1 * 1024 * 1024;
unsigned int block_size = 1 * 1024 * 1024;
unsigned int records_in_block = block_size / sizeof(my_type);
my_type * array = (my_type *) aligned_alloc<BLOCK_ALIGN>(block_size);
syscall_file f("./in", file::CREAT | file::RDWR);
request_ptr req;
my_type::key_type cur_key = max_key;
for (unsigned i = 0; i < max_key / records_in_block; i++ )
{
for (unsigned j = 0; j < records_in_block; j++)
array[j]._key = cur_key--;
req = f.awrite((void *)array, stxxl::int64(i) * block_size, block_size, stxxl::default_completion_handler());
req->wait();
}
aligned_dealloc<BLOCK_ALIGN>(array);
return 0;
}