-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbw.cpp
More file actions
97 lines (76 loc) · 2.12 KB
/
bw.cpp
File metadata and controls
97 lines (76 loc) · 2.12 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
#include <cstdio>
#include <cstdlib>
#include <string>
#include "mpi.h"
#include "cuda_runtime.h"
#include "helper.h"
#define WIN_SIZE 64
#define DEVICE_BUFFER 1
//
// this code is mostly copied from osu_bw
//
void bwtest(int size0, int size1){
int myid, numprocs, i, j;
double t_start = 0.0, t_end = 0.0, t = 0.0;
int size;
int namelen;
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
char *s_buf;
char *r_buf;
#ifdef DEVICE_BUFFER
HANDLE_ERROR(cudaMalloc(&s_buf, size1));
HANDLE_ERROR(cudaMalloc(&r_buf, size1));
#else
s_buf = new char[size1];
r_buf = new char[size1];
#endif
MPI_Request request[WIN_SIZE];
MPI_Status reqstat[WIN_SIZE];
if(numprocs < 2){
return;
}
if(myid == 0){
printf("\n ----- Checking bandwidth from rank 0 to all other ranks ------- \n\n");
}
// loop over the proc that will receive data
for(int p=1; p<numprocs; p++){
// loop over packet size
for(size = size0; size<=size1; size*=4){
if(myid == 0){
t_start = MPI_Wtime();
for(j = 0; j < WIN_SIZE; j++){
MPI_Isend(s_buf, size, MPI_CHAR, p, 100, MPI_COMM_WORLD, request + j);
}
MPI_Waitall(WIN_SIZE, request, reqstat);
MPI_Recv(r_buf, 4, MPI_CHAR, p, 101, MPI_COMM_WORLD,&reqstat[0]);
t_end = MPI_Wtime();
t = t_end - t_start;
} else if(myid == p){
for(j = 0; j < WIN_SIZE; j++) {
MPI_Irecv(r_buf, size, MPI_CHAR, 0, 100, MPI_COMM_WORLD,request+j);
}
MPI_Waitall(WIN_SIZE, request, reqstat);
MPI_Send(s_buf, 4, MPI_CHAR, 0, 101, MPI_COMM_WORLD);
}
if(myid == 0) {
double tmp = size / 1e9 * WIN_SIZE;
printf("N=%10d | 0 -> %3d | %7.4f GB/s\n", size, p, tmp/t);
fflush(stdout);
}
}
if(myid==0){
printf("----\n");
}
}
if(myid == 0){
printf("------------------------------------------\n");
}
#ifdef DEVICE_BUFFER
HANDLE_ERROR(cudaFree(s_buf));
HANDLE_ERROR(cudaFree(r_buf));
#else
delete[] s_buf;
delete[] r_buf;
#endif
}