ortho_range_search_main.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00038 #include "data_aux.h"
00039 #include "naive_ortho_range_search.h"
00040 #include "ortho_range_search.h"
00041
00042 #include "fastlib/mmanager/memory_manager.h"
00043
00044 void OutputOrhogonalRangeSearchResults(const GenMatrix<bool> &search_results,
00045 const char *file_name) {
00046
00047 FILE *file_pointer = fopen(file_name, "w+");
00048
00049 for(index_t r = 0; r < search_results.n_rows(); r++) {
00050 for(index_t c = 0; c < search_results.n_cols(); c++) {
00051
00052 if(search_results.get(r, c)) {
00053 fprintf(file_pointer, "1 ");
00054 }
00055 else {
00056 fprintf(file_pointer, "0 ");
00057 }
00058 }
00059 fprintf(file_pointer, "\n");
00060 }
00061 }
00062
00112 int main(int argc, char *argv[]) {
00113
00114
00115
00116 fx_init(argc, argv, NULL);
00117
00118
00119 std::string pool_name("/scratch/temp_mem");
00120 mmapmm::MemoryManager<false>::allocator_ =
00121 new mmapmm::MemoryManager<false>();
00122 mmapmm::MemoryManager<false>::allocator_->set_pool_name(pool_name);
00123 mmapmm::MemoryManager<false>::allocator_->set_capacity(65536*1000);
00124 mmapmm::MemoryManager<false>::allocator_->Init();
00125
00127
00128
00129 const char* dataset_file_name = fx_param_str(NULL, "data", "data.csv");
00130
00131
00132 GenMatrix<double> dataset;
00133
00134
00135 data::Load(dataset_file_name, &dataset);
00136
00137
00138 GenMatrix<double> low_coord_limits, high_coord_limits;
00139
00140
00141
00142 const char *lower_limit_file_name = fx_param_str(NULL, "lower", "lower.csv");
00143 const char *upper_limit_file_name = fx_param_str(NULL, "upper", "upper.csv");
00144
00145 data::Load(lower_limit_file_name, &low_coord_limits);
00146 data::Load(upper_limit_file_name, &high_coord_limits);
00147
00148
00149 bool do_naive = fx_param_exists(NULL, "do_naive");
00150
00151
00152 const char *load_tree_file_name;
00153
00154 if(fx_param_exists(NULL, "load_tree_file")) {
00155 load_tree_file_name = fx_param_str(NULL, "load_tree_file", NULL);
00156 }
00157 else {
00158 load_tree_file_name = NULL;
00159 }
00160
00161
00162 OrthoRangeSearch<double> fast_search;
00163 fast_search.Init(dataset, fx_param_exists(NULL, "do_naive"),
00164 load_tree_file_name);
00165 GenMatrix<bool> fast_search_results;
00166 fast_search.Compute(low_coord_limits, high_coord_limits,
00167 &fast_search_results);
00168
00169 if(fx_param_exists(NULL, "save_tree_file")) {
00170 const char *save_tree_file_name = fx_param_str(NULL, "save_tree_file",
00171 NULL);
00172 fast_search.SaveTree(save_tree_file_name);
00173 }
00174
00175
00176 OutputOrhogonalRangeSearchResults(fast_search_results, "results.txt");
00177
00178
00179 if(do_naive) {
00180 NaiveOrthoRangeSearch<double> search;
00181 GenMatrix<bool> naive_search_results;
00182 search.Init(dataset);
00183 search.Compute(low_coord_limits, high_coord_limits, &naive_search_results);
00184 bool flag = true;
00185
00186 for(index_t i = 0; i < fast_search_results.n_cols(); i++) {
00187 for(index_t j = 0; j < dataset.n_cols(); j++) {
00188 if(fast_search_results.get(j, i) != naive_search_results.get(j, i)) {
00189 flag = false;
00190 printf("Differ on (%d, %d)\n", i, j);
00191 break;
00192 }
00193 }
00194 }
00195 if(flag) {
00196 printf("Both naive and tree-based method got the same results...\n");
00197 }
00198 else {
00199 printf("Both methods have different results...\n");
00200 }
00201 }
00202 fx_timer *tree_range_search_time = fx_get_timer(NULL, "tree_range_search");
00203 fx_timer *naive_search_time = fx_get_timer(NULL, "naive_search");
00204
00205 fx_format_result(NULL, "speedup", "%g",
00206 ((double)(naive_search_time->total).micros) /
00207 ((double)(tree_range_search_time->total).micros));
00208
00209
00210 mmapmm::MemoryManager<false>::allocator_->Destruct();
00211 delete mmapmm::MemoryManager<false>::allocator_;
00212 fx_done(NULL);
00213 return 0;
00214 }