// // 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...06-Jun-2014 // //######################################################################## // Includes #include "common.h" //######################################################################## //### Start of the main function //######################################################################## int main(void) { // Declare the loop iterators int i,j,k; // Declare the error variables float error[1] = { 100000.0 }; float old_error; int iterations = 0; // Declare the distance variables and arrays float distances[SIZE]; // Initialising memory printf("\n[k-means] Initialising memory"); fflush(stdout); float input[SIZE][DIMENSIONS]; float centroids[NUM_CLUSTERS][DIMENSIONS]; float 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 0) { val = centroids_temp[k][j] / count; } else { val = centroids_temp[k][j]; } centroids[k][j] = val; } } // Go to the next iteration iterations += 1; #pragma endscop //} } while (fabs(error[0]-old_error) > THRESHOLD); // Print the results printf("\n[k-means] Algorithm finished in %d iterations with an error of %.3lf", iterations, error[0]); fflush(stdout); //printf("\n[k-means] Printing the results: \n\n"); fflush(stdout); //for (k=0; k