diff --git a/part-comm/README.md b/part-comm/README.md new file mode 100644 index 0000000..99bef13 --- /dev/null +++ b/part-comm/README.md @@ -0,0 +1,5 @@ +Partition Communication Unit Test + +Test suite for testing different routines, error cases and behavior for Point to Point partition communication + +Adriel Poo Armas diff --git a/part-comm/test_commOrder0.c b/part-comm/test_commOrder0.c new file mode 100644 index 0000000..ac57bca --- /dev/null +++ b/part-comm/test_commOrder0.c @@ -0,0 +1,82 @@ +/*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, i, j; +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); + +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..bad6610 --- /dev/null +++ b/part-comm/test_commOrder1.c @@ -0,0 +1,83 @@ +/*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; +int myrank, provided, i, j; +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); + +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..3780748 --- /dev/null +++ b/part-comm/test_commOrder2.c @@ -0,0 +1,83 @@ +/*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, i, j; +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); + +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..0838e27 --- /dev/null +++ b/part-comm/test_commOrder3.c @@ -0,0 +1,110 @@ +/*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, timer, trigger, i, j; +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); + +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..07023ac --- /dev/null +++ b/part-comm/test_negPartError.c @@ -0,0 +1,78 @@ +/*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, 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, 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..4196c94 --- /dev/null +++ b/part-comm/test_nullBuff.c @@ -0,0 +1,77 @@ +/*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, i, j; +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); + +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..3c41570 --- /dev/null +++ b/part-comm/test_parrived.c @@ -0,0 +1,104 @@ +/*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, timer, trigger, i, j; +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); + +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..98ab17e --- /dev/null +++ b/part-comm/test_partComm.c @@ -0,0 +1,75 @@ +/*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, i, j; +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); + +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..907e308 --- /dev/null +++ b/part-comm/test_preadyError0.c @@ -0,0 +1,78 @@ +/*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. + */ + +#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, i, j; +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); + +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..c3da3c6 --- /dev/null +++ b/part-comm/test_preadyError1.c @@ -0,0 +1,84 @@ +/*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]; + +//Defining an array of partitions +int partitionsList[8]; + +//MPI varaibles declarations +int src = 0, dest = 1, tag = 100, flag = 0; +int myrank, provided, i, j; +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); + +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; + } + partitionsList[i] = i; + MPI_Pready(i, request); + } + + //Mark ready all of the partitions, which are already declared ready/active + MPI_Pready_list(partitions, partitionsList, 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_preadyList.c b/part-comm/test_preadyList.c new file mode 100644 index 0000000..997817d --- /dev/null +++ b/part-comm/test_preadyList.c @@ -0,0 +1,81 @@ +/*Partitions MPI Unit Test + * + * Shows the behavior of the communication when Pready_list is called and all the are set ready randomly. + */ + +#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]; + +//Defining an array of partitions +int partitionsList[8]; + +//MPI variables declarations +int src = 0, dest = 1, tag = 100, flag = 0; +int myrank, provided, i, j; +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); + +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 and filling them + for (i = 0; i < partitions; i++) + { + for (j = (i*COUNT); j < ((i+1)*COUNT); j++) + { + message[j] = j+1; + } + //Adding partitions to a partition array + partitionsList[i] = i; + } + //Marking partitions ready + MPI_Pready_list(partitions, partitionsList, 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_preadyRange.c b/part-comm/test_preadyRange.c new file mode 100644 index 0000000..51acaa1 --- /dev/null +++ b/part-comm/test_preadyRange.c @@ -0,0 +1,89 @@ +/*Partitions MPI Unit Test + * + * Shows the behavior of the communication when partitions are marked ready through Pready_range. + */ + +#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, i, j; +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); + +//For this test 4 or more partitions are necessary +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); + + //Iterating through each buffer partition and filling them + for (i = 0; i < partitions; i++) + { + for (j = (i*COUNT); j < ((i+1)*COUNT); j++) + { + message[j] = j+1; + } + //Marks the first half of partitions reday to send + if ( i = ((partitions/2)-1) ){ + MPI_Pready_range(0, ((partitions/2)-1), request); + } + //Marks the second half of partitions ready to send + else if ( i = (partitions-1) ){ + MPI_Pready_range((partitions/2), (partitions-1), 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_procNull.c b/part-comm/test_procNull.c new file mode 100644 index 0000000..62e6ae1 --- /dev/null +++ b/part-comm/test_procNull.c @@ -0,0 +1,60 @@ +/*Partitions MPI Unit Test + * + * Shows the behavior of the communication when using a null process + */ + +#include +#include +#include "mpi.h" +#include "assert.h" + +#define PARTITIONS 8 +#define COUNT 0 + +int main (int argc, char *argv[]) +{ +//Buffer message +double message [PARTITIONS * COUNT]; + +//MPI variables declarations +//Source and destinations are declared as null +int src = MPI_PROC_NULL, dest = MPI_PROC_NULL, tag = 100, flag = 0, flag2 = 0; +int myrank, provided; +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); + +if (myrank == 0) +{ + MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request); + MPI_Start(&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); + } + + 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..964c8b3 --- /dev/null +++ b/part-comm/test_startall.c @@ -0,0 +1,89 @@ +/*Partitions MPI Unit Test + * + * Shows the behavior of the communication with 2 send / recv corridors initialied. + */ + +#include +#include +#include "mpi.h" +#include "assert.h" + +#define PARTITIONS 8 +#define COUNT 5 + +int main (int argc, char *argv[]) +{ +//Buffer messages +double numbers [PARTITIONS * COUNT]; +double sum [PARTITIONS * COUNT]; + +//MPI variables declarations +int src = 0, dest = 1, tag = 100, sumtag = 101, flag = 0, flag2 = 0; +int myrank, provided, i, j; + +MPI_Count partitions = PARTITIONS; +MPI_Request requests[2]; + +//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(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); + + //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++) + { + numbers[j] = j+1; + sum[j] = numbers[j] + sum[j-1]; + } + MPI_Pready(i, requests[0]); + MPI_Pready(i, requests[1]); + } + + //Test for overall send operation completion + 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); + + //Test for overall send operation completion + 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]); + + //Test the buffer to check that the message was recieved correctly + 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_wildcardsError.c b/part-comm/test_wildcardsError.c new file mode 100644 index 0000000..fb7571e --- /dev/null +++ b/part-comm/test_wildcardsError.c @@ -0,0 +1,77 @@ +/*Partitions MPI Unit Test + * + * Shows the behavior of the communication when using wildcard for recv side source and tag. + * 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 variables declarations +int src = 0, dest = 1, tag = 100, flag = 0; +int myrank, provided, i, j; +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); + +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, MPI_ANY_SOURCE, MPI_ANY_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; +} +