Critical bug fixed, still looking at distributed tree.

This commit is contained in:
Dongryeol Lee
2011-01-10 22:01:24 +00:00
parent ca78d9477f
commit eeca2ebccb
6 changed files with 85 additions and 11 deletions
@@ -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);
@@ -200,6 +200,11 @@ class DistributedTreeBuilder {
std::vector<int> 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<typename MetricType>
@@ -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.
*/
@@ -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:
@@ -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<typename MetricType>
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<double>(count)) * bound_ref;
@@ -142,20 +142,22 @@ class GeneralBinarySpaceTree {
public:
/** @brief A method for serializing a node. This method does not
* save the children.
*/
template<class Archive>
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<class Archive>
void load(Archive &ar, const unsigned int version) {
// This does not get the children.
ar & bound_;
ar & begin_;
ar & count_;