Skip to content

Commit

Permalink
openmp
Browse files Browse the repository at this point in the history
  • Loading branch information
CaucherWang committed Dec 23, 2022
1 parent 4f7aee2 commit 69a5587
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 65 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ set(CMAKE_CXX_STANDARD 23)
#set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#add_definitions(-DMALLOC_CHECK_=3)
find_package(Threads REQUIRED)
find_package(OpenMP REQUIRED)
find_package(GSL REQUIRED)
include_directories(${GSL_INCLUDE_DIRES} ${GSLCBLAS_INCLUDE_DIRS})
link_libraries(${GSL_LIBRARIES} ${GSLBLAS_LIBRARIES})
add_compile_options(-march=haswell)
#add_compile_options("-mavx2")
add_executable(FADAS src/main.cpp include/DataStructures/TimeSeries.h include/DataStructures/PqItemSeries.h src/DSTree/DSTreeNode.cpp include/DSTree/DSTreeNode.h include/DSTree/InsertedSeries.h include/DSTree/Sketch.h include/DSTree/PqItemNode.h include/DSTree/SplitInfo.h include/DSTree/INodeSegmentSplitPolicy.h src/DSTree/DSTreeNodeConstruction.cpp include/DSTree/DSTreeNodeConstruction.h src/DSTree/MeanNodeSegmentSplitPolicy.cpp include/DSTree/MeanNodeSegmentSplitPolicy.h src/DSTree/StdevNodeSegmentSplitPolicy.cpp include/DSTree/StdevNodeSegmentSplitPolicy.h src/Utils/FileUtil.cpp include/Utils/FileUtil.h src/Utils/TimeSeriesUtil.cpp include/Utils/TimeSeriesUtil.h src/Utils/SaxUtil.cpp include/Utils/SaxUtil.h include/DataStructures/PqItemIndex.h src/Utils/MathUtil.cpp include/Utils/MathUtil.h src/SearchEngine/ExactSearcher.cpp include/Searchers/ExactSearcher.h src/SearchEngine/DSTreeApproxSearcher.cpp include/Searchers/DSTreeApproxSearcher.h src/SearchEngine/DSTreeExactSearcher.cpp include/Searchers/DSTreeExactSearcher.h src/IndexConstruction/GraphConstruction.cpp include/DataStructures/GraphConstruction.h src/PqItemSeries.cpp src/DSTree/INodeSegmentSplitPolicy.cpp src/Expr/Recall.cpp include/Expr/Recall.h include/Const.h src/Expr/DataDistribution.cpp include/Expr/DataDistribution.h src/Tardis/TardisTreeNode.cpp include/Tardis/TardisTreeNode.h src/SearchEngine/TardisApproxSearch.cpp include/Searchers/TardisApproxSearch.h src/IndexConstruction/IPGNode.cpp include/DataStructures/IPGNode.h src/IndexConstruction/IPGPartition.cpp include/DataStructures/IPGPartition.h src/SearchEngine/IPGApproxSearcher.cpp include/Searchers/IPGApproxSearcher.h src/iSAX/iSAXNode.cpp include/DataStructures/iSAXNode.h src/SearchEngine/iSAXSearcher.cpp include/Searchers/iSAXSearcher.h src/Expr/RandDataGenerator.cpp include/Expr/RandDataGenerator.h src/Expr/DNATranslator.cpp include/Expr/DNATranslator.h src/IndexConstruction/IPGDataNode.cpp include/DataStructures/IPGDataNode.h src/Utils/INIReader.cpp include/Utils/INIReader.h src/Utils/ini.c include/DataStructures/OffsetDist.h src/Const.cpp src/IndexConstruction/FADASNode.cpp include/DataStructures/FADASNode.h src/SearchEngine/FADASSearcher.cpp include/Searchers/FADASSearcher.h src/IndexConstruction/FADASFuzzy.cpp src/Expr/ECGParser.cpp include/Expr/ECGParser.h src/TAR/TARGNode.cpp include/TAR/TARGNode.h src/TAR/TARLNode.cpp include/TAR/TARLNode.h src/SearchEngine/TARSearcher.cpp include/TAR/TARSearcher.h include/DataStructures/SafePq.h include/DataStructures/ThreadPool.h include/DataStructures/SafeHashMap.h)
add_executable(FADAS src/main.cpp include/DataStructures/TimeSeries.h include/DataStructures/PqItemSeries.h src/DSTree/DSTreeNode.cpp include/DSTree/DSTreeNode.h include/DSTree/InsertedSeries.h include/DSTree/Sketch.h include/DSTree/PqItemNode.h include/DSTree/SplitInfo.h include/DSTree/INodeSegmentSplitPolicy.h src/DSTree/DSTreeNodeConstruction.cpp include/DSTree/DSTreeNodeConstruction.h src/DSTree/MeanNodeSegmentSplitPolicy.cpp include/DSTree/MeanNodeSegmentSplitPolicy.h src/DSTree/StdevNodeSegmentSplitPolicy.cpp include/DSTree/StdevNodeSegmentSplitPolicy.h src/Utils/FileUtil.cpp include/Utils/FileUtil.h src/Utils/TimeSeriesUtil.cpp include/Utils/TimeSeriesUtil.h src/Utils/SaxUtil.cpp include/Utils/SaxUtil.h include/DataStructures/PqItemIndex.h src/Utils/MathUtil.cpp include/Utils/MathUtil.h src/SearchEngine/ExactSearcher.cpp include/Searchers/ExactSearcher.h src/SearchEngine/DSTreeApproxSearcher.cpp include/Searchers/DSTreeApproxSearcher.h src/SearchEngine/DSTreeExactSearcher.cpp include/Searchers/DSTreeExactSearcher.h src/IndexConstruction/GraphConstruction.cpp include/DataStructures/GraphConstruction.h src/PqItemSeries.cpp src/DSTree/INodeSegmentSplitPolicy.cpp src/Expr/Recall.cpp include/Expr/Recall.h include/Const.h src/Expr/DataDistribution.cpp include/Expr/DataDistribution.h src/Tardis/TardisTreeNode.cpp include/Tardis/TardisTreeNode.h src/SearchEngine/TardisApproxSearch.cpp include/Searchers/TardisApproxSearch.h src/IndexConstruction/IPGNode.cpp include/DataStructures/IPGNode.h src/IndexConstruction/IPGPartition.cpp include/DataStructures/IPGPartition.h src/SearchEngine/IPGApproxSearcher.cpp include/Searchers/IPGApproxSearcher.h src/iSAX/iSAXNode.cpp include/DataStructures/iSAXNode.h src/SearchEngine/iSAXSearcher.cpp include/Searchers/iSAXSearcher.h src/Expr/RandDataGenerator.cpp include/Expr/RandDataGenerator.h src/Expr/DNATranslator.cpp include/Expr/DNATranslator.h src/IndexConstruction/IPGDataNode.cpp include/DataStructures/IPGDataNode.h src/Utils/INIReader.cpp include/Utils/INIReader.h src/Utils/ini.c include/DataStructures/OffsetDist.h src/Const.cpp src/IndexConstruction/FADASNode.cpp include/DataStructures/FADASNode.h src/SearchEngine/FADASSearcher.cpp include/Searchers/FADASSearcher.h src/IndexConstruction/FADASFuzzy.cpp src/Expr/ECGParser.cpp include/Expr/ECGParser.h src/TAR/TARGNode.cpp include/TAR/TARGNode.h src/TAR/TARLNode.cpp include/TAR/TARLNode.h src/SearchEngine/TARSearcher.cpp include/TAR/TARSearcher.h include/DataStructures/SafePq.h include/DataStructures/ThreadPool.h include/DataStructures/SafeHashMap.h include/DataStructures/io_data.h)
#target_compile_options(FADAS PUBLIC "-mavx2")
target_link_libraries(FADAS Threads::Threads libboost_serialization-mt-x64.a libboost_serialization-mt-x64.so libboost_serialization.so.1.76.0 ${GSL_LIBRARIES} ${GSLBLAS_LIBRARIES} liburing.so)
target_link_libraries(FADAS OpenMP::OpenMP_CXX Threads::Threads libboost_serialization-mt-x64.a libboost_serialization-mt-x64.so libboost_serialization.so.1.76.0 ${GSL_LIBRARIES} ${GSLBLAS_LIBRARIES} liburing.so)
9 changes: 5 additions & 4 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ materialized = 1
;6 for approx dtw search, 7 for exact dtw search,
;8 for inc approx. dtw, 9 for complete workload
;10 for ng-search
ops = 2
;11 for parallel exact-search
ops = 11
;50 for ecg on-disk and rand-100m, rand-300m, deep-10m, dna-26m
;500 for seismic,deep1b,
;100 for others
Expand All @@ -26,9 +27,9 @@ k = 50
query_num = 40
;dna:26339815
series_num = 100000000
thread_num = 40
messi_pq_num = 10
SSD_pq_num = 5
thread_num = 4
messi_pq_num = 1
SSD_pq_num = 64

