//kmeans_starter.c #include #include #include #include #include #include #define KMEANSITERS 10 //compile //mpicc kmeans.c -lm -o kmeans //run example with 2 means //mpirun -np 4 -hostfile myhostfile.txt ./kmeans 5159737 2 2 iono_57min_5.16Mpts_2D.txt //function prototypes int importDataset(char * fname, int N, double ** dataset); int main(int argc, char **argv) { int my_rank, nprocs; MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD,&my_rank); MPI_Comm_size(MPI_COMM_WORLD,&nprocs); //Process command-line arguments int N; int DIM; int KMEANS; char inputFname[500]; if (argc != 5) { fprintf(stderr,"Please provide the following on the command line: N (number of lines in the file), dimensionality (number of coordinates per point/feature vector), K (number of means), dataset filename. Your input: %s\n",argv[0]); MPI_Finalize(); exit(0); } sscanf(argv[1],"%d",&N); sscanf(argv[2],"%d",&DIM); sscanf(argv[3],"%d",&KMEANS); strcpy(inputFname,argv[4]); //pointer to entire dataset double ** dataset; if (N<1 || DIM <1 || KMEANS < 1) { printf("\nOne of the following are invalid: N, DIM, K(MEANS)\n"); MPI_Finalize(); exit(0); } //All ranks import dataset else { if (my_rank==0) { printf("\nNumber of lines (N): %d, Dimensionality: %d, KMEANS: %d, Filename: %s\n", N, DIM, KMEANS, inputFname); } //allocate memory for dataset dataset=(double**)malloc(sizeof(double*)*N); for (int i=0; i