diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/dense_matrix.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/dense_matrix.h index 0dc5739c96..f2343b96aa 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/dense_matrix.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/dense_matrix.h @@ -15,6 +15,7 @@ namespace table { class DenseMatrix { private: + boost::interprocess::offset_ptr ptr_; int n_rows_; 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 a17d68cbe5..0e21310ceb 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 @@ -57,7 +57,12 @@ class DistributedTable: public boost::noncopyable { void AssignLeafNodes_( const core::metric_kernels::AbstractMetric &metric_in, const std::vector &top_leaf_nodes, - std::vector *point_assignments) { + std::vector *point_assignments, + bool *points_assigned_to_node) { + + for(unsigned int i = 0; i < top_leaf_nodes.size(); i++) { + points_assigned_to_node[i] = 0; + } // Loop through each point and find the closest leaf node. for(int i = 0; i < owned_table_->n_entries(); i++) { @@ -65,6 +70,8 @@ class DistributedTable: public boost::noncopyable { owned_table_->get(i, &point); // Loop through each leaf node. + double min_squared_mid_distance = std::numeric_limits::max(); + int min_index = -1; for(unsigned int j = 0; j < top_leaf_nodes.size(); j++) { const typename TreeType::BoundType &leaf_node_bound = top_leaf_nodes[j]->bound(); @@ -72,7 +79,15 @@ class DistributedTable: public boost::noncopyable { // Compute the squared mid-distance. double squared_mid_distance = leaf_node_bound.MidDistanceSq( metric_in, point); + if(squared_mid_distance < min_squared_mid_distance) { + min_squared_mid_distance = squared_mid_distance; + min_index = j; + } } + + // Output the assignments. + point_assignments->push_back(min_index); + points_assigned_to_node[min_index] = true; } } @@ -314,7 +329,7 @@ class DistributedTable: public boost::noncopyable { // The master builds the top tree, and sends the leaf nodes to // the rest. - std::vector top_leaf_nodes; + std::vector top_leaf_nodes; if(table_outbox_group_comm.rank() == 0) { sampled_table.IndexData( metric_in, leaf_size, table_outbox_group_comm.size()); @@ -332,7 +347,35 @@ class DistributedTable: public boost::noncopyable { // Assign each point to one of the leaf nodes. std::vector point_assignments; - AssignLeafNodes_(metric_in, top_leaf_nodes, &point_assignments); + bool *local_points_assigned_to_node = new bool[top_leaf_nodes.size()]; + bool *points_assigned_to_node = NULL; + AssignLeafNodes_( + metric_in, top_leaf_nodes, &point_assignments, + local_points_assigned_to_node); + + // Do a reduction to find whether at least one point has been + // assigned to each partition. + if(table_outbox_group_comm.rank() == 0) { + points_assigned_to_node = new bool[top_leaf_nodes.size()]; + boost::mpi::reduce( + table_outbox_group_comm, local_points_assigned_to_node, + top_leaf_nodes.size(), points_assigned_to_node, + std::logical_or(), 0); + + + printf("Checking:\n"); + for(unsigned int i = 0; i < top_leaf_nodes.size(); i++) { + printf(" %d ", points_assigned_to_node[i]); + } + printf("\n"); + } + else { + boost::mpi::reduce( + table_outbox_group_comm, local_points_assigned_to_node, + top_leaf_nodes.size(), std::logical_or(), 0); + } + + delete[] points_assigned_to_node; } void get( diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/general_spacetree.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/general_spacetree.h index 6e7864d6cc..76039be6d3 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/general_spacetree.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/general_spacetree.h @@ -26,6 +26,13 @@ */ #include +#include "core/table/memory_mapped_file.h" + +namespace core { +namespace table { +extern core::table::MemoryMappedFile *global_m_file_; +}; +}; namespace core { namespace tree { @@ -65,15 +72,38 @@ class GeneralBinarySpaceTree { friend class boost::serialization::access; template - void serialize(Archive &ar, const unsigned int version) { + void save(Archive &ar, const unsigned int version) const { ar & bound_; ar & begin_; ar & count_; - ar & left_; - ar & right_; ar & stat_; + GeneralBinarySpaceTree *left_ptr = left_.get(); + GeneralBinarySpaceTree *right_ptr = right_.get(); + ar & left_ptr; + ar & right_ptr; } + template + void load(Archive &ar, const unsigned int version) { + ar & bound_; + ar & begin_; + ar & count_; + ar & stat_; + GeneralBinarySpaceTree *left_ptr_in = + (core::table::global_m_file_) ? + core::table::global_m_file_->Construct() : + new GeneralBinarySpaceTree(); + GeneralBinarySpaceTree *right_ptr_in = + (core::table::global_m_file_) ? + core::table::global_m_file_->Construct() : + new GeneralBinarySpaceTree(); + ar & left_ptr_in; + ar & right_ptr_in; + left_ = left_ptr_in; + right_ = right_ptr_in; + } + BOOST_SERIALIZATION_SPLIT_MEMBER() + ~GeneralBinarySpaceTree() { if(left_ != NULL) { delete left_.get(); diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/distributed_kde/distributed_kde.cc b/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/distributed_kde/distributed_kde.cc index 4e9db1826f..92b2482ae7 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/distributed_kde/distributed_kde.cc +++ b/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/distributed_kde/distributed_kde.cc @@ -199,11 +199,15 @@ int main(int argc, char *argv[]) { // Wait until the memory allocator is in synch. world.barrier(); - // Read the distributed table once per each compute node, and put a - // barrier. + // Read the distributed table once per each compute node, and build + // the tree, and barrier. if(membership_key == 0) { distributed_table = InitDistributedTable(world, local_group_comm); + + core::metric_kernels::LMetric<2> l2_metric; + distributed_table->IndexData( + l2_metric, local_group_comm, 3, 0.5); } world.barrier(); diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/kde/kde_dualtree.h b/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/kde/kde_dualtree.h index 3dd751ac63..85a7625720 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/kde/kde_dualtree.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/mlpack/kde/kde_dualtree.h @@ -7,7 +7,8 @@ #define MLPACK_KDE_KDE_DUALTREE_H #include -#include "boost/math/distributions/normal.hpp" +#include +#include #include "core/monte_carlo/mean_variance_pair.h" #include "core/metric_kernels/kernel.h" #include "core/tree/statistic.h" @@ -17,6 +18,10 @@ namespace mlpack { namespace kde { class KdePostponed { + private: + + friend class boost::serialization::access; + public: double densities_l_; @@ -27,6 +32,14 @@ class KdePostponed { double used_error_; + template + void serialize(Archive &ar, const unsigned int version) { + ar & densities_l_; + ar & densities_u_; + ar & pruned_; + ar & used_error_; + } + KdePostponed() { } @@ -354,6 +367,10 @@ class KdeDelta { class KdeSummary { + private: + + friend class boost::serialization::access; + public: double densities_l_; @@ -364,6 +381,14 @@ class KdeSummary { double used_error_u_; + template + void serialize(Archive &ar, const unsigned int version) { + ar & densities_l_; + ar & densities_u_; + ar & pruned_l_; + ar & used_error_u_; + } + KdeSummary() { SetZero(); } @@ -564,6 +589,9 @@ class KdeSummary { class KdeStatistic { private: + + friend class boost::serialization::access; + KdeStatistic(const KdeStatistic &stat_in) { } @@ -573,6 +601,12 @@ class KdeStatistic { mlpack::kde::KdeSummary summary_; + template + void serialize(Archive &ar, const unsigned int version) { + ar & postponed_; + ar & summary_; + } + KdeStatistic() { }