diff --git a/part-comm/.test_commOrder3.c.swp b/part-comm/.test_commOrder3.c.swp new file mode 100644 index 0000000..4b59511 Binary files /dev/null and b/part-comm/.test_commOrder3.c.swp differ diff --git a/part-comm/test.c b/part-comm/test.c new file mode 100644 index 0000000..9c2fc77 --- /dev/null +++ b/part-comm/test.c @@ -0,0 +1,74 @@ +#include +#include +#include "mpi.h" +#define PARTITIONS 8 +#define COUNT 4 + +int main (int argc, char *argv[]) +{ +double message [PARTITIONS * COUNT]; +int src = 0, dest = 1, tag = 100, flag = 0, flag2 = 0; +int send_partitions = PARTITIONS, + send_partlength = COUNT, + recv_partitions = PARTITIONS/2, + recv_partlength = COUNT*2; +int myrank, provided, i, j; +MPI_Request request; + +MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); +if (provided < MPI_THREAD_SERIALIZED) + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +MPI_Comm_rank(MPI_COMM_WORLD, &myrank); + +if (myrank == 0) +{ + MPI_Psend_init(message, send_partitions, send_partlength, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + for (i = 0; i < send_partitions; i++) + { + printf("Partition %d Ready to Send, Send Buff: ", i); + for (j = (i*send_partlength); j < ((i+1)*send_partlength); j++) + { + message[j] = j+1; + printf(" %.2lf, ", message[j]); + } + printf("\n"); + MPI_Pready(i, request); + + } + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + MPI_Request_free(&request); +} +else if (myrank == 1) +{ + MPI_Precv_init(message, recv_partitions, recv_partlength, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + for (i = 0; i < recv_partitions; i++) + { + MPI_Parrived(request, i, &flag2); + if (!flag2) { + i--; + } + else { + printf("Partition %d Recieved Buff: ", i); + for (j = (i*recv_partlength); j < ((i+1)*recv_partlength); j++) + { + printf(" %.2lf, ", message[j]); + } + printf("\n"); + } + } + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + MPI_Request_free(&request); +} +MPI_Finalize(); +return 0; +} diff --git a/part-comm/test_commOrder0.c b/part-comm/test_commOrder0.c new file mode 100644 index 0000000..9c591cb --- /dev/null +++ b/part-comm/test_commOrder0.c @@ -0,0 +1,84 @@ +/*Partitions MPI Unit Test + * + * Shows the behavior of the communication when a partitioned recieve call is initialized + * before a partitioned send is declared + * */ + +#include +#include +#include "mpi.h" +#include "assert.h" + +#define PARTITIONS 8 +#define COUNT 5 + +int main (int argc, char *argv[]) +{ +//Buffer message +double message [PARTITIONS * COUNT]; + +//MPI variable declarations +int src = 0, dest = 1, tag = 100, flag = 0; +int myrank, provided, len, i, j; +char hostname[MPI_MAX_PROCESSOR_NAME]; +MPI_Count partitions = PARTITIONS; +MPI_Request request; + +//Initializing threaded MPI +MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); +if (provided < MPI_THREAD_SERIALIZED) + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +MPI_Comm_rank(MPI_COMM_WORLD, &myrank); +MPI_Get_processor_name(hostname, &len); + +if (myrank == 0) +{ + //This Barrier prevents task 0 to run before the partitioned recieve is initialized in task 1 + MPI_Barrier(MPI_COMM_WORLD); + + MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + //Iterating through each buffer partition, filling them and marking them ready to send + for (i = 0; i < partitions; i++) + { + for (j = (i*COUNT); j < ((i+1)*COUNT); j++) + { + message[j] = j+1; + } + MPI_Pready(i, request); + } + + //Test for overall send operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + MPI_Request_free(&request); +} +else if (myrank == 1) +{ + MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + //This Barrier allows task 0 to proceed + MPI_Barrier(MPI_COMM_WORLD); + + //Test for overall recieve operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + + //Test the buffer to check that the message was recieved correctly + for (i = 0; i < (PARTITIONS * COUNT); i++) + { + assert(message[i] = (i+1)); + } + printf("Test Passed Succesfully\n"); + MPI_Request_free(&request); +} +MPI_Finalize(); +return 0; +} + diff --git a/part-comm/test_commOrder1.c b/part-comm/test_commOrder1.c new file mode 100644 index 0000000..c844ec3 --- /dev/null +++ b/part-comm/test_commOrder1.c @@ -0,0 +1,85 @@ +/*Partitions MPI Unit Test + * + * Shows the behavior of the communicattion when a partitioned send call completes + * before a partitioned recieve call is declared + */ + +#include +#include +#include "mpi.h" +#include "assert.h" + +#define PARTITIONS 8 +#define COUNT 5 + +int main (int argc, char *argv[]) +{ +//Buffer message +double message [PARTITIONS * COUNT]; + +//MPI variable declaration +int src = 0, dest = 1, tag = 100, flag = 0, flag2 = 0; +int myrank, provided, len, i, j; +char hostname[MPI_MAX_PROCESSOR_NAME]; +MPI_Count partitions = PARTITIONS; +MPI_Request request; + +//Initializing threaded MPI +MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); +if (provided < MPI_THREAD_SERIALIZED) + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +MPI_Comm_rank(MPI_COMM_WORLD, &myrank); +MPI_Get_processor_name(hostname, &len); + +if (myrank == 0) +{ + MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + //Iterating through each buffer partition, filling them and marking them ready to send + for (i = 0; i < partitions; i++) + { + for (j = (i*COUNT); j < ((i+1)*COUNT); j++) + { + message[j] = j+1; + } + MPI_Pready(i, request); + } + + //Test for overall send operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + + //This Barrier allows task 1 to proceed + MPI_Barrier(MPI_COMM_WORLD); + + MPI_Request_free(&request); +} +else if (myrank == 1) +{ + //This Barrier prevents the task 1 to run before the partitioned send completes + MPI_Barrier(MPI_COMM_WORLD); + + MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + //Test for overall recieve operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + + //Test the buffer to check that the message was recieved correctly + for (i = 0; i < (PARTITIONS * COUNT); i++) + { + assert(message[i] == (i+1)); + } + printf("Test Passed Succesfully\n"); + MPI_Request_free(&request); +} +MPI_Finalize(); +return 0; +} + diff --git a/part-comm/test_commOrder2.c b/part-comm/test_commOrder2.c new file mode 100644 index 0000000..2782558 --- /dev/null +++ b/part-comm/test_commOrder2.c @@ -0,0 +1,85 @@ +/*Partitions MPI Unit Test + * + * Shows the behavior of the communication when a send / recv partitioned corridor + * is created and initialized before operations starts. + */ + +#include +#include +#include "mpi.h" +#include "assert.h" + +#define PARTITIONS 8 +#define COUNT 5 + +int main (int argc, char *argv[]) +{ +//Buffer message +double message [PARTITIONS * COUNT]; + +//MPI variables declaration +int src = 0, dest = 1, tag = 100, flag = 0, flag2 = 0; +int myrank, provided, len, i, j; +char hostname[MPI_MAX_PROCESSOR_NAME]; +MPI_Count partitions = PARTITIONS; +MPI_Request request; + +//Initializing threaded MPI +MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); +if (provided < MPI_THREAD_SERIALIZED) + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +MPI_Comm_rank(MPI_COMM_WORLD, &myrank); +MPI_Get_processor_name(hostname, &len); + +if (myrank == 0) +{ + MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + + MPI_Start(&request); + + //This Barrier ensures that a send/recv is establish before proceeding + MPI_Barrier(MPI_COMM_WORLD); + + //Iterating through each buffer partition, filling them and marking them ready to send + for (i = 0; i < partitions; i++) + { + for (j = (i*COUNT); j < ((i+1)*COUNT); j++) + { + message[j] = j+1; + } + MPI_Pready(i, request); + } + + //Test for overall send operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + MPI_Request_free(&request); +} +else if (myrank == 1) +{ + MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + //This Barrier ensures that a send/recv is establish before proceeding + MPI_Barrier(MPI_COMM_WORLD); + + //Test for overall recieve operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + + //Test the buffer to check that the message was recieved correctly + for (i = 0; i < (PARTITIONS * COUNT); i++) + { + assert(message[i] == (i+1)); + } + printf("Test Passed Succesfully\n"); + MPI_Request_free(&request); +} +MPI_Finalize(); +return 0; +} + diff --git a/part-comm/test_commOrder3.c b/part-comm/test_commOrder3.c new file mode 100644 index 0000000..8385b03 --- /dev/null +++ b/part-comm/test_commOrder3.c @@ -0,0 +1,112 @@ +/*Partitions MPI Unit Test + * + * Shows the behavior of the communication when a partitioned recv / send corridor is declared. + * Parrived loops trying to find a recieved partition before any are sent and fails. + * Parrived should timeout. + */ + +#include +#include +#include "mpi.h" +#include "assert.h" +#include "time.h" + +#define PARTITIONS 8 +#define COUNT 5 +#define TIMEOUT 10000 + +int main (int argc, char *argv[]) +{ +//Buffer message +double message [PARTITIONS * COUNT]; + +//MPI variables declarations +int src = 0, dest = 1, tag = 100, flag = 0, flag2 = 0; +int myrank, provided, len, timer, trigger, i, j; +char hostname[MPI_MAX_PROCESSOR_NAME]; +MPI_Count partitions = PARTITIONS; +MPI_Request request; + +//Initializing threaded MPI +MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); +if (provided < MPI_THREAD_SERIALIZED) + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +MPI_Comm_rank(MPI_COMM_WORLD, &myrank); +MPI_Get_processor_name(hostname, &len); + +if (myrank == 0) +{ + MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + + //This Barrier prevents task 0 to initialize a send operation before task 0 loops through Parrived + + MPI_Barrier(MPI_COMM_WORLD); + + MPI_Start(&request); + + //Iterating through each buffer partition, filling them and marking them ready to send + for (i = 0; i < partitions; i++) + { + for (j = (i*COUNT); j < ((i+1)*COUNT); j++) + { + message[j] = j+1; + } + MPI_Pready(i, request); + } + + //Test for overall send operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + MPI_Request_free(&request); +} +else if (myrank == 1) +{ + MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + //sets a timer in milliseconds equal to the time passed since beginning of operation + timer = clock() * 1000 / CLOCKS_PER_SEC; + //creates a trigger by adding a timeout time in millisecond to the current time passed + trigger = timer + TIMEOUT; + + //Iterates through the partitions and check indefinetly to see if they have arrived + for (i = 0; i < partitions; i++) + { + MPI_Parrived(request, i, &flag2); + if (!flag2) { + i--; + } + else { + //Test the buffer to check that the message was recieved correctly + for (j = (i * COUNT); j < ((i+1) * COUNT); j++) + { + assert(message[j] == (j + 1)); + } + } + //set timer equal to the current time elapsed + timer = clock() * 1000 / CLOCKS_PER_SEC; + //Abort MPI if Parrived loops more than time time allowed + if (timer > trigger){ + printf("Parrived Timeout, No Partitions recieved in %d millisecond", TIMEOUT); + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); + } + } + + //This barrier allows task 0 to proceed + MPI_Barrier(MPI_COMM_WORLD); + + //Test for overall recieve operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + + printf("Test Passed Succesfully\n"); + MPI_Request_free(&request); +} +MPI_Finalize(); +return 0; +} + diff --git a/part-comm/test_diffPartSize.c b/part-comm/test_diffPartSize.c new file mode 100644 index 0000000..05568b5 --- /dev/null +++ b/part-comm/test_diffPartSize.c @@ -0,0 +1,82 @@ +/*Partitions MPI Unit Test + * + * Shows the behavior of partitioned communication when there is different partitions size + * from send-side and recv-side. + * Buffer size stays the same. + */ + +#include +#include +#include "mpi.h" +#include "assert.h" + +#define PARTITIONS 5 +#define COUNT 3 + +int main (int argc, char *argv[]) +{ +//Buffer message +double message [PARTITIONS * COUNT]; + +//Sets send side partitions to the provided constant and recv-side partitions to half +//(int floors to the nearest lowest number in case of decimal) +int send_partitions = PARTITIONS, + send_partlength = COUNT, + recv_partitions = PARTITIONS/2, + recv_partlength = COUNT*2; + +//MPI variables declarations +int src = 0, dest = 1, tag = 100, flag = 0; +int myrank, provided, i, j; +MPI_Request request; + +//Initializing threaded MPI +MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); +if (provided < MPI_THREAD_SERIALIZED) + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +MPI_Comm_rank(MPI_COMM_WORLD, &myrank); + +if (myrank == 0) +{ + MPI_Psend_init(message, send_partitions, send_partlength, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + //Iterating through each buffer partition, filling them and marking them ready to send + for (i = 0; i < send_partitions; i++) + { + for (j = (i*send_partlength); j < ((i+1)*send_partlength); j++) + { + message[j]= j + 1; + } + MPI_Pready(i, request); + } + + //Test for overall send operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + MPI_Request_free(&request); +} +else if (myrank == 1) +{ + MPI_Precv_init(message, recv_partitions, recv_partlength, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + //Test for overall recieve operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + + //Test the buffer to check that the message was recieved correctly + for (i = 0; i < (PARTITIONS * COUNT); i++) + { + assert(message[i] == (i+1)); + } + printf("Test Passed Succesful\n"); + MPI_Request_free(&request); +} +MPI_Finalize(); +return 0; +} diff --git a/part-comm/test_negPartError.c b/part-comm/test_negPartError.c new file mode 100644 index 0000000..43a43cc --- /dev/null +++ b/part-comm/test_negPartError.c @@ -0,0 +1,80 @@ +/*Partitions MPI Unit Test + * + * Shows the behavior of the communication when a partitions is declared as a negative number + * This action should be erroneous + */ + +#include +#include +#include "mpi.h" +#include "assert.h" + +#define PARTITIONS 8 +#define COUNT 5 + +int main (int argc, char *argv[]) +{ +//Buffer message +double message [PARTITIONS * COUNT]; + +//Set partitions to a negative number +MPI_Count partitions = 0 - PARTITIONS; + +//MPI variables declarations +int src = 0, dest = 1, tag = 100, flag = 0, flag2 = 0; +int myrank, provided, len, i, j; +char hostname[MPI_MAX_PROCESSOR_NAME]; +MPI_Request request; + +//Initializing threaded MPI +MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); +if (provided < MPI_THREAD_SERIALIZED) + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +MPI_Comm_rank(MPI_COMM_WORLD, &myrank); +MPI_Get_processor_name(hostname, &len); + +if (myrank == 0) +{ + MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + //Iterating through each buffer partition, filling them and marking them ready to send + for (i = 0; i < partitions; i++) + { + for (j = (i*COUNT); j < ((i+1)*COUNT); j++) + { + message[j] = j+1; + } + MPI_Pready(i, request); + } + + //Test for overall send operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + MPI_Request_free(&request); +} +else if (myrank == 1) +{ + MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + //Test for overall recieve operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + + //Test the buffer to check that the message was recieved correctly + for (i = 0; i < (PARTITIONS * COUNT); i++) + { + assert(message[i] = (i+1)); + } + printf("Test Passed Succesfully\n"); + MPI_Request_free(&request); +} +MPI_Finalize(); +return 0; +} + diff --git a/part-comm/test_nullBuff.c b/part-comm/test_nullBuff.c new file mode 100644 index 0000000..4ab1546 --- /dev/null +++ b/part-comm/test_nullBuff.c @@ -0,0 +1,79 @@ +/*Partitions MPI Unit Test + * + * Shows the behavior of the communication when the buffer is empty + */ + +#include +#include +#include "mpi.h" +#include "assert.h" + +#define PARTITIONS 1 +//Count is set to, buffer is empty, 0 elements send/recv per parition +#define COUNT 0 + +int main (int argc, char *argv[]) +{ +//Buffer message +double message [PARTITIONS * COUNT]; + +//MPI variables declarations +int src = 0, dest = 1, tag = 100, flag = 0, flag2 = 0; +int myrank, provided, len, i, j; +char hostname[MPI_MAX_PROCESSOR_NAME]; +MPI_Count partitions = PARTITIONS; +MPI_Request request; + +//Initializing threaded MPI +MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); +if (provided < MPI_THREAD_SERIALIZED) + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +MPI_Comm_rank(MPI_COMM_WORLD, &myrank); +MPI_Get_processor_name(hostname, &len); + +if (myrank == 0) +{ + MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + //Iterating through each buffer partition, not really filling anything but marking them ready to send + for (i = 0; i < partitions; i++) + { + for (j = (i*COUNT); j < ((i+1)*COUNT); j++) + { + message[j] = j+1; + } + MPI_Pready(i, request); + } + + //Test for overall send operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + MPI_Request_free(&request); +} +else if (myrank == 1) +{ + MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + //Test for overall recieve operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + + //Test the buffer to check that the "message" was recieved correctly + //Should pass nothing == nothing + for (i = 0; i < (PARTITIONS * COUNT); i++) + { + assert(message[i] == (i+1)); + } + printf("Test Passed Succesfully\n"); + MPI_Request_free(&request); +} +MPI_Finalize(); +return 0; +} + diff --git a/part-comm/test_parrived.c b/part-comm/test_parrived.c new file mode 100644 index 0000000..6308ae9 --- /dev/null +++ b/part-comm/test_parrived.c @@ -0,0 +1,106 @@ +/*Partitions MPI Unit Test + * + * Shows the behavior of the communication with the method parrived. + * Parrived checks for partitions as they are sent even before the sent operations is complete. + * Parrived loops trying to find a recieved partitions if it takes too long it timesout. + */ + +#include +#include +#include "mpi.h" +#include "assert.h" +#include "time.h" + +#define PARTITIONS 8 +#define COUNT 5 + +//Set a timeout time in milliseconds as the max time for Parrived to loop. +#define TIMEOUT 10000 + +int main (int argc, char *argv[]) +{ +//Buffer message +double message [PARTITIONS * COUNT]; + +//MPI variables declarations +int src = 0, dest = 1, tag = 100, flag = 0, flag2 = 0, counter = 0 ; +int myrank, provided, len, timer, trigger, i, j; +char hostname[MPI_MAX_PROCESSOR_NAME]; +MPI_Count partitions = PARTITIONS; +MPI_Request request; + +//Initializing threaded MPI +MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); +if (provided < MPI_THREAD_SERIALIZED) + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +MPI_Comm_rank(MPI_COMM_WORLD, &myrank); +MPI_Get_processor_name(hostname, &len); + +if (myrank == 0) +{ + MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + //Iterating through each buffer partition, filling them and marking them ready to send + for (i = 0; i < partitions; i++) + { + for (j = (i*COUNT); j < ((i+1)*COUNT); j++) + { + message[j] = j+1; + } + MPI_Pready(i, request); + } + + //Test for overall send operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + MPI_Request_free(&request); +} +else if (myrank == 1) +{ + MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + //sets a timer in milliseconds equal to the time passed since beginning of operation + timer = clock() * 1000 / CLOCKS_PER_SEC; + //creates a trigger by adding a timeout time in millisecond to the current time passed + trigger = timer + TIMEOUT; + + //Iterates through the partitions and check indefinetly to see if they have arrived + for (i = 0; i < partitions; i++) + { + MPI_Parrived(request, i, &flag2); + if (!flag2) { + i--; + } + else { + //Test the buffer to check that the message was recieved correctly + for (j = (i * COUNT); j < ((i+1) * COUNT); j++) + { + assert(message[j] == (j + 1)); + } + } + //set timer equal to the current time elapsed + timer = clock() * 1000 / CLOCKS_PER_SEC; + //Abort MPI if Parrived loops more than time time allowed + if (timer > trigger){ + printf("Parrived Timeout, No Partitions recieved in %d millisecond", TIMEOUT); + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); + } + } + + //Test for overall recieve operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + + printf("Test Passed Succesfully\n"); + MPI_Request_free(&request); +} +MPI_Finalize(); +return 0; +} + diff --git a/part-comm/test_partComm.c b/part-comm/test_partComm.c new file mode 100644 index 0000000..1447090 --- /dev/null +++ b/part-comm/test_partComm.c @@ -0,0 +1,77 @@ +/*Partitions MPI Unit Test + * + * Shows the behavior of the communication for simple same size partition send/recv + */ + +#include +#include +#include "mpi.h" +#include "assert.h" + +#define PARTITIONS 8 +#define COUNT 5 + +int main (int argc, char *argv[]) +{ +//Buffer Message +double message [PARTITIONS * COUNT]; + +//MPI variables declarations +int src = 0, dest = 1, tag = 100, flag = 0; +int myrank, provided, len, i, j; +char hostname[MPI_MAX_PROCESSOR_NAME]; +MPI_Count partitions = PARTITIONS; +MPI_Request request; + +//Initializing threaded MPI +MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); +if (provided < MPI_THREAD_SERIALIZED) + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +MPI_Comm_rank(MPI_COMM_WORLD, &myrank); +MPI_Get_processor_name(hostname, &len); + +if (myrank == 0) +{ + MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + //Iterating through each buffer partition, filling them and marking them ready to send + for (i = 0; i < partitions; i++) + { + for (j = (i*COUNT); j < ((i+1)*COUNT); j++) + { + message[j] = j+1; + } + MPI_Pready(i, request); + } + + //Test for overall send operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + MPI_Request_free(&request); +} +else if (myrank == 1) +{ + MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + //Test for overall recieve operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + + //Test the buffer to check that the message was recieved correctly + for (i = 0; i < (PARTITIONS * COUNT); i++) + { + assert(message[i] == (i+1)); + } + printf("Test Passed Succesfully\n"); + MPI_Request_free(&request); +} +MPI_Finalize(); +return 0; +} + diff --git a/part-comm/test_preadyError0.c b/part-comm/test_preadyError0.c new file mode 100644 index 0000000..550fcaa --- /dev/null +++ b/part-comm/test_preadyError0.c @@ -0,0 +1,86 @@ +/*Partitions MPI Unit Test + * + * Shows the behavior of the communication when Pready is call on an partition that doesn't exist. + * This action should be erroneous. + */ +/*Partitions MPI Unit Test + * * + * * Shows the behavior of the communication when Pready is call on an already active partition. + * * This action should be erroneous. + * */ + + +#include +#include +#include "mpi.h" +#include "assert.h" + +#define PARTITIONS 8 +#define COUNT 5 + +int main (int argc, char *argv[]) +{ +//Buffer message +double message [PARTITIONS * COUNT]; + +//MPI variable declaration +int src = 0, dest = 1, tag = 100, flag = 0; +int myrank, provided, len, i, j; +char hostname[MPI_MAX_PROCESSOR_NAME]; +MPI_Count partitions = PARTITIONS; +MPI_Request request; + +//Initializing threaded MPI +MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); +if (provided < MPI_THREAD_SERIALIZED) + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +MPI_Comm_rank(MPI_COMM_WORLD, &myrank); +MPI_Get_processor_name(hostname, &len); + +if (myrank == 0) +{ + MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + //Iterating through each buffer partition, filling them and marking them ready to send + for (i = 0; i < partitions; i++) + { + for (j = (i*COUNT); j < ((i+1)*COUNT); j++) + { + message[j] = j+1; + } + MPI_Pready(i, request); + } + //Marking ready partition equal to the number of partitions which doesnt exist. + MPI_Pready(partitions, request); + + //Test for overall send operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + MPI_Request_free(&request); +} +else if (myrank == 1) +{ + MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + //Test for overall recieve operation completion + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + + //Test for overall recieve operation completion + for (i = 0; i < (PARTITIONS * COUNT); i++) + { + assert(message[i] == (i+1)); + } + printf("Test Passed Succesfully\n"); + MPI_Request_free(&request); +} +MPI_Finalize(); +return 0; +} + diff --git a/part-comm/test_preadyError1.c b/part-comm/test_preadyError1.c new file mode 100644 index 0000000..7a49c6e --- /dev/null +++ b/part-comm/test_preadyError1.c @@ -0,0 +1,67 @@ +#include +#include +#include "mpi.h" +#include "assert.h" + +#define PARTITIONS 8 +#define COUNT 5 + +int main (int argc, char *argv[]) +{ +double message [PARTITIONS * COUNT]; +int src = 0, dest = 1, tag = 100, flag = 0, flag2 = 0; +int myrank, provided, len, i, j; +int partitionsList[]; +char hostname[MPI_MAX_PROCESSOR_NAME]; +MPI_Count partitions = PARTITIONS; +MPI_Request request; + +MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); +if (provided < MPI_THREAD_SERIALIZED) + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +MPI_Comm_rank(MPI_COMM_WORLD, &myrank); +MPI_Get_processor_name(hostname, &len); + +if (myrank == 0) +{ + MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + for (i = 0; i < partitions; i++) + { + for (j = (i*COUNT); j < ((i+1)*COUNT); j++) + { + message[j] = j+1; + } + partitionList[i] = i; + MPI_Pready(i, request); + } + MPI_Pready_list(partitions, partitionsList, request); + + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + MPI_Request_free(&request); +} +else if (myrank == 1) +{ + MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + + for (i = 0; i < (PARTITIONS * COUNT); i++) + { + assert(message[i] = (i+1)); + } + printf("Test Passed Succesfully\n"); + MPI_Request_free(&request); +} +MPI_Finalize(); +return 0; +} + diff --git a/part-comm/test_preadyList.c b/part-comm/test_preadyList.c new file mode 100644 index 0000000..a9f00f4 --- /dev/null +++ b/part-comm/test_preadyList.c @@ -0,0 +1,66 @@ +#include +#include +#include "mpi.h" +#include "assert.h" + +#define PARTITIONS 8 +#define COUNT 5 + +int main (int argc, char *argv[]) +{ +double message [PARTITIONS * COUNT]; +int src = 0, dest = 1, tag = 100, flag = 0, flag2 = 0; +int myrank, provided, len, i, j; +int partitionsList[]; +char hostname[MPI_MAX_PROCESSOR_NAME]; +MPI_Count partitions = PARTITIONS; +MPI_Request request; + +MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); +if (provided < MPI_THREAD_SERIALIZED) + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +MPI_Comm_rank(MPI_COMM_WORLD, &myrank); +MPI_Get_processor_name(hostname, &len); + +if (myrank == 0) +{ + MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + for (i = 0; i < partitions; i++) + { + for (j = (i*COUNT); j < ((i+1)*COUNT); j++) + { + message[j] = j+1; + } + partitionList[i] = i; + } + MPI_Pready_list(partitions, partitionsList, request); + + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + MPI_Request_free(&request); +} +else if (myrank == 1) +{ + MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + + for (i = 0; i < (PARTITIONS * COUNT); i++) + { + assert(message[i] = (i+1)); + } + printf("Test Passed Succesfully\n"); + MPI_Request_free(&request); +} +MPI_Finalize(); +return 0; +} + diff --git a/part-comm/test_preadyRange.c b/part-comm/test_preadyRange.c new file mode 100644 index 0000000..9ebd7f7 --- /dev/null +++ b/part-comm/test_preadyRange.c @@ -0,0 +1,75 @@ +#include +#include +#include "mpi.h" +#include "assert.h" + +#define PARTITIONS 8 +#define COUNT 5 + +int main (int argc, char *argv[]) +{ +double message [PARTITIONS * COUNT]; +int src = 0, dest = 1, tag = 100, flag = 0, flag2 = 0; +int myrank, provided, len, i, j; +char hostname[MPI_MAX_PROCESSOR_NAME]; +MPI_Count partitions = PARTITIONS; +MPI_Request request; + +MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); +if (provided < MPI_THREAD_SERIALIZED) + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +MPI_Comm_rank(MPI_COMM_WORLD, &myrank); +MPI_Get_processor_name(hostname, &len); + +if (partitions < 4) +{ + printf("Partitions must be greater or equal to 4, current number of partitions: %d", partitions); + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +} + +if (myrank == 0) +{ + MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + for (i = 0; i < partitions; i++) + { + for (j = (i*COUNT); j < ((i+1)*COUNT); j++) + { + message[j] = j+1; + } + if ( i = ((partitions/2)-1) ){ + MPI_Pready_range(0, ((partitions/2)-1), request); + } + else if ( i = (partitions-1) ){ + MPI_Pready_range((partitions/2), (partitions-1), request); + } + } + + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + MPI_Request_free(&request); +} +else if (myrank == 1) +{ + MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + + for (i = 0; i < (PARTITIONS * COUNT); i++) + { + assert(message[i] = (i+1)); + } + printf("Test Passed Succesfully\n"); + MPI_Request_free(&request); +} +MPI_Finalize(); +return 0; +} + diff --git a/part-comm/test_procNull.c b/part-comm/test_procNull.c new file mode 100644 index 0000000..ac1b311 --- /dev/null +++ b/part-comm/test_procNull.c @@ -0,0 +1,51 @@ +#include +#include +#include "mpi.h" +#include "assert.h" + +#define PARTITIONS 8 +#define COUNT 0 + +int main (int argc, char *argv[]) +{ +double message [PARTITIONS * COUNT]; +int src = MPI_PROC_NULL, dest = MPI_PROC_NULL, tag = 100, flag = 0, flag2 = 0; +int myrank, provided, len, i, j; +char hostname[MPI_MAX_PROCESSOR_NAME]; +MPI_Count partitions = PARTITIONS; +MPI_Request request; + +MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); +if (provided < MPI_THREAD_SERIALIZED) + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +MPI_Comm_rank(MPI_COMM_WORLD, &myrank); +MPI_Get_processor_name(hostname, &len); + +if (myrank == 0) +{ + MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + MPI_Request_free(&request); +} +else if (myrank == 1) +{ + MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + + printf("Test Passed Succesfully\n"); + MPI_Request_free(&request); +} +MPI_Finalize(); +return 0; +} + diff --git a/part-comm/test_startall.c b/part-comm/test_startall.c new file mode 100644 index 0000000..10eceff --- /dev/null +++ b/part-comm/test_startall.c @@ -0,0 +1,77 @@ +#include +#include +#include "mpi.h" +#include "assert.h" + +#define PARTITIONS 8 +#define COUNT 5 + +int main (int argc, char *argv[]) +{ +double numbers [PARTITIONS * COUNT]; +double sum [PARTITIONS * COUNT]; +int src = 0, dest = 1, tag = 100, sumtag = 101, flag = 0, flag2 = 0; +int myrank, provided, len, i, j; +char hostname[MPI_MAX_PROCESSOR_NAME]; +MPI_Count partitions = PARTITIONS; +MPI_Request requests[2]; + +MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); +if (provided < MPI_THREAD_SERIALIZED) + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +MPI_Comm_rank(MPI_COMM_WORLD, &myrank); +MPI_Get_processor_name(hostname, &len); + +if (myrank == 0) +{ + MPI_Psend_init(numbers, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &requests[0]); + MPI_Psend_init(sum, partitions, COUNT, MPI_DOUBLE, dest, sumtag, MPI_COMM_WORLD, MPI_INFO_NULL, &requests[1]); + + MPI_Startall(2, requests); + + for (i = 0; i < partitions; i++) + { + for (j = (i*COUNT); j < ((i+1)*COUNT); j++) + { + numbers[j] = j+1; + sum[j] = numbers[j] + sum[j-1]; + } + MPI_Pready(i, requests[0]); + MPI_Pready(i, requests[1]); + } + + while (!flag || !flag2) + { + MPI_Test(&requests[0], &flag, MPI_STATUS_IGNORE); + MPI_Test(&requests[1], &flag2, MPI_STATUS_IGNORE); + } + MPI_Request_free(&requests[0]); + MPI_Request_free(&requests[1]); +} +else if (myrank == 1) +{ + MPI_Precv_init(numbers, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &requests[0]); + MPI_Precv_init(sum, partitions, COUNT, MPI_DOUBLE, src, sumtag, MPI_COMM_WORLD, MPI_INFO_NULL, &requests[1]); + + MPI_Startall(2, requests); + + while (!flag || !flag2) + { + MPI_Test(&requests[0], &flag, MPI_STATUS_IGNORE); + MPI_Test(&requests[1], &flag2, MPI_STATUS_IGNORE); + } + MPI_Request_free(&requests[0]); + MPI_Request_free(&requests[1]); + + for (i = 0; i < (PARTITIONS * COUNT); i++) + { + assert(numbers[i] = (i+1)); + assert(sum[j] = numbers[j] + sum[j-1]); + } + + printf("Test Passed Succesfully\n"); +} +MPI_Finalize(); +return 0; +} + diff --git a/part-comm/test_upperLimit.c b/part-comm/test_upperLimit.c new file mode 100644 index 0000000..8b9d12a --- /dev/null +++ b/part-comm/test_upperLimit.c @@ -0,0 +1,64 @@ +#include +#include +#include "mpi.h" +#include "assert.h" + +#define PARTITIONS 1 + +int main (int argc, char *argv[]) +{ +char *count = argv[1]; +int COUNT = 1040000 + atoi(count); +double message [PARTITIONS * COUNT]; +int src = 0, dest = 1, tag = 100, flag = 0, flag2 = 0; +int myrank, provided, len, i, j; +char hostname[MPI_MAX_PROCESSOR_NAME]; +MPI_Count partitions = PARTITIONS; +MPI_Request request; + +MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); +if (provided < MPI_THREAD_SERIALIZED) + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +MPI_Comm_rank(MPI_COMM_WORLD, &myrank); +MPI_Get_processor_name(hostname, &len); + +if (myrank == 0) +{ + MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + for (i = 0; i < partitions; i++) + { + for (j = (i*COUNT); j < ((i+1)*COUNT); j++) + { + message[j] = j+1; + } + MPI_Pready(i, request); + } + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + MPI_Request_free(&request); +} +else if (myrank == 1) +{ + MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + + for (i = 0; i < (PARTITIONS * COUNT); i++) + { + assert(message[i] = (i+1)); + } + printf("\n Test %d Passed Succesfully\n", COUNT); + MPI_Request_free(&request); +} +MPI_Finalize(); +return 0; +} + diff --git a/part-comm/test_wildcardsError.c b/part-comm/test_wildcardsError.c new file mode 100644 index 0000000..1ddf4f4 --- /dev/null +++ b/part-comm/test_wildcardsError.c @@ -0,0 +1,63 @@ +#include +#include +#include "mpi.h" +#include "assert.h" + +#define PARTITIONS 8 +#define COUNT 5 + +int main (int argc, char *argv[]) +{ +double message [PARTITIONS * COUNT]; +int src = 0, dest = 1, tag = 100, flag = 0, flag2 = 0; +int myrank, provided, len, i, j; +char hostname[MPI_MAX_PROCESSOR_NAME]; +MPI_Count partitions = PARTITIONS; +MPI_Request request; + +MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); +if (provided < MPI_THREAD_SERIALIZED) + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); +MPI_Comm_rank(MPI_COMM_WORLD, &myrank); +MPI_Get_processor_name(hostname, &len); + +if (myrank == 0) +{ + MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + for (i = 0; i < partitions; i++) + { + for (j = (i*COUNT); j < ((i+1)*COUNT); j++) + { + message[j] = j+1; + } + MPI_Pready(i, request); + } + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + MPI_Request_free(&request); +} +else if (myrank == 1) +{ + MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&request); + + while (!flag) + { + MPI_Test(&request, &flag, MPI_STATUS_IGNORE); + } + + for (i = 0; i < (PARTITIONS * COUNT); i++) + { + assert(message[i] = (i+1)); + } + printf("Test Passed Succesfully\n"); + MPI_Request_free(&request); +} +MPI_Finalize(); +return 0; +} +