Skip to content

Commit

Permalink
Initial part comm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriel Poo-Armas committed Aug 9, 2023
1 parent dcc6ec7 commit 5940bf3
Show file tree
Hide file tree
Showing 19 changed files with 1,413 additions and 0 deletions.
Binary file added part-comm/.test_commOrder3.c.swp
Binary file not shown.
74 changes: 74 additions & 0 deletions part-comm/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include <stdio.h>
#include <stdlib.h>
#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;
}
84 changes: 84 additions & 0 deletions part-comm/test_commOrder0.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <stdlib.h>
#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;
}

85 changes: 85 additions & 0 deletions part-comm/test_commOrder1.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <stdlib.h>
#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;
}

85 changes: 85 additions & 0 deletions part-comm/test_commOrder2.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <stdlib.h>
#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;
}

Loading

0 comments on commit 5940bf3

Please sign in to comment.