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