#include #include #include "knnMPIBlockingDeclarations.h" #include "mpi.h" /* Structs */ struct timeval startwtime, endwtime , commStartWTime, commEndWTime , calcStartWTime, calcEndWTime; /* Global variables */ int numberOfPoints = 0, numberOfDimensions = 0, numberOfNeighbors = 0; char *pointsFilename = NULL, *testFilename = NULL; double seq_time = 0; /* Main */ int main(int argc, char **argv){ int numberOfTasks = 0, taskId = 0, chunksize = 0, myOffset = 0, destination = 0, source = 0; double **myPoints, **inBuffer, **outBuffer, commTimeSum = 0, calcTimeSum = 0; neighbor **sortedNeighborsArray; MPI_Status status; getArguments(argc, argv); //Initializes mpi and necessary variables MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &numberOfTasks); if (numberOfPoints % numberOfTasks != 0){ printf("Quitting. Number of points must be divisible by number of MPI tasks.\n"); abExit(0); } MPI_Comm_rank(MPI_COMM_WORLD, &taskId); chunksize = numberOfPoints / numberOfTasks; //number of points each task has myOffset = taskId * chunksize; //this task's offset from (complete) point's array start destination = taskId + 1; //this task's destination task id for sending messages if (destination >= numberOfTasks){ destination = 0; } source= taskId - 1; //this task's source task id for receiving messages if (source < 0){ source = numberOfTasks - 1; } init(&myPoints, &inBuffer, &outBuffer, &sortedNeighborsArray, chunksize , myOffset * numberOfDimensions); MPI_Barrier(MPI_COMM_WORLD); if (taskId == MASTER){ gettimeofday(&startwtime, NULL); } gettimeofday(&calcStartWTime, NULL); //Calculates distances between task's own points calculateDistances(&myPoints, &myPoints, &sortedNeighborsArray, chunksize, myOffset , taskId * chunksize); gettimeofday(&calcEndWTime, NULL); calcTimeSum += (double)((calcEndWTime.tv_usec - calcStartWTime.tv_usec)/1.0e6 + calcEndWTime.tv_sec - calcStartWTime.tv_sec); for (int chunk=0; chunk