Skip to content

Commit 5940bf3

Browse files
author
Adriel Poo-Armas
committed
Initial part comm tests
1 parent dcc6ec7 commit 5940bf3

19 files changed

+1413
-0
lines changed

part-comm/.test_commOrder3.c.swp

12 KB
Binary file not shown.

part-comm/test.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include "mpi.h"
4+
#define PARTITIONS 8
5+
#define COUNT 4
6+
7+
int main (int argc, char *argv[])
8+
{
9+
double message [PARTITIONS * COUNT];
10+
int src = 0, dest = 1, tag = 100, flag = 0, flag2 = 0;
11+
int send_partitions = PARTITIONS,
12+
send_partlength = COUNT,
13+
recv_partitions = PARTITIONS/2,
14+
recv_partlength = COUNT*2;
15+
int myrank, provided, i, j;
16+
MPI_Request request;
17+
18+
MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided);
19+
if (provided < MPI_THREAD_SERIALIZED)
20+
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
21+
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
22+
23+
if (myrank == 0)
24+
{
25+
MPI_Psend_init(message, send_partitions, send_partlength, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request);
26+
MPI_Start(&request);
27+
28+
for (i = 0; i < send_partitions; i++)
29+
{
30+
printf("Partition %d Ready to Send, Send Buff: ", i);
31+
for (j = (i*send_partlength); j < ((i+1)*send_partlength); j++)
32+
{
33+
message[j] = j+1;
34+
printf(" %.2lf, ", message[j]);
35+
}
36+
printf("\n");
37+
MPI_Pready(i, request);
38+
39+
}
40+
while (!flag)
41+
{
42+
MPI_Test(&request, &flag, MPI_STATUS_IGNORE);
43+
}
44+
MPI_Request_free(&request);
45+
}
46+
else if (myrank == 1)
47+
{
48+
MPI_Precv_init(message, recv_partitions, recv_partlength, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request);
49+
MPI_Start(&request);
50+
51+
for (i = 0; i < recv_partitions; i++)
52+
{
53+
MPI_Parrived(request, i, &flag2);
54+
if (!flag2) {
55+
i--;
56+
}
57+
else {
58+
printf("Partition %d Recieved Buff: ", i);
59+
for (j = (i*recv_partlength); j < ((i+1)*recv_partlength); j++)
60+
{
61+
printf(" %.2lf, ", message[j]);
62+
}
63+
printf("\n");
64+
}
65+
}
66+
while (!flag)
67+
{
68+
MPI_Test(&request, &flag, MPI_STATUS_IGNORE);
69+
}
70+
MPI_Request_free(&request);
71+
}
72+
MPI_Finalize();
73+
return 0;
74+
}

part-comm/test_commOrder0.c

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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, len, i, j;
23+
char hostname[MPI_MAX_PROCESSOR_NAME];
24+
MPI_Count partitions = PARTITIONS;
25+
MPI_Request request;
26+
27+
//Initializing threaded MPI
28+
MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided);
29+
if (provided < MPI_THREAD_SERIALIZED)
30+
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
31+
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
32+
MPI_Get_processor_name(hostname, &len);
33+
34+
if (myrank == 0)
35+
{
36+
//This Barrier prevents task 0 to run before the partitioned recieve is initialized in task 1
37+
MPI_Barrier(MPI_COMM_WORLD);
38+
39+
MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request);
40+
MPI_Start(&request);
41+
42+
//Iterating through each buffer partition, filling them and marking them ready to send
43+
for (i = 0; i < partitions; i++)
44+
{
45+
for (j = (i*COUNT); j < ((i+1)*COUNT); j++)
46+
{
47+
message[j] = j+1;
48+
}
49+
MPI_Pready(i, request);
50+
}
51+
52+
//Test for overall send operation completion
53+
while (!flag)
54+
{
55+
MPI_Test(&request, &flag, MPI_STATUS_IGNORE);
56+
}
57+
MPI_Request_free(&request);
58+
}
59+
else if (myrank == 1)
60+
{
61+
MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request);
62+
MPI_Start(&request);
63+
64+
//This Barrier allows task 0 to proceed
65+
MPI_Barrier(MPI_COMM_WORLD);
66+
67+
//Test for overall recieve operation completion
68+
while (!flag)
69+
{
70+
MPI_Test(&request, &flag, MPI_STATUS_IGNORE);
71+
}
72+
73+
//Test the buffer to check that the message was recieved correctly
74+
for (i = 0; i < (PARTITIONS * COUNT); i++)
75+
{
76+
assert(message[i] = (i+1));
77+
}
78+
printf("Test Passed Succesfully\n");
79+
MPI_Request_free(&request);
80+
}
81+
MPI_Finalize();
82+
return 0;
83+
}
84+

