From eeca2ebccbb1e3863d3c65a6153d27d08fbd7242 Mon Sep 17 00:00:00 2001 From: Dongryeol Lee Date: Mon, 10 Jan 2011 22:01:24 +0000 Subject: [PATCH] Critical bug fixed, still looking at distributed tree. --- .../core/parallel/distributed_tree.test.cc | 4 +- .../core/parallel/distributed_tree_builder.h | 27 ++++++++++++++ .../core/table/offset_dense_matrix.h | 37 +++++++++++++++++++ .../thesis_research/core/tree/ball_bound.h | 7 ++++ .../core/tree/gen_metric_tree.h | 11 +++--- .../core/tree/general_spacetree.h | 10 +++-- 6 files changed, 85 insertions(+), 11 deletions(-) diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/parallel/distributed_tree.test.cc b/fastlib/trunk/contrib/dongryel/thesis_research/core/parallel/distributed_tree.test.cc index b175f8a456..78ef4ab40f 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/parallel/distributed_tree.test.cc +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/parallel/distributed_tree.test.cc @@ -45,10 +45,10 @@ class TestDistributedTree { // Only the master broadcasts the dimension; int num_dimensions; if(world.rank() == 0) { - num_dimensions = core::math::RandInt(3, 20); + num_dimensions = core::math::RandInt(3, 4); } boost::mpi::broadcast(world, num_dimensions, 0); - int num_points = core::math::RandInt(300, 501); + int num_points = core::math::RandInt(10, 21); if(StressTest(world, num_dimensions, num_points) == false) { printf("Failed!\n"); exit(0); diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/parallel/distributed_tree_builder.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/parallel/distributed_tree_builder.h index f9d32bf6c3..728d212cd8 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/parallel/distributed_tree_builder.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/parallel/distributed_tree_builder.h @@ -200,6 +200,11 @@ class DistributedTreeBuilder { std::vector sampled_indices; SelectSubset_(&sampled_indices); + distributed_table_->local_table()->data().Print(); + for(unsigned int i = 0; i < sampled_indices.size(); i++) { + printf("Process %d selects %d\n", world.rank(), sampled_indices[i]); + } + // Send the number of points chosen in this process to the // master so that the master can allocate the appropriate amount // of space to receive all the points. @@ -222,6 +227,14 @@ class DistributedTreeBuilder { sampled_table.Init( distributed_table_->n_attributes(), total_num_samples); SetupGatherPointers_(sampled_table, counts, &gather_pointers); + + // The master process actually needs to setup its own portion + // manually since MPI gather does not call + // serialize/unserialize on the self. + local_pointer.Export( + gather_pointers[0].matrix(), + gather_pointers[0].old_from_new(), + gather_pointers[0].starting_column_index()); } boost::mpi::gather(world, local_pointer, gather_pointers, 0); @@ -229,6 +242,10 @@ class DistributedTreeBuilder { // the number of processes. If missing some nodes, then sample a // region and try to make up a node. if(world.rank() == 0) { + + sampled_table.data().Print(); + + top_leaf_nodes_out->resize(0); sampled_table.IndexData(metric_in, 1, world.size()); sampled_table.get_leaf_nodes( sampled_table.get_tree(), top_leaf_nodes_out); @@ -243,7 +260,17 @@ class DistributedTreeBuilder { top_leaf_nodes_out->begin(), top_leaf_nodes_out->end(), MortonOrderNodes_); } + else { + top_leaf_nodes_out->resize(world.size()); + std::fill( + top_leaf_nodes_out->begin(), top_leaf_nodes_out->end(), + new TreeType()); + } boost::mpi::broadcast(world, *top_leaf_nodes_out, 0); + + for(unsigned int i = 0; i < top_leaf_nodes_out->size(); i++) { + (*top_leaf_nodes_out)[i]->bound().center().Print(); + } } template diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/offset_dense_matrix.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/offset_dense_matrix.h index 000019e8ac..32d2cefd60 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/offset_dense_matrix.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/offset_dense_matrix.h @@ -46,6 +46,18 @@ class SampleDenseMatrix { public: + core::table::DenseMatrix *matrix() { + return matrix_; + } + + OldFromNewIndexType *old_from_new() { + return old_from_new_; + } + + int starting_column_index() const { + return starting_column_index_; + } + /** @brief The default constructor that initializes every member * to its default value. */ @@ -85,6 +97,31 @@ class SampleDenseMatrix { num_entries_to_load_ = num_entries_to_load_in; } + /** @brief Extract a given list of indices of points along with + * its old_from_new mappings onto new destinations. + */ + void Export( + core::table::DenseMatrix *matrix_out, + OldFromNewIndexType *old_from_new_out, + int starting_column_index_in) const { + + int destination_column_index = starting_column_index_in; + for(unsigned int i = 0; i < indices_to_be_serialized_->size(); + i++, destination_column_index++) { + int source_point_index = (*indices_to_be_serialized_)[i]; + core::table::DensePoint source_point; + matrix_->MakeColumnVector(source_point_index, &source_point); + core::table::DensePoint destination_point; + matrix_out->MakeColumnVector( + destination_column_index, &destination_point); + for(int j = 0; j < source_point.length(); j++) { + destination_point[j] = source_point[j]; + } + old_from_new_out[destination_column_index] = + old_from_new_[source_point_index]; + } + } + /** @brief Serialize a given list of indices of points along with * its old_from_new mappings. */ diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/ball_bound.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/ball_bound.h index da2c571555..9ec103b1f6 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/ball_bound.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/ball_bound.h @@ -23,9 +23,16 @@ namespace tree { class BallBound { private: + + /** @brief The radius of the ball bound. + */ double radius_; + + /** @brief The center of the ball bound. + */ core::table::DensePoint center_; + // For boost serialization. friend class boost::serialization::access; public: diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/gen_metric_tree.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/gen_metric_tree.h index 1fdc773cab..f9c239bb55 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/gen_metric_tree.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/gen_metric_tree.h @@ -25,6 +25,10 @@ class GenMetricTree { typedef IncomingStatisticType StatisticType; private: + + /** @brief Computes the furthest point from the given pivot and + * finds out the index. + */ template static int FurthestColumnIndex_( const MetricType &metric_in, @@ -48,7 +52,6 @@ class GenMetricTree { furthest_index = i; } } - return furthest_index; } @@ -72,14 +75,12 @@ class GenMetricTree { bounds->center().SetZero(); int end = begin + count; - core::table::DensePoint col_point; arma::vec bound_ref; core::table::DensePointToArmaVec(bounds->center(), &bound_ref); for(int i = begin; i < end; i++) { + arma::vec col_point; matrix.MakeColumnVector(i, &col_point); - arma::vec col_point_ref; - core::table::DensePointToArmaVec(col_point, &col_point_ref); - bound_ref += col_point_ref; + bound_ref += col_point; } bound_ref = (1.0 / static_cast(count)) * bound_ref; 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 d17cea4660..6fcf26ee8b 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 @@ -142,20 +142,22 @@ class GeneralBinarySpaceTree { public: + /** @brief A method for serializing a node. This method does not + * save the children. + */ template void save(Archive &ar, const unsigned int version) const { - - // This does not save the children. ar & bound_; ar & begin_; ar & count_; ar & stat_; } + /** @brief A method for unserializing a node. This does not + * recover its children though. + */ template void load(Archive &ar, const unsigned int version) { - - // This does not get the children. ar & bound_; ar & begin_; ar & count_;