[go: up one dir, main page]

Menu

[461a73]: / io / test_io.cpp  Maximize  Restore  History

Download this file

93 lines (73 with data), 3.1 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/***************************************************************************
* io/test_io.cpp
*
* Part of the STXXL. See http://stxxl.sourceforge.net
*
* Copyright (C) 2002 Roman Dementiev <dementiev@mpi-sb.mpg.de>
* Copyright (C) 2008, 2009 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
**************************************************************************/
#include <limits>
#include <stxxl/io>
#include <stxxl/aligned_alloc>
//! \example io/test_io.cpp
//! This is an example of use of \c \<stxxl\> files, requests, and
//! completion tracking mechanisms, i.e. \c stxxl::file , \c stxxl::request
using stxxl::file;
struct my_handler
{
void operator () (stxxl::request * ptr)
{
STXXL_MSG("Request completed: " << ptr);
}
};
int main(int argc, char ** argv)
{
if (argc < 2)
{
std::cout << "Usage: " << argv[0] << " tempdir" << std::endl;
return -1;
}
std::string tempfilename[2];
tempfilename[0] = std::string(argv[1]) + "/test_io_1.dat";
tempfilename[1] = std::string(argv[1]) + "/test_io_2.dat";
std::cout << sizeof(void *) << std::endl;
const int size = 1024 * 384;
char * buffer = (char *)stxxl::aligned_alloc<4096>(size);
memset(buffer, 0, size);
#ifndef BOOST_MSVC
stxxl::mmap_file file1(tempfilename[0], file::CREAT | file::RDWR /* | file::DIRECT */, 0);
file1.set_size(size * 1024);
#endif
stxxl::syscall_file file2(tempfilename[1], file::CREAT | file::RDWR /* | file::DIRECT */, 1);
stxxl::request_ptr req[16];
unsigned i;
for (i = 0; i < 16; i++)
req[i] = file2.awrite(buffer, i * size, size, my_handler());
wait_all(req, 16);
// check behaviour of having requests to the same location at the same time
for (i = 2; i < 16; i++)
req[i] = file2.awrite(buffer, 0, size, my_handler());
req[0] = file2.aread(buffer, 0, size, my_handler());
req[1] = file2.awrite(buffer, 0, size, my_handler());
wait_all(req, 16);
stxxl::aligned_dealloc<4096>(buffer);
std::cout << *(stxxl::stats::get_instance());
stxxl::uint64 sz;
for (sz = 123, i = 0; i < 20; ++i, sz *= 10)
STXXL_MSG(">>>" << stxxl::add_SI_multiplier(sz) << "<<<");
for (sz = 123, i = 0; i < 20; ++i, sz *= 10)
STXXL_MSG(">>>" << stxxl::add_SI_multiplier(sz, "B") << "<<<");
STXXL_MSG(">>>" << stxxl::add_SI_multiplier((std::numeric_limits<stxxl::uint64>::max)(), "B") << "<<<");
for (sz = 123, i = 0; i < 20; ++i, sz *= 10)
STXXL_MSG(">>>" << stxxl::add_IEC_binary_multiplier(sz) << "<<<");
for (sz = 123, i = 0; i < 20; ++i, sz *= 10)
STXXL_MSG(">>>" << stxxl::add_IEC_binary_multiplier(sz, "B") << "<<<");
STXXL_MSG(">>>" << stxxl::add_IEC_binary_multiplier((std::numeric_limits<stxxl::uint64>::max)(), "B") << "<<<");
unlink(tempfilename[0].c_str());
unlink(tempfilename[1].c_str());
return 0;
}