Skip to content

Commit 80bc444

Browse files
Adriel Poo-Armasadrielpoo
Adriel Poo-Armas
authored andcommitted
Initial part comm tests
Initial part comm test Initial part comm test Initial part comm test Update README.md Update README.md Part Comm Unit Test Signed-off-by: Adriel Poo Armas <[email protected]>
1 parent dcc6ec7 commit 80bc444

17 files changed

+1337
-0
lines changed

part-comm/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Partition Communication Unit Test
2+
3+
Test suite for testing different routines, error cases and behavior for Point to Point partition communication
4+
5+
Adriel Poo Armas

part-comm/test_commOrder0.c

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*Partitions MPI Unit Test
2+
*
3+
* Shows the behavior of the communication when a partitioned recieve call is initialized
4+
* before a partitioned send is declared
5+
* */
6+
7+
#include <stdio.h>
8+
#include <stdlib.h>
9+
#include "mpi.h"
10+
#include "assert.h"
11+
12+
#define PARTITIONS 8
13+
#define COUNT 5
14+
15+
int main (int argc, char *argv[])
16+
{
17+
//Buffer message
18+
double message [PARTITIONS * COUNT];
19+
20+
//MPI variable declarations
21+
int src = 0, dest = 1, tag = 100, flag = 0;
22+
int myrank, provided, i, j;
23+
MPI_Count partitions = PARTITIONS;
24+
MPI_Request request;
25+
26+
//Initializing threaded MPI
27+
MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided);
28+
if (provided < MPI_THREAD_SERIALIZED)
29+
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
30+
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
31+
32+
if (myrank == 0)
33+
{
34+
//This Barrier prevents task 0 to run before the partitioned recieve is initialized in task 1
35+
MPI_Barrier(MPI_COMM_WORLD);
36+
37+
MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request);
38+
MPI_Start(&request);
39+
40+
//Iterating through each buffer partition, filling them and marking them ready to send
41+
for (i = 0; i < partitions; i++)
42+
{
43+
for (j = (i*COUNT); j < ((i+1)*COUNT); j++)
44+
{
45+
message[j] = j+1;
46+
}
47+
MPI_Pready(i, request);
48+
}
49+
50+
//Test for overall send operation completion
51+
while (!flag)
52+
{
53+
MPI_Test(&request, &flag, MPI_STATUS_IGNORE);
54+
}
55+
MPI_Request_free(&request);
56+
}
57+
else if (myrank == 1)
58+
{
59+
MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request);
60+
MPI_Start(&request);
61+
62+
//This Barrier allows task 0 to proceed
63+
MPI_Barrier(MPI_COMM_WORLD);
64+
65+
//Test for overall recieve operation completion
66+
while (!flag)
67+
{
68+
MPI_Test(&request, &flag, MPI_STATUS_IGNORE);
69+
}
70+
71+
//Test the buffer to check that the message was recieved correctly
72+
for (i = 0; i < (PARTITIONS * COUNT); i++)
73+
{
74+
assert(message[i] = (i+1));
75+
}
76+
printf("Test Passed Succesfully\n");
77+
MPI_Request_free(&request);
78+
}
79+
MPI_Finalize();
80+
return 0;
81+
}
82+

