Loading src/common/common.c +7 −0 Original line number Diff line number Diff line Loading @@ -1110,4 +1110,11 @@ void write_cluster_results(global_context_t* ctx, clusters_t* clusters, write_centers_binary(ctx, clusters, output_dir); write_borders_binary(ctx, clusters, output_dir); write_assignments_binary(ctx, local_assignments, output_dir, parallel_dump); if(parallel_dump) { char filepath[PATH_LEN]; snprintf(filepath, PATH_LEN, "%s/og_idxs", output_dir); distributed_buffer_to_file(ctx, ctx -> og_idxs, sizeof(idx_t), ctx -> local_n_points, filepath); } } src/main/main.c +23 −30 Original line number Diff line number Diff line Loading @@ -468,35 +468,28 @@ void mpiio_master_read_and_scatter(int dims, size_t n, global_context_t *ctx) break; } if(ctx -> world_size <= 32) { char out_file[200]; snprintf(out_file, 200, "%s/og_idx", ctx->output_data_file); big_ordered_buffer_to_file(ctx, ctx->og_idxs, sizeof(idx_t), ctx -> local_n_points, out_file); snprintf(out_file, 200, "%s/data", ctx->output_data_file); big_ordered_buffer_to_file(ctx, data_to_write, sizeof(float_t), ctx -> local_n_points * ctx -> dims, out_file); } else { char out_file[200]; // if(ctx -> world_size <= 32) // { // char out_file[200]; // // snprintf(out_file, 200, "%s/og_idx", ctx->output_data_file); // big_ordered_buffer_to_file(ctx, ctx->og_idxs, sizeof(idx_t), ctx -> local_n_points, out_file); // // snprintf(out_file, 200, "%s/data", ctx->output_data_file); // big_ordered_buffer_to_file(ctx, data_to_write, sizeof(float_t), ctx -> local_n_points * ctx -> dims, out_file); // } // else // { // char out_file[200]; // // snprintf(out_file, 200, "%s/og_idx", ctx->output_data_file); // distributed_buffer_to_file(ctx, ctx->og_idxs, sizeof(idx_t), ctx -> local_n_points, out_file); // // snprintf(out_file, 200, "%s/data", ctx->output_data_file); // distributed_buffer_to_file(ctx, data_to_write, sizeof(float_t), ctx -> local_n_points * ctx -> dims, out_file); // } snprintf(out_file, 200, "%s/og_idx", ctx->output_data_file); distributed_buffer_to_file(ctx, ctx->og_idxs, sizeof(idx_t), ctx -> local_n_points, out_file); snprintf(out_file, 200, "%s/data", ctx->output_data_file); distributed_buffer_to_file(ctx, data_to_write, sizeof(float_t), ctx -> local_n_points * ctx -> dims, out_file); } if(ctx->parallel_dump) { write_cluster_results(ctx, &clusters, cl, ctx->output_data_file, ctx->parallel_dump); } else { write_cluster_results(ctx, &clusters, cl, ctx->output_data_file, ctx->parallel_dump); } elapsed_time = TIME_STOP; LOG_WRITE("Write results to file", elapsed_time); Loading src/tree/tree.c +20 −71 Original line number Diff line number Diff line Loading @@ -290,42 +290,17 @@ void compute_bounding_box_data(global_context_t *ctx, float_t *data, float_t* lb /* compute minimum and maximum for each dimensions, store them in local bb */ /* each processor on its own */ // this moves memory maybe there is a better way #pragma omp parallel { float_t* pvt_lb = (float_t*)MY_MALLOC(ctx -> dims * sizeof(float_t)); float_t* pvt_ub = (float_t*)MY_MALLOC(ctx -> dims * sizeof(float_t)); for (size_t d = 0; d < ctx->dims; ++d) { pvt_lb[d] = FLT_MAX; pvt_ub[d] = -FLT_MAX; } #pragma omp for // Use OpenMP 4.5+ array reduction with runtime size #pragma omp parallel for reduction(min:lb[:ctx->dims]) reduction(max:ub[:ctx->dims]) for (size_t i = 0; i < n_points; ++i) { for (size_t d = 0; d < ctx->dims; ++d) { pvt_lb[d] = MIN(data[i*ctx->dims + d], pvt_lb[d]); pvt_ub[d] = MAX(data[i*ctx->dims + d], pvt_ub[d]); } } #pragma omp critical (bounding_box_reduction) { for (size_t d = 0; d < ctx->dims; ++d) { lb[d] = MIN(pvt_lb[d], lb[d]); ub[d] = MAX(pvt_ub[d], ub[d]); lb[d] = MIN(data[i*ctx->dims + d], lb[d]); ub[d] = MAX(data[i*ctx->dims + d], ub[d]); } } free(pvt_lb); free(pvt_ub); } /*get the bounding box */ MPI_Allreduce(MPI_IN_PLACE, lb, ctx->dims, MPI_MY_FLOAT, MPI_MIN, ctx->mpi_communicator); Loading @@ -342,54 +317,28 @@ void compute_bounding_box_data(global_context_t *ctx, float_t *data, float_t* lb } void compute_bounding_box_pointset(global_context_t *ctx, pointset_t *ps) { #define local_data ps->datapoints #define lb ps->lb_box #define ub ps->ub_box // Use local pointers instead of macros to enable efficient OpenMP reduction point_t* local_data = ps->datapoints; float_t* lb = ps->lb_box; float_t* ub = ps->ub_box; for (size_t d = 0; d < ps->dims; ++d) { ps->lb_box[d] = FLT_MAX; ps->ub_box[d] = -FLT_MAX; // Initialize bounding boxes for (size_t d = 0; d < ps->dims; ++d) { lb[d] = FLT_MAX; ub[d] = -FLT_MAX; } /* compute minimum and maximum for each dimensions, store them in local bb */ /* each processor on its own */ // this moves memory maybe there is a better way #pragma omp parallel { float_t* pvt_lb = (float_t*)MY_MALLOC(ctx -> dims * sizeof(float_t)); float_t* pvt_ub = (float_t*)MY_MALLOC(ctx -> dims * sizeof(float_t)); for (size_t d = 0; d < ps->dims; ++d) { pvt_lb[d] = FLT_MAX; pvt_ub[d] = -FLT_MAX; } #pragma omp for #pragma omp parallel for reduction(min:lb[:ps->dims]) reduction(max:ub[:ps->dims]) for (size_t i = 0; i < ps->n_points; ++i) { for (size_t d = 0; d < ps->dims; ++d) { pvt_lb[d] = MIN(local_data[i].data[d], pvt_lb[d]); pvt_ub[d] = MAX(local_data[i].data[d], pvt_ub[d]); } lb[d] = MIN(local_data[i].data[d], lb[d]); ub[d] = MAX(local_data[i].data[d], ub[d]); } #pragma omp critical (bounding_box_reduction) { for (size_t d = 0; d < ps->dims; ++d) { lb[d] = MIN(pvt_lb[d], lb[d]); ub[d] = MAX(pvt_ub[d], ub[d]); } } free(pvt_lb); free(pvt_ub); } /*get the bounding box */ Loading Loading
src/common/common.c +7 −0 Original line number Diff line number Diff line Loading @@ -1110,4 +1110,11 @@ void write_cluster_results(global_context_t* ctx, clusters_t* clusters, write_centers_binary(ctx, clusters, output_dir); write_borders_binary(ctx, clusters, output_dir); write_assignments_binary(ctx, local_assignments, output_dir, parallel_dump); if(parallel_dump) { char filepath[PATH_LEN]; snprintf(filepath, PATH_LEN, "%s/og_idxs", output_dir); distributed_buffer_to_file(ctx, ctx -> og_idxs, sizeof(idx_t), ctx -> local_n_points, filepath); } }
src/main/main.c +23 −30 Original line number Diff line number Diff line Loading @@ -468,35 +468,28 @@ void mpiio_master_read_and_scatter(int dims, size_t n, global_context_t *ctx) break; } if(ctx -> world_size <= 32) { char out_file[200]; snprintf(out_file, 200, "%s/og_idx", ctx->output_data_file); big_ordered_buffer_to_file(ctx, ctx->og_idxs, sizeof(idx_t), ctx -> local_n_points, out_file); snprintf(out_file, 200, "%s/data", ctx->output_data_file); big_ordered_buffer_to_file(ctx, data_to_write, sizeof(float_t), ctx -> local_n_points * ctx -> dims, out_file); } else { char out_file[200]; // if(ctx -> world_size <= 32) // { // char out_file[200]; // // snprintf(out_file, 200, "%s/og_idx", ctx->output_data_file); // big_ordered_buffer_to_file(ctx, ctx->og_idxs, sizeof(idx_t), ctx -> local_n_points, out_file); // // snprintf(out_file, 200, "%s/data", ctx->output_data_file); // big_ordered_buffer_to_file(ctx, data_to_write, sizeof(float_t), ctx -> local_n_points * ctx -> dims, out_file); // } // else // { // char out_file[200]; // // snprintf(out_file, 200, "%s/og_idx", ctx->output_data_file); // distributed_buffer_to_file(ctx, ctx->og_idxs, sizeof(idx_t), ctx -> local_n_points, out_file); // // snprintf(out_file, 200, "%s/data", ctx->output_data_file); // distributed_buffer_to_file(ctx, data_to_write, sizeof(float_t), ctx -> local_n_points * ctx -> dims, out_file); // } snprintf(out_file, 200, "%s/og_idx", ctx->output_data_file); distributed_buffer_to_file(ctx, ctx->og_idxs, sizeof(idx_t), ctx -> local_n_points, out_file); snprintf(out_file, 200, "%s/data", ctx->output_data_file); distributed_buffer_to_file(ctx, data_to_write, sizeof(float_t), ctx -> local_n_points * ctx -> dims, out_file); } if(ctx->parallel_dump) { write_cluster_results(ctx, &clusters, cl, ctx->output_data_file, ctx->parallel_dump); } else { write_cluster_results(ctx, &clusters, cl, ctx->output_data_file, ctx->parallel_dump); } elapsed_time = TIME_STOP; LOG_WRITE("Write results to file", elapsed_time); Loading
src/tree/tree.c +20 −71 Original line number Diff line number Diff line Loading @@ -290,42 +290,17 @@ void compute_bounding_box_data(global_context_t *ctx, float_t *data, float_t* lb /* compute minimum and maximum for each dimensions, store them in local bb */ /* each processor on its own */ // this moves memory maybe there is a better way #pragma omp parallel { float_t* pvt_lb = (float_t*)MY_MALLOC(ctx -> dims * sizeof(float_t)); float_t* pvt_ub = (float_t*)MY_MALLOC(ctx -> dims * sizeof(float_t)); for (size_t d = 0; d < ctx->dims; ++d) { pvt_lb[d] = FLT_MAX; pvt_ub[d] = -FLT_MAX; } #pragma omp for // Use OpenMP 4.5+ array reduction with runtime size #pragma omp parallel for reduction(min:lb[:ctx->dims]) reduction(max:ub[:ctx->dims]) for (size_t i = 0; i < n_points; ++i) { for (size_t d = 0; d < ctx->dims; ++d) { pvt_lb[d] = MIN(data[i*ctx->dims + d], pvt_lb[d]); pvt_ub[d] = MAX(data[i*ctx->dims + d], pvt_ub[d]); } } #pragma omp critical (bounding_box_reduction) { for (size_t d = 0; d < ctx->dims; ++d) { lb[d] = MIN(pvt_lb[d], lb[d]); ub[d] = MAX(pvt_ub[d], ub[d]); lb[d] = MIN(data[i*ctx->dims + d], lb[d]); ub[d] = MAX(data[i*ctx->dims + d], ub[d]); } } free(pvt_lb); free(pvt_ub); } /*get the bounding box */ MPI_Allreduce(MPI_IN_PLACE, lb, ctx->dims, MPI_MY_FLOAT, MPI_MIN, ctx->mpi_communicator); Loading @@ -342,54 +317,28 @@ void compute_bounding_box_data(global_context_t *ctx, float_t *data, float_t* lb } void compute_bounding_box_pointset(global_context_t *ctx, pointset_t *ps) { #define local_data ps->datapoints #define lb ps->lb_box #define ub ps->ub_box // Use local pointers instead of macros to enable efficient OpenMP reduction point_t* local_data = ps->datapoints; float_t* lb = ps->lb_box; float_t* ub = ps->ub_box; for (size_t d = 0; d < ps->dims; ++d) { ps->lb_box[d] = FLT_MAX; ps->ub_box[d] = -FLT_MAX; // Initialize bounding boxes for (size_t d = 0; d < ps->dims; ++d) { lb[d] = FLT_MAX; ub[d] = -FLT_MAX; } /* compute minimum and maximum for each dimensions, store them in local bb */ /* each processor on its own */ // this moves memory maybe there is a better way #pragma omp parallel { float_t* pvt_lb = (float_t*)MY_MALLOC(ctx -> dims * sizeof(float_t)); float_t* pvt_ub = (float_t*)MY_MALLOC(ctx -> dims * sizeof(float_t)); for (size_t d = 0; d < ps->dims; ++d) { pvt_lb[d] = FLT_MAX; pvt_ub[d] = -FLT_MAX; } #pragma omp for #pragma omp parallel for reduction(min:lb[:ps->dims]) reduction(max:ub[:ps->dims]) for (size_t i = 0; i < ps->n_points; ++i) { for (size_t d = 0; d < ps->dims; ++d) { pvt_lb[d] = MIN(local_data[i].data[d], pvt_lb[d]); pvt_ub[d] = MAX(local_data[i].data[d], pvt_ub[d]); } lb[d] = MIN(local_data[i].data[d], lb[d]); ub[d] = MAX(local_data[i].data[d], ub[d]); } #pragma omp critical (bounding_box_reduction) { for (size_t d = 0; d < ps->dims; ++d) { lb[d] = MIN(pvt_lb[d], lb[d]); ub[d] = MAX(pvt_ub[d], ub[d]); } } free(pvt_lb); free(pvt_ub); } /*get the bounding box */ Loading