Commit 2d2c6a6d authored by lykos98's avatar lykos98
Browse files

node bounding box impl

parent fe30144a
Loading
Loading
Loading
Loading
+61 −33
Original line number Diff line number Diff line
@@ -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;
@@ -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,7 +1286,7 @@ 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:
@@ -1298,6 +1294,18 @@ void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree
				{
					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;

@@ -1306,13 +1314,31 @@ void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree
				{
					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,6 +1358,10 @@ 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 = {
@@ -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);
+2 −2
Original line number Diff line number Diff line
@@ -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;