Stxxl
1.4.0
|
00001 /*************************************************************************** 00002 * io/test_io_sizes.cpp 00003 * 00004 * Part of the STXXL. See http://stxxl.sourceforge.net 00005 * 00006 * Copyright (C) 2010 Johannes Singler <singler@kit.edu> 00007 * 00008 * Distributed under the Boost Software License, Version 1.0. 00009 * (See accompanying file LICENSE_1_0.txt or copy at 00010 * http://www.boost.org/LICENSE_1_0.txt) 00011 **************************************************************************/ 00012 00013 #include <stxxl/io> 00014 #include <stxxl/aligned_alloc> 00015 #include <stxxl/bits/mng/mng.h> 00016 00017 //! \example io/test_io_sizes.cpp 00018 //! This tests the maximum chunk size that a file type can handle with a single request. 00019 00020 00021 int main(int argc, char ** argv) 00022 { 00023 if (argc < 4) 00024 { 00025 std::cout << "Usage: " << argv[0] << " filetype tempfile maxsize" << std::endl; 00026 return -1; 00027 } 00028 00029 using stxxl::uint64; 00030 00031 uint64 max_size = stxxl::atoint64(argv[3]); 00032 uint64 * buffer = (uint64 *)stxxl::aligned_alloc<4096>(max_size); 00033 00034 try 00035 { 00036 stxxl::compat_unique_ptr<stxxl::file>::result file( 00037 stxxl::create_file(argv[1], argv[2], stxxl::file::CREAT | stxxl::file::RDWR | stxxl::file::DIRECT)); 00038 file->set_size(max_size); 00039 00040 stxxl::request_ptr req; 00041 stxxl::stats_data stats1(*stxxl::stats::get_instance()); 00042 for (uint64 size = 4096; size < max_size; size *= 2) 00043 { 00044 //generate data 00045 for (uint64 i = 0; i < size / sizeof(uint64); ++i) 00046 buffer[i] = i; 00047 00048 //write 00049 STXXL_MSG(stxxl::add_IEC_binary_multiplier(size, "B") << "are being written at once"); 00050 req = file->awrite(buffer, 0, size, stxxl::default_completion_handler()); 00051 wait_all(&req, 1); 00052 00053 //fill with wrong data 00054 for (uint64 i = 0; i < size / sizeof(uint64); ++i) 00055 buffer[i] = 0xFFFFFFFFFFFFFFFFull; 00056 00057 //read again 00058 STXXL_MSG(stxxl::add_IEC_binary_multiplier(size, "B") << "are being read at once"); 00059 req = file->aread(buffer, 0, size, stxxl::default_completion_handler()); 00060 wait_all(&req, 1); 00061 00062 //check 00063 bool wrong = false; 00064 for (uint64 i = 0; i < size / sizeof(uint64); ++i) 00065 if (buffer[i] != i) 00066 { 00067 STXXL_ERRMSG("Read inconsistent data at position " << i * sizeof(uint64)); 00068 wrong = true; 00069 break; 00070 } 00071 00072 if (wrong) 00073 break; 00074 } 00075 std::cout << stxxl::stats_data(*stxxl::stats::get_instance()) - stats1; 00076 00077 file->remove(); 00078 } 00079 catch (stxxl::io_error e) 00080 { 00081 std::cerr << e.what() << std::endl; 00082 } 00083 00084 stxxl::aligned_dealloc<4096>(buffer); 00085 00086 return 0; 00087 } 00088 // vim: et:ts=4:sw=4