// // This file is part of the Bones source-to-source compiler examples. This C-code // demonstrates the use of Bones for an example application: 'K-means clustering', // as also available in the Rodinia benchmark suite. For more information on the // application or on Bones please use the contact information below. // // == This implementation of K-means clustering is inspired by: // Author.............Roger Zhang // Web address........http://cs.smu.ca/~r_zhang/code/kmeans.c // // == More information on Bones // Contact............Cedric Nugteren // Web address........http://parse.ele.tue.nl/bones/ // // == File information // Filename...........applications/kmeans.c // Authors............Cedric Nugteren // Last modified on...10-Aug-2012 // //######################################################################## //### Includes //######################################################################## #include #include #include //######################################################################## //### Defines //######################################################################## #define SIZE 512 #define NUM_CLUSTERS 20 #define DIMENSIONS 2 #define THRESHOLD 0.0001 //######################################################################## //### Start of the main function //######################################################################## int main(void) { // Declare the loop iterators int i,j,k; // Declare the error variables double error = DBL_MAX; double old_error; int iterations = 0; // Declare the distance variables and arrays double distance[1]; double min_distance[1]; double distances[SIZE]; // Initialising memory printf("\n[k-means] Initialising memory"); fflush(stdout); double input[SIZE][DIMENSIONS]; double centroids[NUM_CLUSTERS][DIMENSIONS]; double centroids_temp[NUM_CLUSTERS][DIMENSIONS]; int output[SIZE]; int counts[NUM_CLUSTERS]; // Set the input data printf("\n[k-means] Populating memory"); fflush(stdout); for (i=0; i THRESHOLD); // Print the results printf("\n[k-means] Algorithm finished in %d iterations with an error of %.3lf", iterations, error); fflush(stdout); printf("\n[k-means] Printing the results: \n\n"); fflush(stdout); for (k=0; k