Loading src/tree/tree.c +88 −346 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #define TOP_TREE_RCH 1 #define TOP_TREE_LCH 0 #define NO_CHILD -1 float_t *read_data_file(global_context_t *ctx, const char *fname, const int file_in_float32) Loading Loading @@ -351,7 +352,7 @@ void check_pc_pointset(global_context_t *ctx, pointset_t *ps, float_t *best_gues } } float_t check_pc_pointset_parallel(global_context_t *ctx, pointset_t *ps, float_t *best_guess, int d, float_t prop) { float_t check_pc_pointset_parallel(global_context_t *ctx, pointset_t *ps, guess_t g, int d, float_t prop) { /* * ONLY FOR TEST PURPOSES * gather on master all data Loading @@ -360,7 +361,7 @@ float_t check_pc_pointset_parallel(global_context_t *ctx, pointset_t *ps, float_ int pvt_count = 0; for (int i = 0; i < ps->n_points; ++i) { pvt_count += ps->data[i * ps->dims + d] <= best_guess[d]; pvt_count += ps->data[i * ps->dims + d] <= g.x_guess; } int pvt_n_and_tot[2] = {pvt_count, ps->n_points}; Loading Loading @@ -818,8 +819,8 @@ int retrieve_guess_adaptive(global_context_t *ctx, pointset_t *ps, return idx; } int retrieve_guess_pure(global_context_t *ctx, pointset_t *ps, uint64_t *global_bin_counts, float_t *best_guess, guess_t retrieve_guess_pure(global_context_t *ctx, pointset_t *ps, uint64_t *global_bin_counts, int k_global, int d, float_t pc) { Loading Loading @@ -862,45 +863,12 @@ int retrieve_guess_pure(global_context_t *ctx, pointset_t *ps, float_t x_guess = (pc - y0) / (y1 - y0) * (x1 - x0) + x0; /* MPI_DB_PRINT("[MASTER] best guess @ %lf is %lf on bin %d on dimension %d --- x0 %lf x1 %lf y0 %lf y1 %lf\n",pc, x_guess,idx, d, x0, x1, y0, y1); MPI_DB_PRINT("[MASTER] best guess @ %lf is %lf on bin %d on dimension %d --- x0 %lf x1 %lf y0 %lf y1 %lf\n",pc, x_guess,idx, d, x0, x1, y0, y1); */ /* find nearest point btw guess */ int best_idx = 0; float_t best_val = 999999; for (int i = 0; i < ps->n_points; ++i) { float_t dist = fabs(x_guess - ps->data[i * ps->dims + d]); int c = dist < best_val; best_val = c ? dist : best_val; best_idx = c ? i : best_idx; } mpi_double_int best = {.val = best_val, .key = ctx->mpi_rank}; MPI_Allreduce(MPI_IN_PLACE, &best, 1, MPI_DOUBLE_INT, MPI_MINLOC, ctx->mpi_communicator); // printf("%lf %d\n", best.val, best.key); /* broadcast best guess */ if (ctx->mpi_rank == best.key) { memcpy(best_guess, ps->data + best_idx * ps->dims, ps->dims * sizeof(float_t)); } MPI_Bcast(best_guess, ps->dims, MPI_MY_FLOAT, best.key, ctx->mpi_communicator); /* recieved ? */ /* MPI_DB_PRINT("[MASTER] ["); for(int i = 0; i < ps -> dims; ++i) MPI_DB_PRINT("%lf ", best_guess[i]); MPI_DB_PRINT("]\n"); */ /* printf("[rank %d] [", ctx -> mpi_rank); for(int i = 0; i < ctx -> dims; ++i) printf("%lf ", best_guess[i]); printf("]\n"); */ return idx; guess_t g = {.bin_idx = idx, .x_guess = x_guess}; return g; } void retrieve_pc(global_context_t *ctx, float_t *global_bin_counts, float_t *best_guess, int k_global, int d, float_t pc) Loading Loading @@ -1054,34 +1022,31 @@ int partition_data_around_value(float_t *array, int vec_len, int compare_dim, return store_index; // maybe, update, it works :) } float_t refine_pure_binning(global_context_t *ctx, pointset_t *ps, float_t *best_guess, uint64_t *global_bin_count, int best_idx, int k_global, int d, float_t f, float_t ep, float_t tolerance) guess_t refine_pure_binning(global_context_t *ctx, pointset_t *ps, guess_t best_guess, uint64_t *global_bin_count, int k_global, int d, float_t f, float_t tolerance) { /* refine process from obtained binning */ if (fabs(ep - f) < tolerance) if (fabs(best_guess.ep - f) < tolerance) { /* MPI_DB_PRINT("[MASTER] No need to refine, finishing\n"); */ return ep; return best_guess; } float_t total_count = 0; float_t starting_cumulative = 0; for (int i = 0; i < best_idx; ++i) starting_cumulative += global_bin_count[i]; for (int i = 0; i < best_guess.bin_idx; ++i) starting_cumulative += global_bin_count[i]; for (int i = 0; i < k_global; ++i) total_count += global_bin_count[i]; float_t bin_w = (ps->ub_box[d] - ps->lb_box[d]) / k_global; float_t bin_lb = ps->lb_box[d] + (bin_w * (best_idx)); float_t bin_ub = ps->lb_box[d] + (bin_w * (best_idx + 1)); float_t bin_lb = ps->lb_box[d] + (bin_w * (best_guess.bin_idx)); float_t bin_ub = ps->lb_box[d] + (bin_w * (best_guess.bin_idx + 1)); uint64_t *tmp_global_bins = (uint64_t *)malloc(sizeof(uint64_t) * k_global); for (int i = 0; i < k_global; ++i) tmp_global_bins[i] = global_bin_count[i]; int tmp_best_idx = best_idx; /* MPI_DB_PRINT("STARTING REFINE global bins: "); for(int i = 0; i < k_global; ++i) Loading @@ -1090,13 +1055,15 @@ float_t refine_pure_binning(global_context_t *ctx, pointset_t *ps, } MPI_DB_PRINT("\n"); */ while (fabs(ep - f) > tolerance) { guess_t g; while (fabs(best_guess.ep - f) > tolerance) { /* compute the target */ float_t ff, b0, b1; ff = -1; b0 = starting_cumulative; b1 = tmp_global_bins[tmp_best_idx]; ff = (f * total_count - b0) / ((float_t)tmp_global_bins[tmp_best_idx]); b1 = tmp_global_bins[best_guess.bin_idx]; ff = (f * total_count - b0) / ((float_t)tmp_global_bins[best_guess.bin_idx]); /* * generate a partset of points in the bin considered Loading @@ -1107,13 +1074,15 @@ float_t refine_pure_binning(global_context_t *ctx, pointset_t *ps, * will be done in place * */ /* MPI_DB_PRINT("---- ---- ----\n"); MPI_DB_PRINT("[MASTER] Refining on bin %d lb %lf ub %lf starting c %lf %lf\n", tmp_best_idx, bin_lb, bin_ub, starting_cumulative/total_count, (tmp_global_bins[tmp_best_idx] + starting_cumulative)/total_count); MPI_DB_PRINT("[MASTER] Refining on bin %d lb %lf ub %lf starting c %lf %lf\n", best_guess.bin_idx, bin_lb, bin_ub, starting_cumulative/total_count, (tmp_global_bins[best_guess.bin_idx] + starting_cumulative)/total_count); */ for (int i = 0; i < k_global; ++i) tmp_global_bins[i] = 0; pointset_t tmp_ps; Loading @@ -1121,33 +1090,6 @@ float_t refine_pure_binning(global_context_t *ctx, pointset_t *ps, int end_idx = partition_data_around_value(ps->data, (int)ps->dims, d, 0, (int)ps->n_points, bin_ub); int start_idx = partition_data_around_value(ps->data, (int)ps->dims, d, 0,end_idx, bin_lb); /* tmp_ps.__capacity = 1000; tmp_ps.n_points = 0; tmp_ps.dims = ps->dims; tmp_ps.data = (float_t*)malloc(tmp_ps.__capacity * tmp_ps.dims * sizeof(float_t)); tmp_ps.lb_box = NULL; tmp_ps.ub_box = NULL; for(int i = 0; i < ps -> n_points; ++i) { float_t p = ps -> data[i * ps -> dims + d]; if( p > bin_lb && p < bin_ub) { if(tmp_ps.n_points == tmp_ps.__capacity) { tmp_ps.__capacity = tmp_ps.__capacity*1.10; tmp_ps.data = (float_t*)realloc(tmp_ps.data, tmp_ps.__capacity * tmp_ps.dims * sizeof(float_t)); } int idx_src = i * ps -> dims; int idx_dst = tmp_ps.n_points * tmp_ps.dims; memcpy(tmp_ps.data + idx_dst, ps -> data + idx_src, tmp_ps.dims * sizeof(float_t)); tmp_ps.n_points++; } } */ tmp_ps.n_points = end_idx - start_idx; tmp_ps.data = ps->data + start_idx * ps->dims; tmp_ps.dims = ps->dims; Loading @@ -1168,17 +1110,16 @@ float_t refine_pure_binning(global_context_t *ctx, pointset_t *ps, // for(int i = 0; i < k_global; ++i) tmp_global_bins[i] += // starting_cumulative; tmp_best_idx = retrieve_guess_pure(ctx, &tmp_ps, tmp_global_bins, best_guess, k_global, d, ff); best_guess = retrieve_guess_pure(ctx, &tmp_ps, tmp_global_bins, k_global, d, ff); ep = check_pc_pointset_parallel(ctx, ps, best_guess, d, f); best_guess.ep = check_pc_pointset_parallel(ctx, ps, best_guess, d, f); // ep = check_pc_pointset_parallel(ctx, &tmp_ps, best_guess, d, f); bin_w = (tmp_ps.ub_box[d] - tmp_ps.lb_box[d]) / k_global; bin_lb = tmp_ps.lb_box[d] + (bin_w * (tmp_best_idx)); bin_ub = tmp_ps.lb_box[d] + (bin_w * (tmp_best_idx + 1)); bin_lb = tmp_ps.lb_box[d] + (bin_w * (best_guess.bin_idx)); bin_ub = tmp_ps.lb_box[d] + (bin_w * (best_guess.bin_idx + 1)); for (int i = 0; i < tmp_best_idx; ++i) starting_cumulative += tmp_global_bins[i]; for (int i = 0; i < best_guess.bin_idx; ++i) starting_cumulative += tmp_global_bins[i]; // free(tmp_ps.data); free(tmp_ps.lb_box); Loading @@ -1191,125 +1132,7 @@ float_t refine_pure_binning(global_context_t *ctx, pointset_t *ps, free(tmp_global_bins); return ep; } float_t refine_on_bin(global_context_t *ctx, pointset_t *ps, float_t *best_guess, float_t *global_bin_count, int best_idx, int k_global, int k_local, int d, float_t f, float_t tolerance) { float_t total_count = 0; float_t starting_cumulative = 0; for (int i = 0; i < best_idx; ++i) starting_cumulative += global_bin_count[i]; float_t ep = 100; for (int i = 0; i < k_global; ++i) total_count += global_bin_count[i]; float_t bin_w = (ps->ub_box[d] - ps->lb_box[d]) / k_global; float_t bin_lb = ps->lb_box[d] + (bin_w * (best_idx)); float_t bin_ub = ps->lb_box[d] + (bin_w * (best_idx + 1)); float_t *tmp_global_bins = (float_t *)malloc(sizeof(float_t) * k_global); float_t *tmp_bin_bounds = (float_t *)malloc((k_local + 1) * sizeof(float_t)); for (int i = 0; i < k_global; ++i) tmp_global_bins[i] = global_bin_count[i]; int tmp_best_idx = best_idx; /* MPI_DB_PRINT("STARTING REFINE global bins: "); for(int i = 0; i < k_global; ++i) { MPI_DB_PRINT("%lf ", global_bin_count[i]); } MPI_DB_PRINT("\n"); */ while (fabs(ep - f) > 0.002) { /* compute the target */ float_t ff, b0, b1; ff = -1; while (ff < 0) { starting_cumulative = 0; for (int i = 0; i < tmp_best_idx; ++i) starting_cumulative += tmp_global_bins[i]; b0 = starting_cumulative; b1 = tmp_global_bins[tmp_best_idx]; ff = (f * total_count - b0) / ((float_t)tmp_global_bins[tmp_best_idx]); } /* * generate a partset of points in the bin considered * each one has to partition its dataset according to the * fact that points on dimension d has to be in the bin * * then make into in place alg * for now dirty and inefficient * */ MPI_DB_PRINT("---- ---- ----\n"); MPI_DB_PRINT("[MASTER] Refining on bin %d lb %lf ub %lf starting c %lf %lf\n", tmp_best_idx, bin_lb, bin_ub, starting_cumulative / total_count, (tmp_global_bins[tmp_best_idx] + starting_cumulative) / total_count); for (int i = 0; i < k_global; ++i) tmp_global_bins[i] = 0; pointset_t tmp_ps; tmp_ps.__capacity = 1000; tmp_ps.n_points = 0; tmp_ps.dims = ps->dims; tmp_ps.data = (float_t *)malloc(tmp_ps.__capacity * tmp_ps.dims * sizeof(float_t)); tmp_ps.lb_box = NULL; tmp_ps.ub_box = NULL; for (int i = 0; i < ps->n_points; ++i) { float_t p = ps->data[i * ps->dims + d]; if (p > bin_lb && p < bin_ub) { if (tmp_ps.n_points == tmp_ps.__capacity) { tmp_ps.__capacity = tmp_ps.__capacity * 1.10; tmp_ps.data = (float_t *)realloc( tmp_ps.data, tmp_ps.__capacity * tmp_ps.dims * sizeof(float_t)); } int idx_src = i * ps->dims; int idx_dst = tmp_ps.n_points * tmp_ps.dims; memcpy(tmp_ps.data + idx_dst, ps->data + idx_src, tmp_ps.dims * sizeof(float_t)); tmp_ps.n_points++; } } compute_bounding_box_pointset(ctx, &tmp_ps); MPI_DB_PRINT("%lf ff\n", ff); // DB_PRINT("%lu\n",tmp_ps.n_points ); MPI_Barrier(ctx->mpi_communicator); compute_adaptive_binning_pointset(ctx, &tmp_ps, k_local, k_global, d, tmp_bin_bounds, tmp_global_bins); /* sum to global bins */ // for(int i = 0; i < k_global; ++i) tmp_global_bins[i] += // starting_cumulative; tmp_best_idx = retrieve_guess_adaptive(ctx, &tmp_ps, tmp_global_bins, best_guess, k_global, d, ff); ep = check_pc_pointset_parallel(ctx, ps, best_guess, d, f); ep = check_pc_pointset_parallel(ctx, &tmp_ps, best_guess, d, f); bin_w = (tmp_ps.ub_box[d] - tmp_ps.lb_box[d]) / k_global; bin_lb = tmp_ps.lb_box[d] + (bin_w * (tmp_best_idx)); bin_ub = tmp_ps.lb_box[d] + (bin_w * (tmp_best_idx + 1)); free(tmp_ps.data); free(tmp_ps.lb_box); free(tmp_ps.ub_box); } MPI_DB_PRINT("SUCCESS!!! --- "); free(tmp_bin_bounds); free(tmp_global_bins); return ep; return best_guess; } void init_queue(partition_queue_t *pq) Loading @@ -1330,8 +1153,8 @@ void get_pointset_from_partition(pointset_t *ps, partition_t *part) ps->n_points = part->n_points; } void compute_median_pure_binning(global_context_t *ctx, pointset_t *ps, float_t *guess, float_t fraction, 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) { Loading @@ -1340,104 +1163,45 @@ void compute_median_pure_binning(global_context_t *ctx, pointset_t *ps, uint64_t *global_bin_counts_int = (uint64_t *)malloc(n_bins * sizeof(uint64_t)); for (int i = 0; i < ctx->dims; ++i) guess[i] = 0.; compute_bounding_box_pointset(ctx, ps); compute_pure_global_binning(ctx, ps, global_bin_counts_int, n_bins, selected_dim); best_bin_idx = retrieve_guess_pure(ctx, ps, global_bin_counts_int, guess, n_bins, selected_dim, fraction); guess_t g = retrieve_guess_pure(ctx, ps, global_bin_counts_int, n_bins, selected_dim, fraction); // check_pc_pointset(ctx, ps, best_guess, d, f); ep = check_pc_pointset_parallel(ctx, ps, guess, selected_dim, fraction); ep = refine_pure_binning(ctx, ps, guess, global_bin_counts_int, best_bin_idx, n_bins, selected_dim, fraction, ep, tolerance); g.ep = check_pc_pointset_parallel(ctx, ps, g, selected_dim, fraction); g = refine_pure_binning(ctx, ps, g, global_bin_counts_int, n_bins, selected_dim, fraction, tolerance); free(global_bin_counts_int); return g; } void top_tree_insert(global_context_t *ctx, top_kdtree_t *tree, float_t *guess, int selected_dim, int is_leaf, size_t n_points) { if (tree->count == tree->_capacity) void top_tree_init(global_context_t *ctx, top_kdtree_t *tree) { int new_cap = tree->_capacity * 1.1; tree->medians = realloc(tree->medians, new_cap * tree->dims * sizeof(float_t)); tree->_nodes = realloc(tree->_nodes, new_cap * sizeof(top_kdtree_node_t)); tree->_capacity = new_cap; } /* copy guess into medians */ memcpy(tree->medians + (tree->count * ctx->dims), guess, ctx->dims * sizeof(float_t)); /* retrieve the next free node */ top_kdtree_node_t *node = &(tree->_nodes[tree->count]); node->data = tree->medians + (tree->count * tree->dims); node->split_dim = selected_dim; node->owner = -1; node->lch = NULL; node->rch = NULL; node->parent = NULL; node->is_leaf = is_leaf; node->n_points = n_points; if (tree->count == 0) { tree->root = node; } else { top_kdtree_node_t *current_node = tree->root; top_kdtree_node_t *parent = NULL; int side = -1; while (current_node) { int split_dim = current_node->split_dim; parent = current_node->parent; /* tree traversal */ int side = node->data[split_dim] - current_node->data[split_dim]; switch (side) { case TOP_TREE_LCH: parent = current_node; current_node = current_node->lch; break; case TOP_TREE_RCH: parent = current_node; current_node = current_node->lch; break; default: break; } } /* found the right place */ switch (side) { case TOP_TREE_LCH: parent->lch = node; node->parent = parent; break; case TOP_TREE_RCH: parent->rch = node; node->parent = parent; break; default: break; } } } void top_tree_init(global_context_t *ctx, top_kdtree_t *tree) { tree->dims = ctx->dims; tree->count = 0; tree->_capacity = 100; tree->_nodes = (top_kdtree_node_t *)malloc(tree->_capacity * sizeof(top_kdtree_node_t)); tree->medians = (float_t *)malloc(tree->_capacity * tree->dims * sizeof(float_t)); return; } void top_tree_free(global_context_t *ctx, top_kdtree_t *tree) { void top_tree_free(global_context_t *ctx, top_kdtree_t *tree) { free(tree->_nodes); free(tree->medians); return; } 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; ++tree -> count; return ptr; } 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; Loading @@ -1460,11 +1224,13 @@ void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree partition_t current_partition = {.d = selected_dim, .base_ptr = og_pointset->data, .n_points = og_pointset->n_points, .n_procs = ctx->world_size}; .n_procs = ctx->world_size, .parent = NULL, .lr = NO_CHILD }; enqueue_partition(&queue, current_partition); pointset_t current_pointset; float_t *median_guess = (float_t *)malloc(ctx->dims * sizeof(float_t)); while (queue.count) { Loading @@ -1474,9 +1240,8 @@ void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree /* handle partition */ compute_bounding_box_pointset(ctx, ¤t_pointset); float_t fraction = (current_partition.n_procs / 2) / (float_t)current_partition.n_procs; compute_median_pure_binning(ctx, ¤t_pointset, median_guess, fraction, selected_dim, n_bins, tolerance); int pv = partition_data_around_value(current_pointset.data, ctx->dims, selected_dim, 0, current_pointset.n_points, median_guess[selected_dim]); guess_t g = compute_median_pure_binning(ctx, ¤t_pointset, fraction, selected_dim, n_bins, tolerance); int pv = partition_data_around_value(current_pointset.data, ctx->dims, selected_dim, 0, current_pointset.n_points, g.x_guess); /* insert node */ /* Loading @@ -1486,14 +1251,11 @@ void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree * */ if (current_pointset.n_points < expected_points_per_node) { top_tree_insert(ctx, tree, median_guess, selected_dim, MY_TRUE, current_pointset.n_points); } else { top_tree_insert(ctx, tree, median_guess, selected_dim, MY_FALSE, current_pointset.n_points); } top_kdtree_node_t* current_node; current_node -> data = g.x_guess; current_node -> split_dim = selected_dim; current_node -> parent = current_partition.parent; size_t points_left = current_partition.n_points * fraction; size_t points_right = current_partition.n_points - points_left; Loading @@ -1504,13 +1266,25 @@ void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree int next_dimension = (++selected_dim) % (ctx->dims); partition_t left_partition = { .n_points = points_left, .n_procs = procs_left .n_procs = procs_left, .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, .parent = current_node, .lr = TOP_TREE_RCH, .base_ptr = current_pointset.data + pv, .d = next_dimension }; /* get left and right pointset */ } free(median_guess); free_queue(&queue); } Loading @@ -1523,8 +1297,7 @@ void simulate_master_read_and_scatter(int dims, size_t n, global_context_t *ctx) if(ctx -> mpi_rank == 0) { data = (float_t*)malloc(dims*n*sizeof(float_t)); //for(size_t i = 0; i < dims * n; ++i) data[i] = (float_t)rand()/(float_t)(RAND_MAX); //for(size_t i = 0; i < dims * n; ++i) data[i] = (float_t)rand()/(float_t)(RAND_MAX); //for(size_t i = 0; i < n; ++i) // for(size_t j = 0; j < dims; ++j) // data[i*dims + j] = (float_t)i; Loading @@ -1534,7 +1307,6 @@ void simulate_master_read_and_scatter(int dims, size_t n, global_context_t *ctx) ctx -> n_points = n; } */ /* read from files */ if (ctx->mpi_rank == 0) Loading Loading @@ -1586,11 +1358,8 @@ void simulate_master_read_and_scatter(int dims, size_t n, global_context_t *ctx) int k_local = 20; int k_global = 20; float_t *global_bin_counts = (float_t *)malloc(k_global * sizeof(float_t)); uint64_t *global_bin_counts_int = (uint64_t *)malloc(k_global * sizeof(uint64_t)); float_t *best_guess = (float_t *)malloc(ctx->dims * sizeof(float_t)); float_t *bin_bounds = (float_t *)malloc((k_local + 1) * sizeof(float_t)); uint64_t *global_bin_counts_int = (uint64_t *)malloc(k_global * sizeof(uint64_t)); pointset_t original_ps; original_ps.data = ctx->local_data; Loading @@ -1609,39 +1378,15 @@ void simulate_master_read_and_scatter(int dims, size_t n, global_context_t *ctx) int best_bin_idx; float_t ep; /* compute_bounding_box_pointset(ctx,&original_ps); compute_adaptive_binning_pointset(ctx,&original_ps,k_local,k_global, d, bin_bounds, global_bin_counts); best_bin_idx = retrieve_guess_adaptive(ctx, &original_ps,global_bin_counts, best_guess, k_global, d, f); //check_pc_pointset(ctx, &ps, best_guess, d, f); ep = check_pc_pointset_parallel(ctx, &original_ps, best_guess, d, f); */ /** if(fabs(ep - f) > 0.02) { refine_on_bin(ctx, &original_ps, best_guess, global_bin_counts, best_bin_idx, k_global, k_local, d, f, 0.2); } */ // MPI_DB_PRINT("--------------------------------------\n\n"); compute_bounding_box_pointset(ctx, &original_ps); compute_pure_global_binning(ctx, &original_ps, global_bin_counts_int, k_global, d); best_bin_idx = retrieve_guess_pure( ctx, &original_ps, global_bin_counts_int, best_guess, k_global, d, f); compute_pure_global_binning(ctx, &original_ps, global_bin_counts_int, k_global, d); guess_t g = retrieve_guess_pure( ctx, &original_ps, global_bin_counts_int, k_global, d, f); // check_pc_pointset(ctx, &ps, best_guess, d, f); ep = check_pc_pointset_parallel(ctx, &original_ps, best_guess, d, f); g.ep = check_pc_pointset_parallel(ctx, &original_ps, g, d, f); ep = refine_pure_binning(ctx, &original_ps, best_guess, global_bin_counts_int, best_bin_idx, k_global, d, f, ep, tol); g = refine_pure_binning(ctx, &original_ps, g, global_bin_counts_int, k_global, d, f, tol); MPI_DB_PRINT("[MASTER] dimension %d searching for %lf found %lf\n", d, f, ep); MPI_DB_PRINT("[MASTER] dimension %d searching for %lf found %lf\n", d, f, g.ep); } MPI_DB_PRINT("--------------------------------------\n\n"); } Loading @@ -1655,10 +1400,7 @@ void simulate_master_read_and_scatter(int dims, size_t n, global_context_t *ctx) free(send_counts); free(displacements); free(global_bin_counts); // free(pvt_data); free(bin_bounds); free(best_guess); if (ctx->mpi_rank == 0) free(data); Loading src/tree/tree.h +14 −2 Original line number Diff line number Diff line Loading @@ -5,11 +5,20 @@ #include <math.h> #include "../common/common.h" typedef struct mpi_double_int{ float_t val; int key; } mpi_double_int; typedef struct guess_t { float_t x_guess; int bin_idx; float_t ep; } guess_t; typedef struct partition_t { Loading @@ -17,6 +26,8 @@ typedef struct partition_t int n_procs; size_t n_points; float_t* base_ptr; int lr; struct top_kdtree_node_t* parent; } partition_t; typedef struct partition_queue_t Loading @@ -29,13 +40,15 @@ typedef struct partition_queue_t typedef struct top_kdtree_node_t { float_t* data; float_t data; //float_t* node_box_lb; //Needed? //float_t* node_box_ub; //Needed? int owner; int split_dim; int is_leaf; size_t n_points; float_t* lb_box; float_t* ub_box; struct top_kdtree_node_t* lch; struct top_kdtree_node_t* rch; struct top_kdtree_node_t* parent; Loading @@ -46,7 +59,6 @@ typedef struct top_kdtree_t int dims; size_t count; size_t _capacity; float_t* medians; struct top_kdtree_node_t* _nodes; struct top_kdtree_node_t* root; Loading Loading
src/tree/tree.c +88 −346 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #define TOP_TREE_RCH 1 #define TOP_TREE_LCH 0 #define NO_CHILD -1 float_t *read_data_file(global_context_t *ctx, const char *fname, const int file_in_float32) Loading Loading @@ -351,7 +352,7 @@ void check_pc_pointset(global_context_t *ctx, pointset_t *ps, float_t *best_gues } } float_t check_pc_pointset_parallel(global_context_t *ctx, pointset_t *ps, float_t *best_guess, int d, float_t prop) { float_t check_pc_pointset_parallel(global_context_t *ctx, pointset_t *ps, guess_t g, int d, float_t prop) { /* * ONLY FOR TEST PURPOSES * gather on master all data Loading @@ -360,7 +361,7 @@ float_t check_pc_pointset_parallel(global_context_t *ctx, pointset_t *ps, float_ int pvt_count = 0; for (int i = 0; i < ps->n_points; ++i) { pvt_count += ps->data[i * ps->dims + d] <= best_guess[d]; pvt_count += ps->data[i * ps->dims + d] <= g.x_guess; } int pvt_n_and_tot[2] = {pvt_count, ps->n_points}; Loading Loading @@ -818,8 +819,8 @@ int retrieve_guess_adaptive(global_context_t *ctx, pointset_t *ps, return idx; } int retrieve_guess_pure(global_context_t *ctx, pointset_t *ps, uint64_t *global_bin_counts, float_t *best_guess, guess_t retrieve_guess_pure(global_context_t *ctx, pointset_t *ps, uint64_t *global_bin_counts, int k_global, int d, float_t pc) { Loading Loading @@ -862,45 +863,12 @@ int retrieve_guess_pure(global_context_t *ctx, pointset_t *ps, float_t x_guess = (pc - y0) / (y1 - y0) * (x1 - x0) + x0; /* MPI_DB_PRINT("[MASTER] best guess @ %lf is %lf on bin %d on dimension %d --- x0 %lf x1 %lf y0 %lf y1 %lf\n",pc, x_guess,idx, d, x0, x1, y0, y1); MPI_DB_PRINT("[MASTER] best guess @ %lf is %lf on bin %d on dimension %d --- x0 %lf x1 %lf y0 %lf y1 %lf\n",pc, x_guess,idx, d, x0, x1, y0, y1); */ /* find nearest point btw guess */ int best_idx = 0; float_t best_val = 999999; for (int i = 0; i < ps->n_points; ++i) { float_t dist = fabs(x_guess - ps->data[i * ps->dims + d]); int c = dist < best_val; best_val = c ? dist : best_val; best_idx = c ? i : best_idx; } mpi_double_int best = {.val = best_val, .key = ctx->mpi_rank}; MPI_Allreduce(MPI_IN_PLACE, &best, 1, MPI_DOUBLE_INT, MPI_MINLOC, ctx->mpi_communicator); // printf("%lf %d\n", best.val, best.key); /* broadcast best guess */ if (ctx->mpi_rank == best.key) { memcpy(best_guess, ps->data + best_idx * ps->dims, ps->dims * sizeof(float_t)); } MPI_Bcast(best_guess, ps->dims, MPI_MY_FLOAT, best.key, ctx->mpi_communicator); /* recieved ? */ /* MPI_DB_PRINT("[MASTER] ["); for(int i = 0; i < ps -> dims; ++i) MPI_DB_PRINT("%lf ", best_guess[i]); MPI_DB_PRINT("]\n"); */ /* printf("[rank %d] [", ctx -> mpi_rank); for(int i = 0; i < ctx -> dims; ++i) printf("%lf ", best_guess[i]); printf("]\n"); */ return idx; guess_t g = {.bin_idx = idx, .x_guess = x_guess}; return g; } void retrieve_pc(global_context_t *ctx, float_t *global_bin_counts, float_t *best_guess, int k_global, int d, float_t pc) Loading Loading @@ -1054,34 +1022,31 @@ int partition_data_around_value(float_t *array, int vec_len, int compare_dim, return store_index; // maybe, update, it works :) } float_t refine_pure_binning(global_context_t *ctx, pointset_t *ps, float_t *best_guess, uint64_t *global_bin_count, int best_idx, int k_global, int d, float_t f, float_t ep, float_t tolerance) guess_t refine_pure_binning(global_context_t *ctx, pointset_t *ps, guess_t best_guess, uint64_t *global_bin_count, int k_global, int d, float_t f, float_t tolerance) { /* refine process from obtained binning */ if (fabs(ep - f) < tolerance) if (fabs(best_guess.ep - f) < tolerance) { /* MPI_DB_PRINT("[MASTER] No need to refine, finishing\n"); */ return ep; return best_guess; } float_t total_count = 0; float_t starting_cumulative = 0; for (int i = 0; i < best_idx; ++i) starting_cumulative += global_bin_count[i]; for (int i = 0; i < best_guess.bin_idx; ++i) starting_cumulative += global_bin_count[i]; for (int i = 0; i < k_global; ++i) total_count += global_bin_count[i]; float_t bin_w = (ps->ub_box[d] - ps->lb_box[d]) / k_global; float_t bin_lb = ps->lb_box[d] + (bin_w * (best_idx)); float_t bin_ub = ps->lb_box[d] + (bin_w * (best_idx + 1)); float_t bin_lb = ps->lb_box[d] + (bin_w * (best_guess.bin_idx)); float_t bin_ub = ps->lb_box[d] + (bin_w * (best_guess.bin_idx + 1)); uint64_t *tmp_global_bins = (uint64_t *)malloc(sizeof(uint64_t) * k_global); for (int i = 0; i < k_global; ++i) tmp_global_bins[i] = global_bin_count[i]; int tmp_best_idx = best_idx; /* MPI_DB_PRINT("STARTING REFINE global bins: "); for(int i = 0; i < k_global; ++i) Loading @@ -1090,13 +1055,15 @@ float_t refine_pure_binning(global_context_t *ctx, pointset_t *ps, } MPI_DB_PRINT("\n"); */ while (fabs(ep - f) > tolerance) { guess_t g; while (fabs(best_guess.ep - f) > tolerance) { /* compute the target */ float_t ff, b0, b1; ff = -1; b0 = starting_cumulative; b1 = tmp_global_bins[tmp_best_idx]; ff = (f * total_count - b0) / ((float_t)tmp_global_bins[tmp_best_idx]); b1 = tmp_global_bins[best_guess.bin_idx]; ff = (f * total_count - b0) / ((float_t)tmp_global_bins[best_guess.bin_idx]); /* * generate a partset of points in the bin considered Loading @@ -1107,13 +1074,15 @@ float_t refine_pure_binning(global_context_t *ctx, pointset_t *ps, * will be done in place * */ /* MPI_DB_PRINT("---- ---- ----\n"); MPI_DB_PRINT("[MASTER] Refining on bin %d lb %lf ub %lf starting c %lf %lf\n", tmp_best_idx, bin_lb, bin_ub, starting_cumulative/total_count, (tmp_global_bins[tmp_best_idx] + starting_cumulative)/total_count); MPI_DB_PRINT("[MASTER] Refining on bin %d lb %lf ub %lf starting c %lf %lf\n", best_guess.bin_idx, bin_lb, bin_ub, starting_cumulative/total_count, (tmp_global_bins[best_guess.bin_idx] + starting_cumulative)/total_count); */ for (int i = 0; i < k_global; ++i) tmp_global_bins[i] = 0; pointset_t tmp_ps; Loading @@ -1121,33 +1090,6 @@ float_t refine_pure_binning(global_context_t *ctx, pointset_t *ps, int end_idx = partition_data_around_value(ps->data, (int)ps->dims, d, 0, (int)ps->n_points, bin_ub); int start_idx = partition_data_around_value(ps->data, (int)ps->dims, d, 0,end_idx, bin_lb); /* tmp_ps.__capacity = 1000; tmp_ps.n_points = 0; tmp_ps.dims = ps->dims; tmp_ps.data = (float_t*)malloc(tmp_ps.__capacity * tmp_ps.dims * sizeof(float_t)); tmp_ps.lb_box = NULL; tmp_ps.ub_box = NULL; for(int i = 0; i < ps -> n_points; ++i) { float_t p = ps -> data[i * ps -> dims + d]; if( p > bin_lb && p < bin_ub) { if(tmp_ps.n_points == tmp_ps.__capacity) { tmp_ps.__capacity = tmp_ps.__capacity*1.10; tmp_ps.data = (float_t*)realloc(tmp_ps.data, tmp_ps.__capacity * tmp_ps.dims * sizeof(float_t)); } int idx_src = i * ps -> dims; int idx_dst = tmp_ps.n_points * tmp_ps.dims; memcpy(tmp_ps.data + idx_dst, ps -> data + idx_src, tmp_ps.dims * sizeof(float_t)); tmp_ps.n_points++; } } */ tmp_ps.n_points = end_idx - start_idx; tmp_ps.data = ps->data + start_idx * ps->dims; tmp_ps.dims = ps->dims; Loading @@ -1168,17 +1110,16 @@ float_t refine_pure_binning(global_context_t *ctx, pointset_t *ps, // for(int i = 0; i < k_global; ++i) tmp_global_bins[i] += // starting_cumulative; tmp_best_idx = retrieve_guess_pure(ctx, &tmp_ps, tmp_global_bins, best_guess, k_global, d, ff); best_guess = retrieve_guess_pure(ctx, &tmp_ps, tmp_global_bins, k_global, d, ff); ep = check_pc_pointset_parallel(ctx, ps, best_guess, d, f); best_guess.ep = check_pc_pointset_parallel(ctx, ps, best_guess, d, f); // ep = check_pc_pointset_parallel(ctx, &tmp_ps, best_guess, d, f); bin_w = (tmp_ps.ub_box[d] - tmp_ps.lb_box[d]) / k_global; bin_lb = tmp_ps.lb_box[d] + (bin_w * (tmp_best_idx)); bin_ub = tmp_ps.lb_box[d] + (bin_w * (tmp_best_idx + 1)); bin_lb = tmp_ps.lb_box[d] + (bin_w * (best_guess.bin_idx)); bin_ub = tmp_ps.lb_box[d] + (bin_w * (best_guess.bin_idx + 1)); for (int i = 0; i < tmp_best_idx; ++i) starting_cumulative += tmp_global_bins[i]; for (int i = 0; i < best_guess.bin_idx; ++i) starting_cumulative += tmp_global_bins[i]; // free(tmp_ps.data); free(tmp_ps.lb_box); Loading @@ -1191,125 +1132,7 @@ float_t refine_pure_binning(global_context_t *ctx, pointset_t *ps, free(tmp_global_bins); return ep; } float_t refine_on_bin(global_context_t *ctx, pointset_t *ps, float_t *best_guess, float_t *global_bin_count, int best_idx, int k_global, int k_local, int d, float_t f, float_t tolerance) { float_t total_count = 0; float_t starting_cumulative = 0; for (int i = 0; i < best_idx; ++i) starting_cumulative += global_bin_count[i]; float_t ep = 100; for (int i = 0; i < k_global; ++i) total_count += global_bin_count[i]; float_t bin_w = (ps->ub_box[d] - ps->lb_box[d]) / k_global; float_t bin_lb = ps->lb_box[d] + (bin_w * (best_idx)); float_t bin_ub = ps->lb_box[d] + (bin_w * (best_idx + 1)); float_t *tmp_global_bins = (float_t *)malloc(sizeof(float_t) * k_global); float_t *tmp_bin_bounds = (float_t *)malloc((k_local + 1) * sizeof(float_t)); for (int i = 0; i < k_global; ++i) tmp_global_bins[i] = global_bin_count[i]; int tmp_best_idx = best_idx; /* MPI_DB_PRINT("STARTING REFINE global bins: "); for(int i = 0; i < k_global; ++i) { MPI_DB_PRINT("%lf ", global_bin_count[i]); } MPI_DB_PRINT("\n"); */ while (fabs(ep - f) > 0.002) { /* compute the target */ float_t ff, b0, b1; ff = -1; while (ff < 0) { starting_cumulative = 0; for (int i = 0; i < tmp_best_idx; ++i) starting_cumulative += tmp_global_bins[i]; b0 = starting_cumulative; b1 = tmp_global_bins[tmp_best_idx]; ff = (f * total_count - b0) / ((float_t)tmp_global_bins[tmp_best_idx]); } /* * generate a partset of points in the bin considered * each one has to partition its dataset according to the * fact that points on dimension d has to be in the bin * * then make into in place alg * for now dirty and inefficient * */ MPI_DB_PRINT("---- ---- ----\n"); MPI_DB_PRINT("[MASTER] Refining on bin %d lb %lf ub %lf starting c %lf %lf\n", tmp_best_idx, bin_lb, bin_ub, starting_cumulative / total_count, (tmp_global_bins[tmp_best_idx] + starting_cumulative) / total_count); for (int i = 0; i < k_global; ++i) tmp_global_bins[i] = 0; pointset_t tmp_ps; tmp_ps.__capacity = 1000; tmp_ps.n_points = 0; tmp_ps.dims = ps->dims; tmp_ps.data = (float_t *)malloc(tmp_ps.__capacity * tmp_ps.dims * sizeof(float_t)); tmp_ps.lb_box = NULL; tmp_ps.ub_box = NULL; for (int i = 0; i < ps->n_points; ++i) { float_t p = ps->data[i * ps->dims + d]; if (p > bin_lb && p < bin_ub) { if (tmp_ps.n_points == tmp_ps.__capacity) { tmp_ps.__capacity = tmp_ps.__capacity * 1.10; tmp_ps.data = (float_t *)realloc( tmp_ps.data, tmp_ps.__capacity * tmp_ps.dims * sizeof(float_t)); } int idx_src = i * ps->dims; int idx_dst = tmp_ps.n_points * tmp_ps.dims; memcpy(tmp_ps.data + idx_dst, ps->data + idx_src, tmp_ps.dims * sizeof(float_t)); tmp_ps.n_points++; } } compute_bounding_box_pointset(ctx, &tmp_ps); MPI_DB_PRINT("%lf ff\n", ff); // DB_PRINT("%lu\n",tmp_ps.n_points ); MPI_Barrier(ctx->mpi_communicator); compute_adaptive_binning_pointset(ctx, &tmp_ps, k_local, k_global, d, tmp_bin_bounds, tmp_global_bins); /* sum to global bins */ // for(int i = 0; i < k_global; ++i) tmp_global_bins[i] += // starting_cumulative; tmp_best_idx = retrieve_guess_adaptive(ctx, &tmp_ps, tmp_global_bins, best_guess, k_global, d, ff); ep = check_pc_pointset_parallel(ctx, ps, best_guess, d, f); ep = check_pc_pointset_parallel(ctx, &tmp_ps, best_guess, d, f); bin_w = (tmp_ps.ub_box[d] - tmp_ps.lb_box[d]) / k_global; bin_lb = tmp_ps.lb_box[d] + (bin_w * (tmp_best_idx)); bin_ub = tmp_ps.lb_box[d] + (bin_w * (tmp_best_idx + 1)); free(tmp_ps.data); free(tmp_ps.lb_box); free(tmp_ps.ub_box); } MPI_DB_PRINT("SUCCESS!!! --- "); free(tmp_bin_bounds); free(tmp_global_bins); return ep; return best_guess; } void init_queue(partition_queue_t *pq) Loading @@ -1330,8 +1153,8 @@ void get_pointset_from_partition(pointset_t *ps, partition_t *part) ps->n_points = part->n_points; } void compute_median_pure_binning(global_context_t *ctx, pointset_t *ps, float_t *guess, float_t fraction, 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) { Loading @@ -1340,104 +1163,45 @@ void compute_median_pure_binning(global_context_t *ctx, pointset_t *ps, uint64_t *global_bin_counts_int = (uint64_t *)malloc(n_bins * sizeof(uint64_t)); for (int i = 0; i < ctx->dims; ++i) guess[i] = 0.; compute_bounding_box_pointset(ctx, ps); compute_pure_global_binning(ctx, ps, global_bin_counts_int, n_bins, selected_dim); best_bin_idx = retrieve_guess_pure(ctx, ps, global_bin_counts_int, guess, n_bins, selected_dim, fraction); guess_t g = retrieve_guess_pure(ctx, ps, global_bin_counts_int, n_bins, selected_dim, fraction); // check_pc_pointset(ctx, ps, best_guess, d, f); ep = check_pc_pointset_parallel(ctx, ps, guess, selected_dim, fraction); ep = refine_pure_binning(ctx, ps, guess, global_bin_counts_int, best_bin_idx, n_bins, selected_dim, fraction, ep, tolerance); g.ep = check_pc_pointset_parallel(ctx, ps, g, selected_dim, fraction); g = refine_pure_binning(ctx, ps, g, global_bin_counts_int, n_bins, selected_dim, fraction, tolerance); free(global_bin_counts_int); return g; } void top_tree_insert(global_context_t *ctx, top_kdtree_t *tree, float_t *guess, int selected_dim, int is_leaf, size_t n_points) { if (tree->count == tree->_capacity) void top_tree_init(global_context_t *ctx, top_kdtree_t *tree) { int new_cap = tree->_capacity * 1.1; tree->medians = realloc(tree->medians, new_cap * tree->dims * sizeof(float_t)); tree->_nodes = realloc(tree->_nodes, new_cap * sizeof(top_kdtree_node_t)); tree->_capacity = new_cap; } /* copy guess into medians */ memcpy(tree->medians + (tree->count * ctx->dims), guess, ctx->dims * sizeof(float_t)); /* retrieve the next free node */ top_kdtree_node_t *node = &(tree->_nodes[tree->count]); node->data = tree->medians + (tree->count * tree->dims); node->split_dim = selected_dim; node->owner = -1; node->lch = NULL; node->rch = NULL; node->parent = NULL; node->is_leaf = is_leaf; node->n_points = n_points; if (tree->count == 0) { tree->root = node; } else { top_kdtree_node_t *current_node = tree->root; top_kdtree_node_t *parent = NULL; int side = -1; while (current_node) { int split_dim = current_node->split_dim; parent = current_node->parent; /* tree traversal */ int side = node->data[split_dim] - current_node->data[split_dim]; switch (side) { case TOP_TREE_LCH: parent = current_node; current_node = current_node->lch; break; case TOP_TREE_RCH: parent = current_node; current_node = current_node->lch; break; default: break; } } /* found the right place */ switch (side) { case TOP_TREE_LCH: parent->lch = node; node->parent = parent; break; case TOP_TREE_RCH: parent->rch = node; node->parent = parent; break; default: break; } } } void top_tree_init(global_context_t *ctx, top_kdtree_t *tree) { tree->dims = ctx->dims; tree->count = 0; tree->_capacity = 100; tree->_nodes = (top_kdtree_node_t *)malloc(tree->_capacity * sizeof(top_kdtree_node_t)); tree->medians = (float_t *)malloc(tree->_capacity * tree->dims * sizeof(float_t)); return; } void top_tree_free(global_context_t *ctx, top_kdtree_t *tree) { void top_tree_free(global_context_t *ctx, top_kdtree_t *tree) { free(tree->_nodes); free(tree->medians); return; } 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; ++tree -> count; return ptr; } 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; Loading @@ -1460,11 +1224,13 @@ void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree partition_t current_partition = {.d = selected_dim, .base_ptr = og_pointset->data, .n_points = og_pointset->n_points, .n_procs = ctx->world_size}; .n_procs = ctx->world_size, .parent = NULL, .lr = NO_CHILD }; enqueue_partition(&queue, current_partition); pointset_t current_pointset; float_t *median_guess = (float_t *)malloc(ctx->dims * sizeof(float_t)); while (queue.count) { Loading @@ -1474,9 +1240,8 @@ void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree /* handle partition */ compute_bounding_box_pointset(ctx, ¤t_pointset); float_t fraction = (current_partition.n_procs / 2) / (float_t)current_partition.n_procs; compute_median_pure_binning(ctx, ¤t_pointset, median_guess, fraction, selected_dim, n_bins, tolerance); int pv = partition_data_around_value(current_pointset.data, ctx->dims, selected_dim, 0, current_pointset.n_points, median_guess[selected_dim]); guess_t g = compute_median_pure_binning(ctx, ¤t_pointset, fraction, selected_dim, n_bins, tolerance); int pv = partition_data_around_value(current_pointset.data, ctx->dims, selected_dim, 0, current_pointset.n_points, g.x_guess); /* insert node */ /* Loading @@ -1486,14 +1251,11 @@ void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree * */ if (current_pointset.n_points < expected_points_per_node) { top_tree_insert(ctx, tree, median_guess, selected_dim, MY_TRUE, current_pointset.n_points); } else { top_tree_insert(ctx, tree, median_guess, selected_dim, MY_FALSE, current_pointset.n_points); } top_kdtree_node_t* current_node; current_node -> data = g.x_guess; current_node -> split_dim = selected_dim; current_node -> parent = current_partition.parent; size_t points_left = current_partition.n_points * fraction; size_t points_right = current_partition.n_points - points_left; Loading @@ -1504,13 +1266,25 @@ void build_top_kdtree(global_context_t *ctx, pointset_t *og_pointset, top_kdtree int next_dimension = (++selected_dim) % (ctx->dims); partition_t left_partition = { .n_points = points_left, .n_procs = procs_left .n_procs = procs_left, .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, .parent = current_node, .lr = TOP_TREE_RCH, .base_ptr = current_pointset.data + pv, .d = next_dimension }; /* get left and right pointset */ } free(median_guess); free_queue(&queue); } Loading @@ -1523,8 +1297,7 @@ void simulate_master_read_and_scatter(int dims, size_t n, global_context_t *ctx) if(ctx -> mpi_rank == 0) { data = (float_t*)malloc(dims*n*sizeof(float_t)); //for(size_t i = 0; i < dims * n; ++i) data[i] = (float_t)rand()/(float_t)(RAND_MAX); //for(size_t i = 0; i < dims * n; ++i) data[i] = (float_t)rand()/(float_t)(RAND_MAX); //for(size_t i = 0; i < n; ++i) // for(size_t j = 0; j < dims; ++j) // data[i*dims + j] = (float_t)i; Loading @@ -1534,7 +1307,6 @@ void simulate_master_read_and_scatter(int dims, size_t n, global_context_t *ctx) ctx -> n_points = n; } */ /* read from files */ if (ctx->mpi_rank == 0) Loading Loading @@ -1586,11 +1358,8 @@ void simulate_master_read_and_scatter(int dims, size_t n, global_context_t *ctx) int k_local = 20; int k_global = 20; float_t *global_bin_counts = (float_t *)malloc(k_global * sizeof(float_t)); uint64_t *global_bin_counts_int = (uint64_t *)malloc(k_global * sizeof(uint64_t)); float_t *best_guess = (float_t *)malloc(ctx->dims * sizeof(float_t)); float_t *bin_bounds = (float_t *)malloc((k_local + 1) * sizeof(float_t)); uint64_t *global_bin_counts_int = (uint64_t *)malloc(k_global * sizeof(uint64_t)); pointset_t original_ps; original_ps.data = ctx->local_data; Loading @@ -1609,39 +1378,15 @@ void simulate_master_read_and_scatter(int dims, size_t n, global_context_t *ctx) int best_bin_idx; float_t ep; /* compute_bounding_box_pointset(ctx,&original_ps); compute_adaptive_binning_pointset(ctx,&original_ps,k_local,k_global, d, bin_bounds, global_bin_counts); best_bin_idx = retrieve_guess_adaptive(ctx, &original_ps,global_bin_counts, best_guess, k_global, d, f); //check_pc_pointset(ctx, &ps, best_guess, d, f); ep = check_pc_pointset_parallel(ctx, &original_ps, best_guess, d, f); */ /** if(fabs(ep - f) > 0.02) { refine_on_bin(ctx, &original_ps, best_guess, global_bin_counts, best_bin_idx, k_global, k_local, d, f, 0.2); } */ // MPI_DB_PRINT("--------------------------------------\n\n"); compute_bounding_box_pointset(ctx, &original_ps); compute_pure_global_binning(ctx, &original_ps, global_bin_counts_int, k_global, d); best_bin_idx = retrieve_guess_pure( ctx, &original_ps, global_bin_counts_int, best_guess, k_global, d, f); compute_pure_global_binning(ctx, &original_ps, global_bin_counts_int, k_global, d); guess_t g = retrieve_guess_pure( ctx, &original_ps, global_bin_counts_int, k_global, d, f); // check_pc_pointset(ctx, &ps, best_guess, d, f); ep = check_pc_pointset_parallel(ctx, &original_ps, best_guess, d, f); g.ep = check_pc_pointset_parallel(ctx, &original_ps, g, d, f); ep = refine_pure_binning(ctx, &original_ps, best_guess, global_bin_counts_int, best_bin_idx, k_global, d, f, ep, tol); g = refine_pure_binning(ctx, &original_ps, g, global_bin_counts_int, k_global, d, f, tol); MPI_DB_PRINT("[MASTER] dimension %d searching for %lf found %lf\n", d, f, ep); MPI_DB_PRINT("[MASTER] dimension %d searching for %lf found %lf\n", d, f, g.ep); } MPI_DB_PRINT("--------------------------------------\n\n"); } Loading @@ -1655,10 +1400,7 @@ void simulate_master_read_and_scatter(int dims, size_t n, global_context_t *ctx) free(send_counts); free(displacements); free(global_bin_counts); // free(pvt_data); free(bin_bounds); free(best_guess); if (ctx->mpi_rank == 0) free(data); Loading
src/tree/tree.h +14 −2 Original line number Diff line number Diff line Loading @@ -5,11 +5,20 @@ #include <math.h> #include "../common/common.h" typedef struct mpi_double_int{ float_t val; int key; } mpi_double_int; typedef struct guess_t { float_t x_guess; int bin_idx; float_t ep; } guess_t; typedef struct partition_t { Loading @@ -17,6 +26,8 @@ typedef struct partition_t int n_procs; size_t n_points; float_t* base_ptr; int lr; struct top_kdtree_node_t* parent; } partition_t; typedef struct partition_queue_t Loading @@ -29,13 +40,15 @@ typedef struct partition_queue_t typedef struct top_kdtree_node_t { float_t* data; float_t data; //float_t* node_box_lb; //Needed? //float_t* node_box_ub; //Needed? int owner; int split_dim; int is_leaf; size_t n_points; float_t* lb_box; float_t* ub_box; struct top_kdtree_node_t* lch; struct top_kdtree_node_t* rch; struct top_kdtree_node_t* parent; Loading @@ -46,7 +59,6 @@ typedef struct top_kdtree_t int dims; size_t count; size_t _capacity; float_t* medians; struct top_kdtree_node_t* _nodes; struct top_kdtree_node_t* root; Loading