dtw_window_percent = 0.05
batch_size = 1400000
Expand Down
15 changes: 15 additions & 0 deletions include/DataStructures/io_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Created by zeyuwang on 2022/12/21.
//

#ifndef FADAS_IO_DATA_H
#define FADAS_IO_DATA_H

struct io_data{
int node_size{};
float lb_dist{};
int fd{};
float* tss{};
};

#endif //FADAS_IO_DATA_H
2 changes: 2 additions & 0 deletions include/Expr/Recall.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class Recall {

static void exactSearchFADAS(FADASNode *root, vector<vector<int>> *g);

static void exactSearchDumpyParallel(FADASNode *root, vector<vector<int>>*g);

static void exactSearchFADASDTW(FADASNode *root, vector<vector<int>>*g);

static void exactSearchFADASNoExpr(FADASNode *root, vector<vector<int>> *g);
Expand Down
10 changes: 7 additions & 3 deletions include/Searchers/FADASSearcher.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
//
// Created by pengwang5 on 2022/1/16.
// Created by zeyuwang on 2022/1/16.
//

#ifndef MULGIFT_FADASSEARCHER_H
#define MULGIFT_FADASSEARCHER_H
#include <vector>
#include <liburing.h>
#include "../DataStructures/FADASNode.h"
#include "../DataStructures/io_data.h"

class FADASSearcher {
public:
Expand Down Expand Up @@ -38,8 +40,10 @@ class FADASSearcher {
static vector<PqItemSeries*>*Par_exactSearchIdLevel_MESSI(FADASNode* root, float *query, int k, vector<vector<int>> *g,
float *query_reordered, int *ordering);

static vector<PqItemSeries*>*Par_exactSearchIdLevel_SSD(FADASNode* root, float *query, int k, vector<vector<int>> *g,
float *query_reordered, int *ordering);
static vector<PqItemSeries *> *
Par_exactSearchIdLevel_SSD(FADASNode *root, float *query, int k, vector<vector<int>> *g,
float *query_reordered, int *ordering, io_uring &ring,
vector<vector<io_data>> &io_buffer);

static vector<PqItemSeries*>* exactSearchDTW(FADASNode* root, float *query, int k, vector<vector<int>> *g);

Expand Down
117 changes: 115 additions & 2 deletions src/Expr/Recall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using namespace std;
// LBSeriesTime2 = 0, LBNodeTime2=0, DSTreeSearchTime2 =0, IOBigTime2 = 0, distBigTime2 = 0, DSTreeNodeApproxTime2 = 0, heapBigTime2 = 0, DSTreePreparePqTime2 =0,DSTreeProcessPqTime2 =0,
// approxSearchTime = 0, exactSearchTime = 0, wallClockTime = 0, hashTableTime = 0, LBSeriesCnt = 0;
extern long approxSearchTimeDetails[]{0,0,0,0}, approxSearchUnits[]{0,0,0,0};
extern long LB_SERIES_TIME , HEAP_TIME ,
extern long LB_SERIES_TIME , HEAP_TIME , IO_URING_WAIT,
LB_NODE_TIME_STAT , LB_NODE_CNT, LOADED_NODE_CNT, LOADED_PACK_CNT=0;
extern double DIST_CALC_TIME ,READ_TIME, PREPARE_TIME, SEARCH_TIME;

Expand Down Expand Up @@ -1570,7 +1570,8 @@ void Recall::exactSearchFADAS(FADASNode *root, vector<vector<int>>*g) {

reorder_query(query, query_reordered, ordering);
auto start = chrono::system_clock::now();
vector<PqItemSeries*> *approxKnn = FADASSearcher::Par_exactSearchIdLevel_SSD(root, query, k, g, query_reordered, ordering);
vector<PqItemSeries*> *approxKnn = FADASSearcher::Par_exactSearchIdLevel_MESSI(root, query, k, g, query_reordered,
ordering);
auto end = chrono::system_clock::now();
duration[curRound] = chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0;
// vector<float*>* exactKnn = getResult(Const::resfn, _k*maxExprRound + curRound, k);
Expand Down Expand Up @@ -1635,6 +1636,118 @@ void Recall::exactSearchFADAS(FADASNode *root, vector<vector<int>>*g) {
fclose(f);
}

void Recall::exactSearchDumpyParallel(FADASNode *root, vector<vector<int>>*g) {
int maxExprRound = Const::query_num;
Const::logPrint( "result file is " + Const::resfn);

float *query;
FILE *f = fopen(Const::queryfn.c_str(), "rb");
int k = Const::k;
int recallNums[maxExprRound];
LB_NODE_CNT = 0;
int search_number[maxExprRound];
float query_reordered[Const::tsLength];
int ordering[Const::tsLength];
double duration[maxExprRound]; // ms
double read_time[maxExprRound], prepare_time[maxExprRound], search_time[maxExprRound], dist_calc_time[maxExprRound];
int load_node_cnt[maxExprRound];
cout<<"------------------Experiment--------------------" << endl;
cout<<"k: " << k << endl;
cout << fixed << setprecision(3);

io_uring ring{};
// io_uring_params params{};
// params.flags |= IORING_SETUP_SQPOLL;
// params.sq_thread_idle = 8000;
auto ret = io_uring_queue_init(Const::SSD_pq_num, &ring, 0);
vector<vector<io_data>>io_buffer(2, vector<io_data>(Const::SSD_pq_num));
for(int i = 0; i < 2 ; ++i)
for(int j = 0; j < Const::SSD_pq_num; ++j)
io_buffer[i][j].tss = new float [Const::th * Const::tsLength];


for(int curRound = 0; curRound < maxExprRound; ++curRound){
// cout<<"Round : " + (curRound + 1));
c_nodes.clear();
_search_num = 0;
READ_TIME = 0; PREPARE_TIME = 0; SEARCH_TIME = 0; DIST_CALC_TIME = 0; IO_URING_WAIT = 0;
LOADED_NODE_CNT = 0;
query = FileUtil::readSeries(f);
// if(curRound < 25) continue;

reorder_query(query, query_reordered, ordering);
auto start = chrono::system_clock::now();
vector<PqItemSeries*> *approxKnn = FADASSearcher::Par_exactSearchIdLevel_SSD(root, query, k, g, query_reordered,
ordering, ring, io_buffer);
auto end = chrono::system_clock::now();
duration[curRound] = chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0;
// vector<float*>* exactKnn = getResult(Const::resfn, _k*maxExprRound + curRound, k);
vector<float*>* exactKnn = getResult(Const::resfn, curRound, k);
vector<PqItemSeries*> exactKnn2;
for(float *t: *exactKnn)
exactKnn2.push_back(new PqItemSeries(t, query));

load_node_cnt[curRound] = LOADED_NODE_CNT;
read_time[curRound] = IO_URING_WAIT;
prepare_time[curRound] = PREPARE_TIME;
search_time[curRound] = SEARCH_TIME;
dist_calc_time[curRound] = DIST_CALC_TIME;
recallNums[curRound] = TimeSeriesUtil::intersectionTsSetsCardinality(approxKnn, exactKnn);
search_number[curRound] = _search_num;
cout << recallNums[curRound] << ";" << (double)_search_num / root->size << ", ";
fflush(stdout);
// analyzePrintSaxFADAS(approxKnn, exactKnn, query);
free_heap(approxKnn);
for(int i=0;i<k;++i)
delete[] (*exactKnn)[i];
delete exactKnn;
delete[] query;
}
cout << endl;

io_uring_queue_exit(&ring);
for(int i = 0; i < 2 ; ++i)
for(int j = 0; j < Const::SSD_pq_num; ++j)
delete io_buffer[i][j].tss;

double totalDuration = 0;
for(double _:duration) {totalDuration += _; cout<< _ << ",";}
cout << endl;
double total_read_time = 0;
for(double _:read_time) {total_read_time += _; cout<<_/1000.0<<",";}
double total_prepare_time = 0;
for(double _:prepare_time) total_prepare_time += _;
double total_search_time = 0;
for(auto _:search_time) total_search_time += _;
double total_dist_calc_time = 0;
for(auto _:dist_calc_time) total_dist_calc_time += _;
cout << endl;
long total_node_cnt = 0;
for(int _:load_node_cnt) { total_node_cnt += _; cout << (_) << ","; }
cout << endl;
long totalSearchNum = 0;
for(int _:search_number) { totalSearchNum += _; cout << (_ / (double)root->size) << ","; }
cout << endl;
int totalRecallNum = 0;
for(int temp:recallNums)
totalRecallNum += temp;
cout<<"\nAverage Recall rate is : " << (float)totalRecallNum / (float) (maxExprRound * k)<< endl;
cout << "Average Search rate is " <<(double)totalSearchNum / ((double)maxExprRound * root->size)<<endl;
cout <<"Average Duration cost is " << totalDuration / maxExprRound << " ms" << endl;
// cout << "Avg. Distance Calculation time is " << DIST_CALC_TIME / 1000.0 / maxExprRound <<"ms."<<endl;
cout << "AVG. I/O read time is " << total_read_time / 1000.0 / maxExprRound << "ms."<<endl;
cout << "AVG. prepare time is " << total_prepare_time / 1000.0 / maxExprRound << "ms."<<endl;
cout << "AVG. pre calc time is " << total_dist_calc_time / 1000.0 / maxExprRound << "ms."<<endl;
cout << "AVG. parallel time is " << total_search_time / 1000.0 / maxExprRound << "ms."<<endl;
cout << "Avg. Priority Queue nodes count = " << LB_NODE_CNT / maxExprRound <<endl;
cout << "Avg. Loaded nodes count = " << total_node_cnt / maxExprRound << endl;
cout << endl;
rewind(f);


fclose(f);
}

void Recall::exactSearchFADASDTW(FADASNode *root, vector<vector<int>>*g) {
int maxExprRound = Const::query_num;
Const::logPrint( "result file is " + Const::resfn);
Expand Down
Loading

0 comments on commit 69a5587

Please sign in to comment.