part-comm/test_commOrder1.c

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*Partitions MPI Unit Test
2+
*
3+
* Shows the behavior of the communicattion when a partitioned send call completes
4+
* before a partitioned recieve call is declared
5+
*/
6+
7+
#include <stdio.h>
8+
#include <stdlib.h>
9+
#include "mpi.h"
10+
#include "assert.h"
11+
12+
#define PARTITIONS 8
13+
#define COUNT 5
14+
15+
int main (int argc, char *argv[])
16+
{
17+
//Buffer message
18+
double message [PARTITIONS * COUNT];
19+
20+
//MPI variable declaration
21+
int src = 0, dest = 1, tag = 100, flag = 0;
22+
int myrank, provided, i, j;
23+
MPI_Count partitions = PARTITIONS;
24+
MPI_Request request;
25+
26+
//Initializing threaded MPI
27+
MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided);
28+
if (provided < MPI_THREAD_SERIALIZED)
29+
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
30+
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
31+
32+
if (myrank == 0)
33+
{
34+
MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request);
35+
MPI_Start(&request);
36+
37+
//Iterating through each buffer partition, filling them and marking them ready to send
38+
for (i = 0; i < partitions; i++)
39+
{
40+
for (j = (i*COUNT); j < ((i+1)*COUNT); j++)
41+
{
42+
message[j] = j+1;
43+
}
44+
MPI_Pready(i, request);
45+
}
46+
47+
//Test for overall send operation completion
48+
while (!flag)
49+
{
50+
MPI_Test(&request, &flag, MPI_STATUS_IGNORE);
51+
}
52+
53+
//This Barrier allows task 1 to proceed
54+
MPI_Barrier(MPI_COMM_WORLD);
55+
56+
MPI_Request_free(&request);
57+
}
58+
else if (myrank == 1)
59+
{
60+
//This Barrier prevents the task 1 to run before the partitioned send completes
61+
MPI_Barrier(MPI_COMM_WORLD);
62+
63+
MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request);
64+
MPI_Start(&request);
65+
66+
//Test for overall recieve operation completion
67+
while (!flag)
68+
{
69+
MPI_Test(&request, &flag, MPI_STATUS_IGNORE);
70+
}
71+
72+
//Test the buffer to check that the message was recieved correctly
73+
for (i = 0; i < (PARTITIONS * COUNT); i++)
74+
{
75+
assert(message[i] == (i+1));
76+
}
77+
printf("Test Passed Succesfully\n");
78+
MPI_Request_free(&request);
79+
}
80+
MPI_Finalize();
81+
return 0;
82+
}
83+

part-comm/test_commOrder2.c

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*Partitions MPI Unit Test
2+
*
3+
* Shows the behavior of the communication when a send / recv partitioned corridor
4+
* is created and initialized before operations starts.
5+
*/
6+
7+
#include <stdio.h>
8+
#include <stdlib.h>
9+
#include "mpi.h"
10+
#include "assert.h"
11+
12+
#define PARTITIONS 8
13+
#define COUNT 5
14+
15+
int main (int argc, char *argv[])
16+
{
17+
//Buffer message
18+
double message [PARTITIONS * COUNT];
19+
20+
//MPI variables declaration
21+
int src = 0, dest = 1, tag = 100, flag = 0, flag2 = 0;
22+
int myrank, provided, i, j;
23+
MPI_Count partitions = PARTITIONS;
24+
MPI_Request request;
25+
26+
//Initializing threaded MPI
27+
MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided);
28+
if (provided < MPI_THREAD_SERIALIZED)
29+
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
30+
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
31+
32+
if (myrank == 0)
33+
{
34+
MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request);
35+
36+
MPI_Start(&request);
37+
38+
//This Barrier ensures that a send/recv is establish before proceeding
39+
MPI_Barrier(MPI_COMM_WORLD);
40+
41+
//Iterating through each buffer partition, filling them and marking them ready to send
42+
for (i = 0; i < partitions; i++)
43+
{
44+
for (j = (i*COUNT); j < ((i+1)*COUNT); j++)
45+
{
46+
message[j] = j+1;
47+
}
48+
MPI_Pready(i, request);
49+
}
50+
51+
//Test for overall send operation completion
52+
while (!flag)
53+
{
54+
MPI_Test(&request, &flag, MPI_STATUS_IGNORE);
55+
}
56+
MPI_Request_free(&request);
57+
}
58+
else if (myrank == 1)
59+
{
60+
MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request);
61+
MPI_Start(&request);
62+
63+
//This Barrier ensures that a send/recv is establish before proceeding
64+
MPI_Barrier(MPI_COMM_WORLD);
65+
66+
//Test for overall recieve operation completion
67+
while (!flag)
68+
{
69+
MPI_Test(&request, &flag, MPI_STATUS_IGNORE);
70+
}
71+
72+
//Test the buffer to check that the message was recieved correctly
73+
for (i = 0; i < (PARTITIONS * COUNT); i++)
74+
{
75+
assert(message[i] == (i+1));
76+
}
77+
printf("Test Passed Succesfully\n");
78+
MPI_Request_free(&request);
79+
}
80+
MPI_Finalize();
81+
return 0;
82+
}
83+

