Stxxl  1.4.0
containers/tpie_stack_benchmark.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *  containers/tpie_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/tpie_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 "app_config.h"
00022 
00023 #include <portability.h>
00024 #include <versions.h>
00025 
00026 // Get the AMI_stack definition.
00027 #include <ami_stack.h>
00028 
00029 // Utilities for ASCII output.
00030 #include <ami_scan_utils.h>
00031 
00032 #include <stxxl/bits/common/utils.h>
00033 #include <stxxl/bits/verbose.h>
00034 #include <stxxl/timer>
00035 
00036 
00037 #define MEM_2_RESERVE    (768 * 1024 * 1024)
00038 
00039 #define BLOCK_SIZE       (2 * 1024 * 1024)
00040 
00041 
00042 #ifndef DISKS
00043  #define DISKS 1
00044 #endif
00045 
00046 template <unsigned RECORD_SIZE>
00047 struct my_record_
00048 {
00049     char data[RECORD_SIZE];
00050     my_record_() { }
00051 };
00052 
00053 
00054 template <class my_record>
00055 void run_stack(stxxl::int64 volume)
00056 {
00057     typedef AMI_stack<my_record> stack_type;
00058 
00059     MM_manager.set_memory_limit(BLOCK_SIZE * DISKS * 8);
00060 
00061     STXXL_MSG("Record size: " << sizeof(my_record) << " bytes");
00062 
00063     stack_type Stack;
00064 
00065     stxxl::int64 ops = volume / sizeof(my_record);
00066 
00067     stxxl::int64 i;
00068 
00069     my_record cur;
00070 
00071     stxxl::timer Timer;
00072     Timer.start();
00073 
00074     for (i = 0; i < ops; ++i)
00075     {
00076         Stack.push(cur);
00077     }
00078 
00079     Timer.stop();
00080 
00081     STXXL_MSG("Records in Stack: " << Stack.stream_len());
00082     if (i != Stack.stream_len())
00083     {
00084         STXXL_MSG("Size does not match");
00085         abort();
00086     }
00087 
00088     STXXL_MSG("Insertions elapsed time: " << (Timer.mseconds() / 1000.) <<
00089               " seconds : " << (double(volume) / (1024. * 1024. * Timer.mseconds() / 1000.)) <<
00090               " MiB/s");
00091 
00092 
00093     ////////////////////////////////////////////////
00094     Timer.reset();
00095     Timer.start();
00096 
00097     my_record * out;
00098 
00099     for (i = 0; i < ops; ++i)
00100     {
00101         Stack.pop(&out);
00102     }
00103 
00104     Timer.stop();
00105 
00106     STXXL_MSG("Records in Stack: " << Stack.stream_len());
00107     if (Stack.stream_len() != 0)
00108     {
00109         STXXL_MSG("Stack must be empty");
00110         abort();
00111     }
00112 
00113     STXXL_MSG("Deletions elapsed time: " << (Timer.mseconds() / 1000.) <<
00114               " seconds : " << (double(volume) / (1024. * 1024. * Timer.mseconds() / 1000.)) <<
00115               " MiB/s");
00116 }
00117 
00118 
00119 int main(int argc, char * argv[])
00120 {
00121     using std::cout;
00122     using std::endl;
00123 #ifdef BTE_COLLECTION_IMP_MMAP
00124     cout << "BTE_COLLECTION_IMP_MMAP is defined" << endl;
00125 #endif
00126 #ifdef BTE_COLLECTION_IMP_UFS
00127     cout << "BTE_COLLECTION_IMP_UFS is defined" << endl;
00128 #endif
00129 #ifdef BTE_STREAM_IMP_UFS
00130     cout << "BTE_STREAM_IMP_UFS is defined" << endl;
00131     cout << "BTE_STREAM_UFS_BLOCK_FACTOR is " << BTE_STREAM_UFS_BLOCK_FACTOR << endl;
00132     cout << "Actual block size is " << (TPIE_OS_BLOCKSIZE() * BTE_STREAM_UFS_BLOCK_FACTOR / 1024) << " KiB" << endl;
00133 #endif
00134 #ifdef BTE_STREAM_IMP_MMAP
00135     cout << "BTE_STREAM_IMP_MMAP is defined" << endl;
00136     cout << "BTE_STREAM_MMAP_BLOCK_FACTOR is " << BTE_STREAM_MMAP_BLOCK_FACTOR << endl;
00137     cout << "Actual block size is " << (TPIE_OS_BLOCKSIZE() * BTE_STREAM_MMAP_BLOCK_FACTOR / 1024) << " KiB" << endl;
00138 #endif
00139 #ifdef BTE_STREAM_IMP_STDIO
00140     cout << "BTE_STREAM_IMP_STDIO is defined" << endl;
00141 #endif
00142     cout << "TPIE_OS_BLOCKSIZE() is " << TPIE_OS_BLOCKSIZE() << endl;
00143 
00144     if (argc < 3)
00145     {
00146         STXXL_MSG("Usage: " << argv[0] << " version #volume");
00147         STXXL_MSG("\t version = 1: TPIE stack with 4 byte records");
00148         STXXL_MSG("\t version = 2: TPIE stack with 32 byte records");
00149         return -1;
00150     }
00151 
00152     int version = atoi(argv[1]);
00153     stxxl::int64 volume = stxxl::atoint64(argv[2]);
00154 
00155     STXXL_MSG("Allocating array with size " << MEM_2_RESERVE
00156                                             << " bytes to prevent file buffering.");
00157     //int * array = new int[MEM_2_RESERVE/sizeof(int)];
00158     int * array = (int *)malloc(MEM_2_RESERVE);
00159     std::fill(array, array + (MEM_2_RESERVE / sizeof(int)), 0);
00160 
00161     STXXL_MSG("Running version: " << version);
00162     STXXL_MSG("Data volume    : " << volume << " bytes");
00163 
00164     switch (version)
00165     {
00166     case 1:
00167         run_stack<my_record_<4> >(volume);
00168         break;
00169     case 2:
00170         run_stack<my_record_<32> >(volume);
00171         break;
00172     default:
00173         STXXL_MSG("Unsupported version " << version);
00174     }
00175 
00176     //delete [] array;
00177     free(array);
00178 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines