Skip to content
Snippets Groups Projects
Commit 9dccc983 authored by lykos98's avatar lykos98
Browse files

implementation of kdtree w boxes

parent c3d215a2
No related branches found
No related tags found
No related merge requests found
......@@ -659,10 +659,7 @@ void get_pointset_from_partition(pointset_t *ps, partition_t *part)
ps->n_points = part->n_points;
}
guess_t compute_median_pure_binning(global_context_t *ctx, pointset_t *ps,
float_t fraction,
int selected_dim, int n_bins,
float_t tolerance)
guess_t compute_median_pure_binning(global_context_t *ctx, pointset_t *ps, float_t fraction, int selected_dim, int n_bins, float_t tolerance)
{
int best_bin_idx;
float_t ep;
......@@ -679,12 +676,24 @@ guess_t compute_median_pure_binning(global_context_t *ctx, pointset_t *ps,
return g;
}
int compute_n_nodes(int n)
{
if(n == 1) return 1;
int nl = n/2;
int nr = n - nl;
return 1 + compute_n_nodes(nl) + compute_n_nodes(nr);
}
void top_tree_init(global_context_t *ctx, top_kdtree_t *tree)
{
/* we want procs leaves */
int l = (int)(ceil(log2((float_t)ctx -> world_size)));
int tree_nodes = (1 << (l + 1)) - 1;
//MPI_DB_PRINT("Tree nodes %d %d %d %d\n", ctx -> world_size,l, tree_nodes, compute_n_nodes(ctx -> world_size));
tree->_nodes = (top_kdtree_node_t*)malloc(tree_nodes * sizeof(top_kdtree_node_t));
tree->_capacity = tree_nodes;
tree->dims = ctx->dims;
tree->count = 0;
tree->_capacity = 100;
tree->_nodes = (top_kdtree_node_t *)malloc(tree->_capacity * sizeof(top_kdtree_node_t));
return;
}
......@@ -701,13 +710,9 @@ void top_tree_free(global_context_t *ctx, top_kdtree_t *tree)
top_kdtree_node_t* top_tree_generate_node(global_context_t* ctx, top_kdtree_t* tree)
{
if (tree->count == tree->_capacity)
{
int new_cap = tree->_capacity * 1.1;
tree->_nodes = realloc(tree->_nodes, new_cap * sizeof(top_kdtree_node_t));
tree->_capacity = new_cap;
}
top_kdtree_node_t* ptr = tree -> _nodes + tree -> count;
ptr -> lch = NULL;
ptr -> rch = NULL;
ptr -> lb_node_box = (float_t*)malloc(ctx -> dims * sizeof(float_t));
ptr -> ub_node_box = (float_t*)malloc(ctx -> dims * sizeof(float_t));
ptr -> owner = -1;
......@@ -722,8 +727,10 @@ void tree_print(global_context_t* ctx, top_kdtree_node_t* root)
MPI_DB_PRINT("\n\tparent %p", root -> parent);
MPI_DB_PRINT("\n\towner %d", root -> owner);
MPI_DB_PRINT("\n\tbox");
MPI_DB_PRINT("\n\tlch %p", root -> lch);
MPI_DB_PRINT("\n\trch %p\n", root -> rch);
for(size_t d = 0; d < ctx -> dims; ++d) MPI_DB_PRINT("\n\t d%d:[%lf, %lf]",(int)d, root -> lb_node_box[d], root -> ub_node_box[d]);
MPI_DB_PRINT("\n\n");
MPI_DB_PRINT("\n");
if(root -> lch) tree_print(ctx, root -> lch);
if(root -> rch) tree_print(ctx, root -> rch);
}
......@@ -772,8 +779,9 @@ void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree
/*generate a tree node */
top_kdtree_node_t* current_node = current_node = top_tree_generate_node(ctx, tree);
top_kdtree_node_t* current_node = top_tree_generate_node(ctx, tree);
/* insert node */
/*
MPI_DB_PRINT("Handling partition: \n\tcurrent_node %p, \n\tdim %d, \n\tn_points %d, \n\tstart_proc %d, \n\tn_procs %d, \n\tparent %p\n",
current_node,
......@@ -825,7 +833,7 @@ void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree
current_node -> lb_node_box[parent_split_dim] = parent_hp;
}
break;
default:
case NO_CHILD:
{
tree -> root = current_node;
memcpy(current_node -> lb_node_box, og_pointset -> lb_box, ctx -> dims * sizeof(float_t));
......@@ -854,11 +862,15 @@ void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree
int procs_left = current_partition.n_procs * fraction;
int procs_right = current_partition.n_procs - procs_left;
/*
MPI_DB_PRINT("Chosing as guess: %lf, seareching for %lf, obtained %lf\n", g.x_guess, fraction, g.ep);
MPI_DB_PRINT("-------------------\n\n");
*/
int next_dimension = (++selected_dim) % (ctx->dims);
partition_t left_partition = {
.n_points = points_left,
......@@ -882,17 +894,25 @@ void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree
enqueue_partition(&queue, left_partition);
enqueue_partition(&queue, right_partition);
MPI_Barrier(ctx -> mpi_communicator);
}
else
{
current_node -> owner = current_partition.start_proc;
}
}
tree -> root = tree -> _nodes;
MPI_DB_PRINT("Root is %p\n", tree -> root);
if(I_AM_MASTER)
{
tree_print(ctx, tree -> root);
}
free(current_pointset.lb_box);
free(current_pointset.ub_box);
free_queue(&queue);
}
void simulate_master_read_and_scatter(int dims, size_t n, global_context_t *ctx)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment