-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_isend.c
More file actions
158 lines (133 loc) · 4.79 KB
/
Copy pathmulti_isend.c
File metadata and controls
158 lines (133 loc) · 4.79 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <cuda_runtime.h>
#include <cuda.h>
#include <stdint.h>
int main(int argc, char **argv)
{
MPI_Comm comm;
MPI_Status status;
MPI_Request request[50];
MPI_Status req_status[50];
int length;
int iter;
int nb_send;
int c;
opterr = 0;
int root = 0;
int dest = 1;
int i, j;
int ierr;
int tag = 0;
char *buffer_cuda = NULL;
double t1, t2;
// Initialize the MPI environment
MPI_Init(NULL, NULL);
// Get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
// Get the rank of the process
int my_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
// Get the name of the processor
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name, &name_len);
length = 1000000;
iter = 10;
nb_send = 10;
while ((c = getopt (argc, argv, "s:i:m:")) != -1) {
switch (c) {
case 's':
length = atoi(optarg);
break;
case 'i':
iter = atoi(optarg);
break;
case 'm':
nb_send = atoi(optarg);
break;
case '?':
if (optopt == 's' || optopt == 'i' || optopt == 'm')
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
else if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf (stderr,"Unknown option character `\\x%x'.\n", optopt);
exit(1);
default:
exit(1);
}
}
printf("Hello world from processor %s, rank %d"
" out of %d processors, length %d, iter %d, nb_send %d\n",
processor_name, my_rank, world_size, length, iter, nb_send);
cudaSetDevice(my_rank);
cudaMalloc((void **)&buffer_cuda, sizeof(char)*length*nb_send);
if (my_rank == root) {
/* warm up */
ierr = MPI_Send(buffer_cuda, length, MPI_CHAR, dest, tag, MPI_COMM_WORLD);
if (ierr != MPI_SUCCESS) {
printf("MPI_Send() returned %d", ierr);
}
ierr = MPI_Recv(buffer_cuda, length, MPI_CHAR, dest, tag, MPI_COMM_WORLD, &status);
if (ierr != MPI_SUCCESS) {
printf("MPI_Recv() returned %d", ierr);
}
MPI_Barrier(MPI_COMM_WORLD);
t1 = MPI_Wtime();
for (i = 0; i < iter; i++) {
for (j = 0; j < nb_send; j++) {
ierr = MPI_Isend(buffer_cuda + j * length, length, MPI_CHAR, dest, tag, MPI_COMM_WORLD, &request[j]);
if (ierr != MPI_SUCCESS) {
printf("MPI_Isend() returned %d", ierr);
}
}
MPI_Waitall(nb_send, request, req_status);
for (j = 0; j < nb_send; j++) {
ierr = MPI_Irecv(buffer_cuda + j * length, length, MPI_CHAR, dest, tag, MPI_COMM_WORLD, &request[j]);
if (ierr != MPI_SUCCESS) {
printf("MPI_Isend() returned %d", ierr);
}
}
MPI_Waitall(nb_send, request, req_status);
}
t2 = MPI_Wtime();
printf("root each send&recv time %fs, BW %f GB/s\n", (t2-t1)*1e6/iter/nb_send, length*sizeof(char)/1.0E9/(t2-t1)*iter*nb_send*2);
} else {
/* warm up */
ierr = MPI_Recv(buffer_cuda, length, MPI_CHAR, root, tag, MPI_COMM_WORLD, &status);
if (ierr != MPI_SUCCESS) {
printf("MPI_Recv() returned %d", ierr);
}
ierr = MPI_Send(buffer_cuda, length, MPI_CHAR, root, tag, MPI_COMM_WORLD);
if (ierr != MPI_SUCCESS) {
printf("MPI_Send() returned %d", ierr);
}
MPI_Barrier(MPI_COMM_WORLD);
for (i = 0; i < iter; i++) {
for (j = 0; j < nb_send; j++) {
ierr = MPI_Irecv(buffer_cuda + j * length, length, MPI_CHAR, root, tag, MPI_COMM_WORLD, &request[j]);
if (ierr != MPI_SUCCESS) {
printf("MPI_Isend() returned %d", ierr);
}
}
MPI_Waitall(nb_send, request, req_status);
for (j = 0; j < nb_send; j++) {
ierr = MPI_Isend(buffer_cuda + j * length, length, MPI_CHAR, root, tag, MPI_COMM_WORLD, &request[j]);
if (ierr != MPI_SUCCESS) {
printf("MPI_Isend() returned %d", ierr);
}
}
MPI_Waitall(nb_send, request, req_status);
}
}
if (buffer_cuda != NULL) cudaFree(buffer_cuda);
// Finalize the MPI environment.
MPI_Finalize();
return 0;
}