Stxxl  1.4.0
io/test_io.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *  io/test_io.cpp
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright (C) 2002 Roman Dementiev <dementiev@mpi-sb.mpg.de>
00007  *  Copyright (C) 2008, 2009 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
00008  *
00009  *  Distributed under the Boost Software License, Version 1.0.
00010  *  (See accompanying file LICENSE_1_0.txt or copy at
00011  *  http://www.boost.org/LICENSE_1_0.txt)
00012  **************************************************************************/
00013 
00014 #include <limits>
00015 #include <stxxl/io>
00016 #include <stxxl/aligned_alloc>
00017 
00018 //! \example io/test_io.cpp
00019 //! This is an example of use of \c <stxxl> files, requests, and
00020 //! completion tracking mechanisms, i.e. \c stxxl::file , \c stxxl::request
00021 
00022 using stxxl::file;
00023 
00024 
00025 struct my_handler
00026 {
00027     void operator () (stxxl::request * ptr)
00028     {
00029         STXXL_MSG("Request completed: " << ptr);
00030     }
00031 };
00032 
00033 int main(int argc, char ** argv)
00034 {
00035     if (argc < 2)
00036     {
00037         std::cout << "Usage: " << argv[0] << " tempdir" << std::endl;
00038         return -1;
00039     }
00040 
00041     std::string tempfilename[2];
00042     tempfilename[0] = std::string(argv[1]) + "/test_io_1.dat";
00043     tempfilename[1] = std::string(argv[1]) + "/test_io_2.dat";
00044 
00045     std::cout << sizeof(void *) << std::endl;
00046     const int size = 1024 * 384;
00047     char * buffer = (char *)stxxl::aligned_alloc<4096>(size);
00048     memset(buffer, 0, size);
00049 
00050 #ifndef BOOST_MSVC
00051     stxxl::mmap_file file1(tempfilename[0], file::CREAT | file::RDWR /* | file::DIRECT */, 0);
00052     file1.set_size(size * 1024);
00053 #endif
00054 
00055     stxxl::syscall_file file2(tempfilename[1], file::CREAT | file::RDWR /* | file::DIRECT */, 1);
00056 
00057     stxxl::request_ptr req[16];
00058     unsigned i;
00059     for (i = 0; i < 16; i++)
00060         req[i] = file2.awrite(buffer, i * size, size, my_handler());
00061 
00062     wait_all(req, 16);
00063 
00064     // check behaviour of having requests to the same location at the same time
00065     for (i = 2; i < 16; i++)
00066         req[i] = file2.awrite(buffer, 0, size, my_handler());
00067     req[0] = file2.aread(buffer, 0, size, my_handler());
00068     req[1] = file2.awrite(buffer, 0, size, my_handler());
00069 
00070     wait_all(req, 16);
00071 
00072     stxxl::aligned_dealloc<4096>(buffer);
00073 
00074     std::cout << *(stxxl::stats::get_instance());
00075 
00076     stxxl::uint64 sz;
00077     for (sz = 123, i = 0; i < 20; ++i, sz *= 10)
00078         STXXL_MSG(">>>" << stxxl::add_SI_multiplier(sz) << "<<<");
00079     for (sz = 123, i = 0; i < 20; ++i, sz *= 10)
00080         STXXL_MSG(">>>" << stxxl::add_SI_multiplier(sz, "B") << "<<<");
00081     STXXL_MSG(">>>" << stxxl::add_SI_multiplier((std::numeric_limits<stxxl::uint64>::max)(), "B") << "<<<");
00082     for (sz = 123, i = 0; i < 20; ++i, sz *= 10)
00083         STXXL_MSG(">>>" << stxxl::add_IEC_binary_multiplier(sz) << "<<<");
00084     for (sz = 123, i = 0; i < 20; ++i, sz *= 10)
00085         STXXL_MSG(">>>" << stxxl::add_IEC_binary_multiplier(sz, "B") << "<<<");
00086     STXXL_MSG(">>>" << stxxl::add_IEC_binary_multiplier((std::numeric_limits<stxxl::uint64>::max)(), "B") << "<<<");
00087 
00088     unlink(tempfilename[0].c_str());
00089     unlink(tempfilename[1].c_str());
00090 
00091     return 0;
00092 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines