-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
81 lines (64 loc) · 2.6 KB
/
Copy pathmain.c
File metadata and controls
81 lines (64 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <stdio.h>
#include <unistd.h>
#include "C:\Program Files (x86)\Microsoft SDKs\MPI\Include\mpi.h"
int main(int argc, char* argv[]) {
MPI_Init(&argc, &argv);
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
// Define message sizes (in bytes) to test
int message_sizes[] = {1024, 2048, 4096, 8192};
int num_sizes = sizeof(message_sizes) / sizeof(message_sizes[0]);
int num_iterations = 100; // Number of iterations for stable results
for (int i = 0; i < num_sizes; i++) {
int msg_size = message_sizes[i];
double total_time = 0.0;
// Create message buffer
char* data = (char*)malloc(msg_size);
// Non-blocking send test
if (rank == 0) {
double start_time, end_time;
MPI_Request request;
for (int iter = 0; iter < num_iterations; iter++) {
start_time = MPI_Wtime();
MPI_Isend(data, msg_size, MPI_BYTE, 1, 0, MPI_COMM_WORLD, &request);
MPI_Wait(&request, MPI_STATUS_IGNORE);
end_time = MPI_Wtime();
total_time += (end_time - start_time);
}
} else if (rank == 1) {
for (int iter = 0; iter < num_iterations; iter++) {
MPI_Recv(data, msg_size, MPI_BYTE, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
}
}
// Calculate bandwidth in Mbps
double bandwidth = (msg_size * num_iterations * 8.0) / (total_time * 1e6);
if (rank == 0) {
printf("Message size: %d bytes | Bandwidth (Non-blocking Send): %lf Mbps\n", msg_size, bandwidth);
}
// Reset time
total_time = 0.0;
// Blocking send test
if (rank == 0) {
double start_time, end_time;
for (int iter = 0; iter < num_iterations; iter++) {
start_time = MPI_Wtime();
MPI_Send(data, msg_size, MPI_BYTE, 1, 0, MPI_COMM_WORLD);
end_time = MPI_Wtime();
total_time += (end_time - start_time);
}
} else if (rank == 1) {
for (int iter = 0; iter < num_iterations; iter++) {
MPI_Recv(data, msg_size, MPI_BYTE, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
}
}
// Calculate bandwidth in Mbps
bandwidth = (msg_size * num_iterations * 8.0) / (total_time * 1e6);
if (rank == 0) {
printf("Message size: %d bytes | Bandwidth (Blocking Send): %lf Mbps\n", msg_size, bandwidth);
}
free(data);
}
MPI_Finalize();
return 0;
}