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