part-comm/test_commOrder3.c

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*Partitions MPI Unit Test
2+
*
3+
* Shows the behavior of the communication when a partitioned recv / send corridor is declared.
4+
* Parrived loops trying to find a recieved partition before any are sent and fails.
5+
* Parrived should timeout.
6+
*/
7+
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
#include "mpi.h"
11+
#include "assert.h"
12+
#include "time.h"
13+
14+
#define PARTITIONS 8
15+
#define COUNT 5
16+
#define TIMEOUT 10000
17+
18+
int main (int argc, char *argv[])
19+
{
20+
//Buffer message
21+
double message [PARTITIONS * COUNT];
22+
23+
//MPI variables declarations
24+
int src = 0, dest = 1, tag = 100, flag = 0, flag2 = 0;
25+
int myrank, provided, timer, trigger, i, j;
26+
MPI_Count partitions = PARTITIONS;
27+
MPI_Request request;
28+
29+
//Initializing threaded MPI
30+
MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided);
31+
if (provided < MPI_THREAD_SERIALIZED)
32+
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
33+
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
34+
35+
if (myrank == 0)
36+
{
37+
MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request);
38+
39+
//This Barrier prevents task 0 to initialize a send operation before task 0 loops through Parrived
40+
41+
MPI_Barrier(MPI_COMM_WORLD);
42+
43+
MPI_Start(&request);
44+
45+
//Iterating through each buffer partition, filling them and marking them ready to send
46+
for (i = 0; i < partitions; i++)
47+
{
48+
for (j = (i*COUNT); j < ((i+1)*COUNT); j++)
49+
{
50+
message[j] = j+1;
51+
}
52+
MPI_Pready(i, request);
53+
}
54+
55+
//Test for overall send operation completion
56+
while (!flag)
57+
{
58+
MPI_Test(&request, &flag, MPI_STATUS_IGNORE);
59+
}
60+
MPI_Request_free(&request);
61+
}
62+
else if (myrank == 1)
63+
{
64+
MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request);
65+
MPI_Start(&request);
66+
67+
//sets a timer in milliseconds equal to the time passed since beginning of operation
68+
timer = clock() * 1000 / CLOCKS_PER_SEC;
69+
//creates a trigger by adding a timeout time in millisecond to the current time passed
70+
trigger = timer + TIMEOUT;
71+
72+
//Iterates through the partitions and check indefinetly to see if they have arrived
73+
for (i = 0; i < partitions; i++)
74+
{
75+
MPI_Parrived(request, i, &flag2);
76+
if (!flag2) {
77+
i--;
78+
}
79+
else {
80+
//Test the buffer to check that the message was recieved correctly
81+
for (j = (i * COUNT); j < ((i+1) * COUNT); j++)
82+
{
83+
assert(message[j] == (j + 1));
84+
}
85+
}
86+
//set timer equal to the current time elapsed
87+
timer = clock() * 1000 / CLOCKS_PER_SEC;
88+
//Abort MPI if Parrived loops more than time time allowed
89+
if (timer > trigger){
90+
printf("Parrived Timeout, No Partitions recieved in %d millisecond", TIMEOUT);
91+
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
92+
}
93+
}
94+
95+
//This barrier allows task 0 to proceed
96+
MPI_Barrier(MPI_COMM_WORLD);
97+
98+
//Test for overall recieve operation completion
99+
while (!flag)
100+
{
101+
MPI_Test(&request, &flag, MPI_STATUS_IGNORE);
102+
}
103+
104+
printf("Test Passed Succesfully\n");
105+
MPI_Request_free(&request);
106+
}
107+
MPI_Finalize();
108+
return 0;
109+
}
110+

0 commit comments

Comments
 (0)