-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
79 lines (61 loc) · 1.7 KB
/
main.cpp
File metadata and controls
79 lines (61 loc) · 1.7 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
#include <cstdio>
#include <cstdlib>
#include <string>
#include "mpi.h"
#include "cuda_runtime.h"
#include "helper.h"
void bwtest(int size0, int size1);
void datatest(int size0, int size1);
void setdev(){
int myid, numprocs, i, j;
double t_start = 0.0, t_end = 0.0, t = 0.0;
char cpu_name[MPI_MAX_PROCESSOR_NAME];
char gpu_name[MPI_MAX_PROCESSOR_NAME];
char line[128];
int namelen;
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
MPI_Get_processor_name(cpu_name, &namelen);
char *s_buf;
char *r_buf;
int device, ngpu;
HANDLE_ERROR(cudaGetDeviceCount(&ngpu));
device = myid % ngpu;
HANDLE_ERROR( cudaSetDevice( device) );
cudaDeviceProp prop;
HANDLE_ERROR( cudaGetDeviceProperties(&prop, device) );
sprintf(gpu_name,"%s_%d[%X]", prop.name,device,((unsigned long long*)prop.uuid.bytes)[0]);
MPI_Status stat;
if(myid == 0){
printf("\n----------- Info about matching ranks to gpus and hosts ------------\n");
}
for(int p=0; p<numprocs; p++){
if(myid == p){
sprintf(line,"Rank %3d on %30s from %20s\n", myid, gpu_name, cpu_name);
if(p>0){
MPI_Send(line, 128, MPI_CHAR, 0, 200+p, MPI_COMM_WORLD);
}
}
if(myid == 0){
if(p>0){
MPI_Recv(line, 128, MPI_CHAR, p, 200+p, MPI_COMM_WORLD,&stat);
}
printf(line);
}
MPI_Barrier(MPI_COMM_WORLD);
}
if(myid == 0){
printf("------------------------------------------------\n");
}
fflush(stdout);
MPI_Barrier(MPI_COMM_WORLD);
}
int main(int argc, char* argv[]){
MPI_Init(&argc, &argv);
setdev();
// bwtest(262144,4194304);
bwtest(4096,4194304);
datatest(4096,4194304);
MPI_Finalize();
return 0;
}