diff --git a/src/tree/tree.c b/src/tree/tree.c index ac507a4c8c39766ad05506c25672251df4795f07..2ab45ed8efea14b7e598a4b9e7b41c720e81799e 100644 --- a/src/tree/tree.c +++ b/src/tree/tree.c @@ -1209,8 +1209,8 @@ void top_tree_free(global_context_t *ctx, top_kdtree_t *tree) { for(int i = 0; i < tree -> count; ++i) { - if(tree -> _nodes[i].node_box_lb) free(tree -> _nodes[i].node_box_lb); - if(tree -> _nodes[i].node_box_ub) free(tree -> _nodes[i].node_box_ub); + if(tree -> _nodes[i].lb_node_box) free(tree -> _nodes[i].lb_node_box); + if(tree -> _nodes[i].ub_node_box) free(tree -> _nodes[i].ub_node_box); } free(tree->_nodes); return; @@ -1225,18 +1225,13 @@ top_kdtree_node_t* top_tree_generate_node(global_context_t* ctx, top_kdtree_t* t tree->_capacity = new_cap; } top_kdtree_node_t* ptr = tree -> _nodes + tree -> count; - ptr -> node_box_lb = (float_t*)malloc(ctx -> dims * sizeof(float_t)); - ptr -> node_box_ub = (float_t*)malloc(ctx -> dims * sizeof(float_t)); + ptr -> lb_node_box = (float_t*)malloc(ctx -> dims * sizeof(float_t)); + ptr -> ub_node_box = (float_t*)malloc(ctx -> dims * sizeof(float_t)); ++tree -> count; return ptr; } -void compute_boxes(global_context_t* ctx, top_kdtree_t* tree) -{ - return; -} - void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree_t *tree, int n_bins, float_t tolerance) { size_t tot_n_points = 0; @@ -1256,12 +1251,12 @@ void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree init_queue(&queue); int selected_dim = 0; - partition_t current_partition = {.d = selected_dim, - .base_ptr = og_pointset->data, - .n_points = og_pointset->n_points, - .n_procs = ctx->world_size, - .parent = NULL, - .lr = NO_CHILD + partition_t current_partition = { .d = selected_dim, + .base_ptr = og_pointset->data, + .n_points = og_pointset->n_points, + .n_procs = ctx->world_size, + .parent = NULL, + .lr = NO_CHILD }; enqueue_partition(&queue, current_partition); @@ -1283,6 +1278,7 @@ void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree top_kdtree_node_t* current_node = 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, current_partition.d, @@ -1290,29 +1286,59 @@ void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree current_partition.start_proc, current_partition.n_procs, current_partition.parent); - MPI_DB_PRINT("-------------------\n\n"); + */ switch (current_partition.lr) { case TOP_TREE_LCH: if(current_partition.parent) { - current_node -> parent = current_partition.parent; + current_node -> parent = current_partition.parent; current_node -> parent -> lch = current_node; + /* compute the box */ + /* + * left child has lb equal to parent + * ub equal to parent except for the dim of splitting + */ + int parent_split_dim = current_node -> parent -> split_dim; + float_t parent_hp = current_node -> parent -> data; + + memcpy(current_node -> lb_node_box, current_node -> parent -> lb_node_box, ctx -> dims * sizeof(float_t)); + memcpy(current_node -> ub_node_box, current_node -> parent -> ub_node_box, ctx -> dims * sizeof(float_t)); + + current_node -> ub_node_box[parent_split_dim] = parent_hp; } break; case TOP_TREE_RCH: if(current_partition.parent) { - current_node -> parent = current_partition.parent; + current_node -> parent = current_partition.parent; current_node -> parent -> rch = current_node; + + int parent_split_dim = current_node -> parent -> split_dim; + float_t parent_hp = current_node -> parent -> data; + + /* + * right child has ub equal to parent + * lb equal to parent except for the dim of splitting + */ + + memcpy(current_node -> lb_node_box, current_node -> parent -> lb_node_box, ctx -> dims * sizeof(float_t)); + memcpy(current_node -> ub_node_box, current_node -> parent -> ub_node_box, ctx -> dims * sizeof(float_t)); + + current_node -> lb_node_box[parent_split_dim] = parent_hp; } break; default: + { + tree -> root = current_node; + memcpy(current_node -> lb_node_box, og_pointset -> lb_box, ctx -> dims * sizeof(float_t)); + memcpy(current_node -> ub_node_box, og_pointset -> ub_box, ctx -> dims * sizeof(float_t)); + } break; } - current_node -> split_dim = selected_dim; + current_node -> split_dim = current_partition.d; current_node -> parent = current_partition.parent; current_node -> lch = NULL; current_node -> rch = NULL; @@ -1332,26 +1358,30 @@ 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, - .n_procs = procs_left, + .n_points = points_left, + .n_procs = procs_left, .start_proc = current_partition.start_proc, - .parent = current_node, - .lr = TOP_TREE_LCH, - .base_ptr = current_pointset.data, - .d = next_dimension, + .parent = current_node, + .lr = TOP_TREE_LCH, + .base_ptr = current_pointset.data, + .d = next_dimension, }; partition_t right_partition = { - .n_points = points_right, - .n_procs = procs_right, + .n_points = points_right, + .n_procs = procs_right, .start_proc = current_partition.start_proc + procs_left, - .parent = current_node, - .lr = TOP_TREE_RCH, - .base_ptr = current_pointset.data + pv * current_pointset.dims, - .d = next_dimension + .parent = current_node, + .lr = TOP_TREE_RCH, + .base_ptr = current_pointset.data + pv * current_pointset.dims, + .d = next_dimension }; enqueue_partition(&queue, left_partition); @@ -1362,8 +1392,6 @@ void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree { current_node -> owner = current_partition.start_proc; } - /* set the root */ - if(current_node -> parent == NULL) tree -> root = current_node; } MPI_DB_PRINT("Root is %p\n", tree -> root); diff --git a/src/tree/tree.h b/src/tree/tree.h index f066ba849d56ae5a5c500aa3a52409c4f994e163..de8fb5dea3e79ded11aa89ee75bc6984a058cd1e 100644 --- a/src/tree/tree.h +++ b/src/tree/tree.h @@ -42,8 +42,8 @@ typedef struct partition_queue_t typedef struct top_kdtree_node_t { float_t data; - float_t* node_box_lb; //Needed? - float_t* node_box_ub; //Needed? + float_t* lb_node_box; //Needed? + float_t* ub_node_box; //Needed? int owner; int split_dim; size_t n_points;