Hybrid Query Processing Engine for Coprocessing in Database Systems
HyPE
|
00001 00002 00003 #include <iostream> 00004 #include <stdlib.h> 00005 #include <hype.hpp> 00006 00007 #include <boost/thread.hpp> 00008 00009 using namespace hype; 00010 using namespace std; 00011 00012 void CPU_algorithm(size_t data_size){ 00013 boost::this_thread::sleep(boost::posix_time::milliseconds(data_size )); 00014 00015 } 00016 00017 void GPU_algorithm(size_t data_size){ 00018 boost::this_thread::sleep(boost::posix_time::milliseconds((data_size/2)+50 )); 00019 00020 } 00021 00022 int main(){ 00023 00024 Scheduler& scheduler=Scheduler::instance(); 00025 00026 scheduler.addAlgorithm("SORT","CPU_Algorithm",CPU,"Least Squares 1D","Periodic Recomputation"); 00027 scheduler.addAlgorithm("SORT","GPU_Algorithm",GPU,"Least Squares 1D","Periodic Recomputation"); 00028 00029 00030 for(int i=0;i<100;i++){ 00031 Tuple t; 00032 t.push_back(rand()%300); 00033 uint64_t begin = core::getTimestamp(); 00034 SchedulingDecision sched_dec = scheduler.getOptimalAlgorithmName("SORT",t); 00035 cout << "Line: " << i << " "; 00036 if(sched_dec.getNameofChoosenAlgorithm()=="CPU_Algorithm"){ 00037 AlgorithmMeasurement alg_measure(sched_dec); 00038 CPU_algorithm(t[0]); 00039 alg_measure.afterAlgorithmExecution(); 00040 }else if(sched_dec.getNameofChoosenAlgorithm()=="GPU_Algorithm"){ 00041 AlgorithmMeasurement alg_measure(sched_dec); 00042 GPU_algorithm(t[0]); 00043 alg_measure.afterAlgorithmExecution(); 00044 } 00045 00046 uint64_t end = core::getTimestamp(); 00047 00048 uint64_t result = end-begin; 00049 if(begin>end) { 00050 cout << "Fatal Error" << endl; 00051 abort(); 00052 } 00053 cout << result << endl; 00054 } 00055 00056 00057 //string algorithm_name = sched_dec.getNameofChoosenAlgorithm(); 00058 00059 return 0; 00060 }; 00061