#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 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 addDistanceAndShift searches an array of neighbors (struct) for an index holding either //an empty distance or a distance that is greater than the one that came in the arguments //(pointsDistance), shifts "right" one time all values of the array after this index and fills the //empty position created after shifting with the one that came in the arguments (pointsDistance) void addDistanceAndShift(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 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_