/** find_clusters() * Find the cluster that is most suitable for a given set of points */ void *find_clusters(void *arg) { thread_arg *t_arg = (thread_arg *)arg; int i, j; unsigned int min_dist, cur_dist; int min_idx; int start_idx = t_arg->start_idx; int end_idx = start_idx + t_arg->num_pts; for (i = start_idx; i < end_idx; i++) { min_dist = get_sq_dist(points[i], means[0]); min_idx = 0; for (j = 1; j < num_means; j++) { cur_dist = get_sq_dist(points[i], means[j]); if (cur_dist < min_dist) { min_dist = cur_dist; min_idx = j; } } if (clusters[i] != min_idx) { clusters[i] = min_idx; modified = true; } } return (void *)0; }
/** find_clusters() * Find the cluster that is most suitable for a given set of points */ void find_clusters(int **points, int **means, int *clusters) { int i, j; unsigned int min_dist, cur_dist; int min_idx; for (i = 0; i < num_points; i++) { min_dist = get_sq_dist(points[i], means[0]); min_idx = 0; for (j = 1; j < num_means; j++) { cur_dist = get_sq_dist(points[i], means[j]); if (cur_dist < min_dist) { min_dist = cur_dist; min_idx = j; } } if (clusters[i] != min_idx) { clusters[i] = min_idx; modified = true; } } }
/** find_clusters() * Find the cluster that is most suitable for a given set of points */ void find_clusters(int *points, keyval_t *means, int *clusters, int size) { int i, j; unsigned int min_dist, cur_dist; int min_idx; for (i = 0; i < size; i++) { min_dist = get_sq_dist(&points[i * dim], (int *)(means[0].val)); min_idx = 0; for (j = 1; j < num_means; j++) { cur_dist = get_sq_dist(&points[i * dim], (int *)(means[j].val)); if (cur_dist < min_dist) { min_dist = cur_dist; min_idx = j; } } if (clusters[i] != min_idx) { clusters[i] = min_idx; modified = true; } //dprintf("Emitting [%d,%d]\n", *((int *)means[min_idx].key), *(points[i])); emit_intermediate(means[min_idx].key, (void *)(&points[i * dim]), sizeof(means[min_idx].key)); } }
/** find_clusters() * Find the cluster that is most suitable for a given set of points */ void *find_clusters(void *arg) { int modified = false; thread_arg *t_arg = (thread_arg *)arg; int i, j; unsigned int min_dist, cur_dist; int min_idx; int start_idx = t_arg->start_idx; int end_idx = start_idx + t_arg->num_pts; int dim = t_arg->dim; int num_means = t_arg->num_means; int num_points = t_arg->num_points; int ** means = t_arg->means; int ** points = t_arg->points; int * clusters = t_arg->clusters; for (i = start_idx; i < end_idx; i++) { min_dist = get_sq_dist(points[i], means[0], dim); min_idx = 0; for (j = 1; j < num_means; j++) { cur_dist = get_sq_dist(points[i], means[j], dim); if (cur_dist < min_dist) { min_dist = cur_dist; min_idx = j; } } if (clusters[i] != min_idx) { clusters[i] = min_idx; modified = true; } } return (void *) modified; }