#ifndef KNNMPINONBLOCKINGFUNCTIONDECLARATION_H_ /* Include guard */ #define KNNMPINONBLOCKINGFUNCTIONDECLARATION_H_ /* Constants definitions */ #define MASTER 0 //task id of the master process #define BLOCK_SENT 0 //index of request used for sending blocks in the requests array #define BLOCK_RECEIVED 1 //index of request used for receiving blocks in the requests array /* 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 that should be found 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 , double ***inBuffer //pointer to the array used as input buffer for mpi , double ***outBuffer //pointer to the array used as output buffer for mpi , neighbor ***sortedNeighborsArray //pointer to the array holding the distances and ID's , int chunksize //number of rows (points) to be allocated , int offset); //process offset used when reading points from the file //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 , int chunksize //number of rows (points) to be read , int offset); //offset from which reading will start //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 , int chunksize //number of points , int myOffset //offset used for ID's of first pool's points , int indexOffset); //offset used for ID's of seconds pool's points //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 firstPointIndex //Index of the first point in task's array , 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 swapPointers swaps the memory blocks pointed to by two pointers void swapPointers(double ***firstArray //first memory block , double ***secondArray); //second memory block //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 , int chunksize //number of points , int offset //process offset , 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 , double ***inBuffer //input buffer pointer , double ***outBuffer //output buffer pointer , neighbor ***sortedNeighborsArray //distanced array pointer , int chunksize); //number of rows (points) //Function abExit exits the program after checking for mpi initialization void abExit(int exitCode); //exit code to exit with #endif // KNNMPINONBLOCKINGFUNCTIONDECLARATION_H_