#ifndef KNNSERIALDECLARATIONS_H_ /* Include guard */ #define KNNSERIALDECLARATIONS_H_ /* Structs */ typedef struct neighbor{ //simple struct defining a point's neighbor double distance; //distance between the two neighbors (points) int neighborId; //index of the neighbor in the (complete) array of points } neighbor; /* Global variables */ extern int numberOfPoints; //number of the points knn should run for extern int numberOfDimensions; //number of dimensions of each point extern int numberOfNeighbors; //number of nearest neighbors knn should find for each point extern int k; //number of nearest neighbors requested by the user extern char *pointsFilename; //name of the binary file storing the coordinates of points extern char *testFilename; //name of binary file storing correct neighbors IDs array /* Functions declaration */ //Function getArguments is used to parse arguments provided to main void getArguments(int argc //arguments count , char** argv); //arguments array //Function init allocates memory for the arrays used and initializes them void init(double ***pointsArray //pointer to the array of points , neighbor ***sortedNeighborsArray); //pointer to the array holding the distances and ID's //Function cMalloc allocates and returns a single block of continuous memory which can //be indexed like a regular array, e.g. array[row][column] double **cMalloc(int rows //number of rows to be allocated , int columns); //number of columns to be allocated //Function readPointsArrayFromFile reads the coordinates of the points from a file and stores them //in an array int readPointsArrayFromFile(double ***array); //array that will hold the coordinates of the points //Function printArray iterates the values of an array printing them void printArray(int rows //number of array's rows , int columns //number of array's columns , double ***array); //array to be printed //Function calculateDistances calculates the distances between all points in two different sets and //adds the distance to sortedNeighborsArray void calculateDistances(double ***firstPointsSet //first pool of points coordinates , double ***secondPointsSet //second pool of points coordinates , neighbor ***sortedNeighborsArray); //array that holds the distances //Function addDistance adds distances to sorted neighbors array, sorted by the ID of the neighbor void addDistance(neighbor ***sortedNeighborsArray //array that holds the distances , int firstPointId //ID of the first point , int secondPointId //ID of the second point , double pointsDistance); //distance between the two points //Function compare compares two neighbors using their distance fields, returns 0 if distances are //equal, 1 if distance of first argument is greater and -1 otherwise int compare (const void *a //first neighbor , const void *b); //second neighbor //Function test checks the validity of the solution based on correct results previously generated //and stored in a text file int test(neighbor ***sortedNeighborsArray //array that holds the IDs , char *testFilename); //name of text file storing correct neighbors IDs array //Function cleanUp frees all memory previously allocated void cleanUp(double ***pointsArray //points array pointer , neighbor ***sortedNeighborsArray); //distances array pointer #endif // KNNMPINONBLOCKINGFUNCTIONDECLARATIONS_H_