part-comm/test_commOrder1.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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, flag2 = 0;
22+
int myrank, provided, len, i, j;
23+
char hostname[MPI_MAX_PROCESSOR_NAME];
24+
MPI_Count partitions = PARTITIONS;
25+
MPI_Request request;
26+
27+
//Initializing threaded MPI
28+
MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided);
29+
if (provided < MPI_THREAD_SERIALIZED)
30+
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
31+
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
32+
MPI_Get_processor_name(hostname, &len);
33+
34+
if (myrank == 0)
35+
{
36+
MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request);
37+
MPI_Start(&request);
38+
39+
//Iterating through each buffer partition, filling them and marking them ready to send
40+
for (i = 0; i < partitions; i++)
41+
{
42+
for (j = (i*COUNT); j < ((i+1)*COUNT); j++)
43+
{
44+
message[j] = j+1;
45+
}
46+
MPI_Pready(i, request);
47+
}
48+
49+
//Test for overall send operation completion
50+
while (!flag)
51+
{
52+
MPI_Test(&request, &flag, MPI_STATUS_IGNORE);
53+
}
54+
55+
//This Barrier allows task 1 to proceed
56+
MPI_Barrier(MPI_COMM_WORLD);
57+
58+
MPI_Request_free(&request);
59+
}
60+
else if (myrank == 1)
61+
{
62+
//This Barrier prevents the task 1 to run before the partitioned send completes
63+
MPI_Barrier(MPI_COMM_WORLD);
64+
65+
MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request);
66+
MPI_Start(&request);
67+
68+
//Test for overall recieve operation completion
69+
while (!flag)
70+
{
71+
MPI_Test(&request, &flag, MPI_STATUS_IGNORE);
72+
}
73+
74+
//Test the buffer to check that the message was recieved correctly
75+
for (i = 0; i < (PARTITIONS * COUNT); i++)
76+
{
77+
assert(message[i] == (i+1));
78+
}
79+
printf("Test Passed Succesfully\n");
80+
MPI_Request_free(&request);
81+
}
82+
MPI_Finalize();
83+
return 0;
84+
}
85+

part-comm/test_commOrder2.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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, len, i, j;
23+
char hostname[MPI_MAX_PROCESSOR_NAME];
24+
MPI_Count partitions = PARTITIONS;
25+
MPI_Request request;
26+
27+
//Initializing threaded MPI
28+
MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided);
29+
if (provided < MPI_THREAD_SERIALIZED)
30+
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
31+
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
32+
MPI_Get_processor_name(hostname, &len);
33+
34+
if (myrank == 0)
35+
{
36+
MPI_Psend_init(message, partitions, COUNT, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request);
37+
38+
MPI_Start(&request);
39+
40+
//This Barrier ensures that a send/recv is establish before proceeding
41+
MPI_Barrier(MPI_COMM_WORLD);
42+
43+
//Iterating through each buffer partition, filling them and marking them ready to send
44+
for (i = 0; i < partitions; i++)
45+
{
46+
for (j = (i*COUNT); j < ((i+1)*COUNT); j++)
47+
{
48+
message[j] = j+1;
49+
}
50+
MPI_Pready(i, request);
51+
}
52+
53+
//Test for overall send operation completion
54+
while (!flag)
55+
{
56+
MPI_Test(&request, &flag, MPI_STATUS_IGNORE);
57+
}
58+
MPI_Request_free(&request);
59+
}
60+
else if (myrank == 1)
61+
{
62+
MPI_Precv_init(message, partitions, COUNT, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_INFO_NULL, &request);
63+
MPI_Start(&request);
64+
65+
//This Barrier ensures that a send/recv is establish before proceeding
66+
MPI_Barrier(MPI_COMM_WORLD);
67+
68+
//Test for overall recieve operation completion
69+
while (!flag)
70+
{
71+
MPI_Test(&request, &flag, MPI_STATUS_IGNORE);
72+
}
73+
74+
//Test the buffer to check that the message was recieved correctly
75+
for (i = 0; i < (PARTITIONS * COUNT); i++)
76+
{
77+
assert(message[i] == (i+1));
78+
}
79+
printf("Test Passed Succesfully\n");
80+
MPI_Request_free(&request);
81+
}
82+
MPI_Finalize();
83+
return 0;
84+
}
85+

0 commit comments

Comments
 (0)