Stxxl  1.4.0
containers/leda_sm_stack_benchmark.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *  containers/leda_sm_stack_benchmark.cpp
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright (C) 2006 Roman Dementiev <dementiev@ira.uka.de>
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 //! \example containers/leda_sm_stack_benchmark.cpp
00014 //! This is a benchmark mentioned in the paper
00015 //! R. Dementiev, L. Kettner, P. Sanders "STXXL: standard template library for XXL data sets"
00016 //! Software: Practice and Experience
00017 //! Volume 38, Issue 6, Pages 589-637, May 2008
00018 //! DOI: 10.1002/spe.844
00019 
00020 
00021 #include <iostream>
00022 #include <algorithm>
00023 
00024 #include <LEDA-SM/ext_stack.h>
00025 #include <LEDA-SM/ext_memory_manager.h>
00026 #include <LEDA-SM/debug.h>
00027 #include <LEDA/random_source.h>
00028 #include <LEDA/stack.h>
00029 #include <LEDA-SM/block.h>
00030 #include <LEDA-SM/name_server.h>
00031 #define DEBUG 0
00032 #define DD 500
00033 
00034 #include <stxxl/types>
00035 #include <stxxl/timer>
00036 
00037 #define STXXL_MSG(x) \
00038     { std::cout << "[STXXL-MSG] " << x << std::endl << std::flush; \
00039     }
00040 
00041 
00042 #define MEM_2_RESERVE    (768 * 1024 * 1024)
00043 
00044 #define BLOCK_SIZE1 (EXT_BLK_SZ * 4)
00045 #define BLOCK_SIZE2 (DISK_BLOCK_SIZE * 4)
00046 
00047 
00048 #ifndef DISKS
00049  #define DISKS 1
00050 #endif
00051 
00052 template <unsigned RECORD_SIZE>
00053 struct my_record_
00054 {
00055     char data[RECORD_SIZE];
00056     my_record_() { }
00057 };
00058 
00059 
00060 template <class my_record>
00061 void run_stack(stxxl::int64 volume)
00062 {
00063     typedef ext_stack<my_record> stack_type;
00064 
00065     STXXL_MSG("Record size: " << sizeof(my_record) << " bytes");
00066 
00067     stack_type Stack;
00068 
00069     stxxl::int64 ops = volume / sizeof(my_record);
00070 
00071     stxxl::int64 i;
00072 
00073     my_record cur;
00074 
00075     stxxl::timer Timer;
00076     Timer.start();
00077 
00078     for (i = 0; i < ops; ++i)
00079     {
00080         Stack.push(cur);
00081     }
00082 
00083     Timer.stop();
00084 
00085     STXXL_MSG("Records in Stack: " << Stack.size());
00086     if (i != Stack.size())
00087     {
00088         STXXL_MSG("Size does not match");
00089         abort();
00090     }
00091 
00092     STXXL_MSG("Insertions elapsed time: " << (Timer.mseconds() / 1000.) <<
00093               " seconds : " << (double(volume) / (1024. * 1024. * Timer.mseconds() / 1000.)) <<
00094               " MiB/s");
00095 
00096     ext_mem_mgr.print_statistics();
00097     ext_mem_mgr.reset_statistics();
00098 
00099 
00100     ////////////////////////////////////////////////
00101     Timer.reset();
00102     Timer.start();
00103 
00104     for (i = 0; i < ops; ++i)
00105     {
00106         Stack.pop();
00107     }
00108 
00109     Timer.stop();
00110 
00111     STXXL_MSG("Records in Stack: " << Stack.size());
00112     if (!Stack.empty())
00113     {
00114         STXXL_MSG("Stack must be empty");
00115         abort();
00116     }
00117 
00118     STXXL_MSG("Deletions elapsed time: " << (Timer.mseconds() / 1000.) <<
00119               " seconds : " << (double(volume) / (1024. * 1024. * Timer.mseconds() / 1000.)) <<
00120               " MiB/s");
00121 
00122     ext_mem_mgr.print_statistics();
00123 }
00124 
00125 
00126 int main(int argc, char * argv[])
00127 {
00128     STXXL_MSG("block size 1: " << BLOCK_SIZE1 << " bytes");
00129     STXXL_MSG("block size 2: " << BLOCK_SIZE2 << " bytes");
00130 
00131 
00132     if (argc < 3)
00133     {
00134         STXXL_MSG("Usage: " << argv[0] << " version #volume");
00135         STXXL_MSG("\t version = 1: LEDA-SM stack with 4 byte records");
00136         STXXL_MSG("\t version = 2: LEDA-SM stack with 32 byte records");
00137         return -1;
00138     }
00139 
00140     int version = atoi(argv[1]);
00141     stxxl::int64 volume = atoll(argv[2]);
00142 
00143     STXXL_MSG("Allocating array with size " << MEM_2_RESERVE
00144                                             << " bytes to prevent file buffering.");
00145     int * array = new int[MEM_2_RESERVE / sizeof(int)];
00146     std::fill(array, array + (MEM_2_RESERVE / sizeof(int)), 0);
00147 
00148     STXXL_MSG("Running version: " << version);
00149     STXXL_MSG("Data volume    : " << volume << " bytes");
00150 
00151     switch (version)
00152     {
00153     case 1:
00154         run_stack<my_record_<4> >(volume);
00155         break;
00156     case 2:
00157         run_stack<my_record_<32> >(volume);
00158         break;
00159     default:
00160         STXXL_MSG("Unsupported version " << version);
00161     }
00162 
00163     delete[] array;
00164 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines