Stxxl  1.4.0
algo/test_ksort_all_parameters.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *  algo/test_ksort_all_parameters.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 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 //#define PLAY_WITH_OPT_PREF
00015 
00016 #include <stxxl/mng>
00017 #include <stxxl/ksort>
00018 #include <stxxl/vector>
00019 #include <stxxl/random>
00020 #include <stxxl/scan>
00021 
00022 #define KEY_COMPARE
00023 #include "test_sort_all_parameters.h"
00024 
00025 
00026 #ifndef RECORD_SIZE
00027  #define RECORD_SIZE 128
00028 #endif
00029 
00030 #define MB (1024 * 1024)
00031 
00032 
00033 template <typename T, typename alloc_strategy_type, unsigned block_size>
00034 void test(stxxl::uint64 data_mem, unsigned memory_to_use)
00035 {
00036     stxxl::uint64 records_to_sort = data_mem / sizeof(T);
00037     typedef stxxl::vector<T, 2, stxxl::lru_pager<8>, block_size, alloc_strategy_type> vector_type;
00038 
00039     memory_to_use = stxxl::div_ceil(memory_to_use, vector_type::block_type::raw_size) * vector_type::block_type::raw_size;
00040 
00041     vector_type v(records_to_sort);
00042     unsigned ndisks = stxxl::config::get_instance()->disks_number();
00043     STXXL_MSG("Sorting " << records_to_sort << " records of size " << sizeof(T));
00044     STXXL_MSG("Total volume " << (records_to_sort * sizeof(T)) / MB << " MiB");
00045     STXXL_MSG("Using " << memory_to_use / MB << " MiB");
00046     STXXL_MSG("Using " << ndisks << " disks");
00047     STXXL_MSG("Using " << alloc_strategy_type::name() << " allocation strategy ");
00048     STXXL_MSG("Block size " << vector_type::block_type::raw_size / 1024 << " KiB");
00049 
00050     STXXL_MSG("Filling vector...");
00051     stxxl::generate(v.begin(), v.end(), stxxl::random_number32_r(), 32);
00052     //std::generate(v.begin(),v.end(),zero());
00053 
00054     STXXL_MSG("Sorting vector...");
00055 
00056     stxxl::stats_data before(*stxxl::stats::get_instance());
00057 
00058     stxxl::ksort(v.begin(), v.end(), memory_to_use);
00059 
00060     stxxl::stats_data after(*stxxl::stats::get_instance());
00061 
00062     STXXL_MSG("Checking order...");
00063     STXXL_MSG((stxxl::is_sorted(v.begin(), v.end()) ? "OK" : "WRONG"));
00064 
00065     STXXL_MSG("Sorting: " << (after - before));
00066     STXXL_MSG("Total:   " << *stxxl::stats::get_instance());
00067 }
00068 
00069 template <typename T, unsigned block_size>
00070 void test_all_strategies(
00071     stxxl::uint64 data_mem,
00072     unsigned memory_to_use,
00073     int strategy)
00074 {
00075     switch (strategy)
00076     {
00077     case 0:
00078         test<T, stxxl::striping, block_size>(data_mem, memory_to_use);
00079         break;
00080     case 1:
00081         test<T, stxxl::SR, block_size>(data_mem, memory_to_use);
00082         break;
00083     case 2:
00084         test<T, stxxl::FR, block_size>(data_mem, memory_to_use);
00085         break;
00086     case 3:
00087         test<T, stxxl::RC, block_size>(data_mem, memory_to_use);
00088         break;
00089     default:
00090         STXXL_ERRMSG("Unknown allocation strategy: " << strategy << ", aborting");
00091         abort();
00092     }
00093 }
00094 
00095 int main(int argc, char * argv[])
00096 {
00097     if (argc < 6)
00098     {
00099         STXXL_ERRMSG("Usage: " << argv[0] <<
00100                      " <MiB to sort> <MiB to use> <alloc_strategy [0..3]> <blk_size [0..14]> <seed>");
00101         return -1;
00102     }
00103 
00104 #if STXXL_PARALLEL_MULTIWAY_MERGE
00105     STXXL_MSG("STXXL_PARALLEL_MULTIWAY_MERGE");
00106 #endif
00107     stxxl::uint64 data_mem = stxxl::atoint64(argv[1]) * MB;
00108     int sort_mem = atoi(argv[2]) * MB;
00109     int strategy = atoi(argv[3]);
00110     int block_size = atoi(argv[4]);
00111     stxxl::set_seed(strtoul(argv[5], NULL, 10));
00112     STXXL_MSG("Seed " << stxxl::get_next_seed());
00113     stxxl::srandom_number32();
00114 
00115     typedef my_type<stxxl::uint64, 8> my_default_type;
00116 
00117     switch (block_size)
00118     {
00119     case 0:
00120         test_all_strategies<my_default_type, 128 * 1024>(data_mem, sort_mem, strategy);
00121         break;
00122     case 1:
00123         test_all_strategies<my_default_type, 256 * 1024>(data_mem, sort_mem, strategy);
00124         break;
00125     case 2:
00126         test_all_strategies<my_default_type, 512 * 1024>(data_mem, sort_mem, strategy);
00127         break;
00128     case 3:
00129         test_all_strategies<my_default_type, 1024 * 1024>(data_mem, sort_mem, strategy);
00130         break;
00131     case 4:
00132         test_all_strategies<my_default_type, 2 * 1024 * 1024>(data_mem, sort_mem, strategy);
00133         break;
00134     case 5:
00135         test_all_strategies<my_default_type, 4 * 1024 * 1024>(data_mem, sort_mem, strategy);
00136         break;
00137     case 6:
00138         test_all_strategies<my_default_type, 8 * 1024 * 1024>(data_mem, sort_mem, strategy);
00139         break;
00140     case 7:
00141         test_all_strategies<my_default_type, 16 * 1024 * 1024>(data_mem, sort_mem, strategy);
00142         break;
00143     case 8:
00144         test_all_strategies<my_default_type, 640 * 1024>(data_mem, sort_mem, strategy);
00145         break;
00146     case 9:
00147         test_all_strategies<my_default_type, 768 * 1024>(data_mem, sort_mem, strategy);
00148         break;
00149     case 10:
00150         test_all_strategies<my_default_type, 896 * 1024>(data_mem, sort_mem, strategy);
00151         break;
00152     case 11:
00153         test_all_strategies<my_type<stxxl::uint64, 12>, 2 * MB>(data_mem, sort_mem, strategy);
00154         break;
00155     case 12:
00156         test_all_strategies<my_type<unsigned, 12>, 2 * MB + 4096>(data_mem, sort_mem, strategy);
00157         break;
00158     case 13:
00159         test_all_strategies<my_type<unsigned, 20>, 2 * MB + 4096>(data_mem, sort_mem, strategy);
00160         break;
00161     case 14:
00162         test_all_strategies<my_type<unsigned, 128>, 2 * MB>(data_mem, sort_mem, strategy);
00163         break;
00164     default:
00165         STXXL_ERRMSG("Unknown block size: " << block_size << ", aborting");
00166         abort();
00167     }
00168 
00169     return 0;
00170 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines