diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/CMakeLists.txt b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/CMakeLists.txt index fa5539bf30..059912ce14 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/CMakeLists.txt +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/CMakeLists.txt @@ -6,6 +6,9 @@ set(SOURCES dense_matrix.h dense_point.h distributed_table.h + distributed_table_message.h + mailbox.h + point_request_message.h table.h transform.h ) diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/distributed_table.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/distributed_table.h index 8fd669fbd1..cece8f48f2 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/distributed_table.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/distributed_table.h @@ -12,131 +12,12 @@ #include "boost/thread.hpp" #include "boost/serialization/string.hpp" #include "core/table/table.h" +#include "core/table/distributed_table_message.h" +#include "core/table/point_request_message.h" +#include "core/table/mailbox.h" namespace core { namespace table { - -class PointRequestMessage { - private: - bool is_valid_; - - int source_rank_; - - int point_id_; - - friend class boost::serialization::access; - - public: - - template - void serialize(Archive &ar, const unsigned int version) { - ar & source_rank_; - ar & point_id_; - } - - PointRequestMessage() { - Reset(); - } - - PointRequestMessage(int source_rank_in, int point_id_in) { - source_rank_ = source_rank_in; - point_id_ = point_id_in; - } - - bool is_valid() const { - return is_valid_; - } - - void Reset() { - is_valid_ = false; - source_rank_ = -1; - point_id_ = -1; - } - - void set_valid() { - is_valid_ = true; - } - - int source_rank() const { - return source_rank_; - } - - int point_id() const { - return point_id_; - } -}; - -class DistributedTableMessage { - public: - enum DistributedTableRequest { REQUEST_POINT, RECEIVE_POINT, TERMINATE_SERVER }; -}; - -class Mailbox { - public: - - boost::mutex termination_mutex_; - - boost::condition_variable termination_cond_; - - boost::mutex mutex_; - - boost::condition_variable point_ready_cond_; - - boost::mpi::communicator *communicator_; - - std::pair < - boost::mpi::request, - core::table::PointRequestMessage > incoming_request_; - - boost::mpi::request outgoing_request_; - - std::pair< boost::mpi::request, bool> incoming_receive_request_; - - int incoming_receive_source_; - - std::vector incoming_point_; - - std::vector outgoing_point_; - - public: - - bool is_done() { - - bool first = (communicator_->iprobe( - boost::mpi::any_source, - core::table::DistributedTableMessage::TERMINATE_SERVER)); - bool second = first && - (!communicator_->iprobe( - boost::mpi::any_source, - core::table::DistributedTableMessage::REQUEST_POINT)); - bool third = second && - (!communicator_->iprobe( - boost::mpi::any_source, - core::table::DistributedTableMessage::RECEIVE_POINT)); - bool fourth = ( - third && incoming_request_.second.is_valid() == false && - incoming_receive_request_.second == false); - if(fourth) { - try { - bool outgoing_request_done = outgoing_request_.test(); - fourth = fourth && outgoing_request_done; - } - catch(boost::mpi::exception &e) { - } - } - return fourth; - } - - void set_communicator(boost::mpi::communicator *comm_in) { - communicator_ = comm_in; - } - - Mailbox() { - communicator_ = NULL; - incoming_receive_request_.second = false; - } -}; - class DistributedTable: public boost::noncopyable { typedef core::tree::GeneralBinarySpaceTree < core::tree::BallBound < diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/distributed_table_message.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/distributed_table_message.h new file mode 100644 index 0000000000..5bb06d56c2 --- /dev/null +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/distributed_table_message.h @@ -0,0 +1,18 @@ +/** @file distributed_table_message.h + * + * @author Dongryeol Lee (dongryel@cc.gatech.edu) + */ + +#ifndef CORE_TABLE_DISTRIBUTED_TABLE_MESSAGE_H +#define CORE_TABLE_DISTRIBUTED_TABLE_MESSAGE_H + +namespace core { +namespace table { +class DistributedTableMessage { + public: + enum DistributedTableRequest { REQUEST_POINT, RECEIVE_POINT, TERMINATE_SERVER }; +}; +}; +}; + +#endif diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/mailbox.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/mailbox.h new file mode 100644 index 0000000000..8b32dcf2c3 --- /dev/null +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/mailbox.h @@ -0,0 +1,81 @@ +/** @file point_request_message.h + * + * @author Dongryeol Lee (dongryel@cc.gatech.edu) + */ + +#ifndef CORE_TABLE_MAILBOX_H +#define CORE_TABLE_MAILBOX_H + +#include "core/table/distributed_table_message.h" + +namespace core { +namespace table { +class Mailbox { + public: + + boost::mutex termination_mutex_; + + boost::condition_variable termination_cond_; + + boost::mutex mutex_; + + boost::condition_variable point_ready_cond_; + + boost::mpi::communicator *communicator_; + + std::pair < + boost::mpi::request, + core::table::PointRequestMessage > incoming_request_; + + boost::mpi::request outgoing_request_; + + std::pair< boost::mpi::request, bool> incoming_receive_request_; + + int incoming_receive_source_; + + std::vector incoming_point_; + + std::vector outgoing_point_; + + public: + + bool is_done() { + + bool first = (communicator_->iprobe( + boost::mpi::any_source, + core::table::DistributedTableMessage::TERMINATE_SERVER)); + bool second = first && + (!communicator_->iprobe( + boost::mpi::any_source, + core::table::DistributedTableMessage::REQUEST_POINT)); + bool third = second && + (!communicator_->iprobe( + boost::mpi::any_source, + core::table::DistributedTableMessage::RECEIVE_POINT)); + bool fourth = ( + third && incoming_request_.second.is_valid() == false && + incoming_receive_request_.second == false); + if(fourth) { + try { + bool outgoing_request_done = outgoing_request_.test(); + fourth = fourth && outgoing_request_done; + } + catch(boost::mpi::exception &e) { + } + } + return fourth; + } + + void set_communicator(boost::mpi::communicator *comm_in) { + communicator_ = comm_in; + } + + Mailbox() { + communicator_ = NULL; + incoming_receive_request_.second = false; + } +}; +}; +}; + +#endif diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/point_request_message.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/point_request_message.h new file mode 100644 index 0000000000..680c0e1364 --- /dev/null +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/point_request_message.h @@ -0,0 +1,64 @@ +/** @file point_request_message.h + * + * @author Dongryeol Lee (dongryel@cc.gatech.edu) + */ + +#ifndef CORE_TABLE_POINT_REQUEST_MESSAGE_H +#define CORE_TABLE_POINT_REQUEST_MESSAGE_H + +namespace core { +namespace table { + +class PointRequestMessage { + private: + bool is_valid_; + + int source_rank_; + + int point_id_; + + friend class boost::serialization::access; + + public: + + template + void serialize(Archive &ar, const unsigned int version) { + ar & source_rank_; + ar & point_id_; + } + + PointRequestMessage() { + Reset(); + } + + PointRequestMessage(int source_rank_in, int point_id_in) { + source_rank_ = source_rank_in; + point_id_ = point_id_in; + } + + bool is_valid() const { + return is_valid_; + } + + void Reset() { + is_valid_ = false; + source_rank_ = -1; + point_id_ = -1; + } + + void set_valid() { + is_valid_ = true; + } + + int source_rank() const { + return source_rank_; + } + + int point_id() const { + return point_id_; + } +}; +}; +}; + +#endif