Column-oriented GPU-accelerated Database Management System
CoGaDB
/home/sebastian/gpudbms/trunk/hype-library/include/query_processing/binary_operator.hpp
Go to the documentation of this file.
00001 #pragma once
00002 
00003 //#include <core/scheduling_decision.hpp>
00004 //#include <boost/shared_ptr.hpp>
00005 
00006 #include <config/global_definitions.hpp>
00007 #include <config/configuration.hpp>
00008 #include "operator.hpp"
00009 #include "typed_operator.hpp"
00010 
00011 
00012 //#ifndef HYPE_ENABLE_PARALLEL_QUERY_PLAN_EVALUATION
00013 //      #define HYPE_ENABLE_PARALLEL_QUERY_PLAN_EVALUATION
00014 //#endif
00015 
00016 
00017 #ifdef HYPE_ENABLE_PARALLEL_QUERY_PLAN_EVALUATION
00018     #include <boost/thread.hpp>
00019     #include <boost/bind.hpp>
00020 #endif
00021 
00022 namespace hype {
00023     namespace queryprocessing {
00024 
00025         template <typename OperatorInputTypeLeftChild, typename OperatorInputTypeRightChild, typename OperatorOutputType>
00026         class BinaryOperator : public TypedOperator<OperatorOutputType> { //uses 2D Learning Method
00027         public:
00028             //typedef typename OperatorMapper_Helper_Template<OperatorOutputType>::TypedOperator TypedOperator;
00029             typedef typename OperatorMapper_Helper_Template<OperatorOutputType>::TypedOperatorPtr TypedOperatorPtr;
00030             typedef typename OperatorMapper_Helper_Template<OperatorOutputType>::TypedNodePtr TypedNodePtr;
00031 
00032             BinaryOperator(const hype::SchedulingDecision& sched_dec,
00033                     boost::shared_ptr<TypedOperator<OperatorInputTypeLeftChild> > left_child,
00034                     boost::shared_ptr<TypedOperator<OperatorInputTypeRightChild> > right_child)
00035             : TypedOperator<OperatorOutputType>(sched_dec), left_child_(left_child), right_child_(right_child) {
00036             }
00037 
00038             virtual ~BinaryOperator() {
00039 
00040             }
00041 
00042             OperatorInputTypeLeftChild getInputDataLeftChild() {
00043                 return this->left_child_->getResult();
00044             }
00045 
00046             OperatorInputTypeRightChild getInputDataRightChild() {
00047                 return this->right_child_->getResult();
00048             }
00049 
00050             virtual bool run() {
00051                 if (!hype::core::Runtime_Configuration::instance().isQueryChoppingEnabled()) {
00052 #ifdef HYPE_ENABLE_PARALLEL_QUERY_PLAN_EVALUATION
00053                 //std::cout << "Binary Operator: launching both childs in parallel" << std::endl;
00054                 boost::thread_group threads;
00055                 if (left_child_) {
00056                     //left_child_->run();
00057                     threads.add_thread(new boost::thread(boost::bind(&TypedOperator<OperatorInputTypeLeftChild>::run, left_child_.get())));
00058                 }
00059                 if (right_child_) {
00060                     //right_child_->run();
00061                     threads.add_thread(new boost::thread(boost::bind(&TypedOperator<OperatorInputTypeLeftChild>::run, right_child_.get())));
00062                 }
00063                 threads.join_all();
00064 #else                                                
00065                 if (left_child_) {
00066                     left_child_->run();
00067                 }
00068                 if (right_child_) {
00069                     right_child_->run();
00070                 }
00071 #endif
00072                 }
00073                 //execute this operator
00074                 double begin = double(hype::core::getTimestamp());
00075                 timeEstimated = double(this->getEstimatedExecutionTime().getTimeinNanoseconds());
00076                 bool retVal = (*this)();
00077                 timeNeeded = double( hype::core::getTimestamp()) - begin;
00078                 return retVal;
00079             }
00080 
00081             virtual void print(unsigned int tree_level) const {
00082                 for (unsigned int i = 0; i < tree_level; ++i) {
00083                     std::cout << "\t";
00084                 }
00085                 assert(!this->getFeatureValues().empty());
00086                 std::cout << this->getAlgorithmName() << " ET: " << this->getEstimatedExecutionTime().getTimeinNanoseconds()
00087                         << "\tEC: " << this->getFeatureValues()[0]
00088                         << std::endl; // << " Features: " << this->getFeatureValues() << std::endl;
00089                 if (left_child_) left_child_->print(tree_level + 1);
00090                 if (right_child_) right_child_->print(tree_level + 1);
00091             }
00092 
00093             virtual void printResult(unsigned int tree_level) const {
00094                 for (unsigned int i = 0; i < tree_level; ++i) {
00095                     std::cout << "\t";
00096                 }
00097                 assert(!this->getFeatureValues().empty());
00098                 std::cout << this->getAlgorithmName() << " ET: " << timeEstimated
00099                         << "\tMT: " << timeNeeded
00100                         << "\tEE: " << 1 - (timeEstimated / timeNeeded)
00101                         << "\tEC: " << this->getFeatureValues()[0];
00102                 if (this->getResultSize() != -1) {
00103                     std::cout << "\tRR: " << this->getResultSize();
00104                 }
00105                 std::cout << std::endl;
00106                 if (left_child_) left_child_->printResult(tree_level + 1);
00107                 if (right_child_) right_child_->printResult(tree_level + 1);
00108             }
00109 
00110             virtual double getRecursiveExecutionTimeInNanoseconds() {
00111                 double executiontime = this->getEstimatedExecutionTime().getTimeinNanoseconds();
00112                 if (executiontime < 0) {
00113                     executiontime = 0;
00114                 }
00115                 if (!hype::core::Runtime_Configuration::instance().isQueryChoppingEnabled()) {
00116                 if (left_child_) {
00117                     executiontime += left_child_->getRecursiveExecutionTimeInNanoseconds();
00118                 }
00119                 if (right_child_) {
00120                     executiontime += right_child_->getRecursiveExecutionTimeInNanoseconds();
00121                 }
00122                 } else {
00123                 if (left_child_ && right_child_) {
00124                     if (left_child_->getRecursiveExecutionTimeInNanoseconds() > right_child_->getRecursiveExecutionTimeInNanoseconds()) {
00125                         executiontime += left_child_->getRecursiveExecutionTimeInNanoseconds();
00126                     } else {
00127                         executiontime += right_child_->getRecursiveExecutionTimeInNanoseconds();
00128                     }
00129                 } else {
00130                 if (left_child_) {
00131                     executiontime += left_child_->getRecursiveExecutionTimeInNanoseconds();
00132                 }
00133                 if (right_child_) {
00134                     executiontime += right_child_->getRecursiveExecutionTimeInNanoseconds();
00135                     }
00136                     }
00137                 }
00138 
00139                 return executiontime;
00140             }
00141             /*
00142             virtual std::list<TypedOperator<OperatorOutputType>& > getOperatorQueue(){
00143 
00144                     std::list<TypedOperator<OperatorOutputType>& > left_list = left_child_->getOperatorQueue();
00145                     left_list.push_front(*this);
00146 
00147                     std::list<TypedOperator<OperatorOutputType>& > right_list = right_child_->getOperatorQueue();
00148 
00149                     left_list.insert(left_list.end(),right_list.begin(),right_list.end());
00150                     return left_list;
00151                     //this->left_child_->
00152             }*/
00153 
00154         private:
00155             double timeNeeded;
00156             double timeEstimated;
00157 
00158             boost::shared_ptr<TypedOperator<OperatorInputTypeLeftChild> > left_child_;
00159             boost::shared_ptr<TypedOperator<OperatorInputTypeRightChild> > right_child_;
00160 
00161             //boost::shared_ptr<TypedOperator<OperatorOutputType> > succsessor_;
00162         };
00163 
00164 
00165     }; //end namespace queryprocessing
00166 }; //end namespace hype
00167 
00168 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines