Exercise 2 for the course "Parallel and distributed systems" of THMMY in AUTH university.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
4.7 KiB

6 years ago
#ifndef KNNMPINONBLOCKINGFUNCTIONDECLARATIONS_H_ /* Include guard */
#define KNNMPINONBLOCKINGFUNCTIONDECLARATIONS_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 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
, 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 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 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 //distances 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 // KNNMPINONBLOCKINGFUNCTIONDECLARATIONS_H_