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