-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmpid.cc
278 lines (237 loc) · 8.76 KB
/
mpid.cc
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
//////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2018, Lawrence Livermore National Security, LLC.
// Produced at the Lawrence Livermore National Laboratory.
//
// Written by Emilio Castillo <ecastill@bsc.es>.
// LLNL-CODE-745958. All rights reserved.
//
// This file is part of Loupe. For details, see:
// https://github.com/LLNL/loupe
// Please also read the LICENSE file for the MIT License notice.
//////////////////////////////////////////////////////////////////////////////
#include <mpi.h>
#include "hdf5_dump.hh"
#include "mpid.hh"
#include "util.hh"
mpid_data_stats::mpid_data_stats(std::string p_section_name, std::string* p_call_names) : m_section_name(p_section_name), m_call_names(p_call_names){
PMPI_Comm_size(MPI_COMM_WORLD, &m_num_ranks);
PMPI_Comm_rank(MPI_COMM_WORLD, &m_rank);
m_enabled = true;
}
void
mpid_data_stats::mpid_init(){
gettimeofday(&m_timer_start, NULL);
}
void
mpid_data_stats::mpid_finalize(){
gettimeofday(&m_timer_end, NULL);
m_enabled = false;
m_app_time = (m_timer_end.tv_sec - m_timer_start.tv_sec)*1e6 + (m_timer_end.tv_usec - m_timer_start.tv_usec);
m_app_time /= 1000;
//Create a dict file with the callsites symbols and fn names ids
dump_symbols(m_call_names);
//binary dump to hdf5
hdf5_dump(this);
}
void
mpid_data_stats::mpid_call_start(int p_name){
gettimeofday(&m_func_timer_start, NULL);
}
uint64_t
mpid_data_stats::mpid_call_end(int p_name){
uint64_t elapsed;
gettimeofday(&m_func_timer_end, NULL);
elapsed = (m_func_timer_end.tv_sec - m_func_timer_start.tv_sec)*1e6 + (m_func_timer_end.tv_usec - m_func_timer_start.tv_usec);
return elapsed;
}
void
mpid_data_stats::mpid_call_stats(int p_count, int p_datatype, uint64_t p_time, int p_name){
uint64_t pc;
int type_size;
if(!m_enabled) return;
backtrace(&pc);
PMPI_Type_size(p_datatype,&type_size);
type_size *= p_count;
if(m_global_call_data.find(p_name)==m_global_call_data.end()){
m_global_call_data[p_name].m_kbytes_sent = 0;
m_global_call_data[p_name].m_total_calls = 0;
m_global_call_data[p_name].m_time_spent = 0;
}
if(m_mpi_call_data.find(pc)==m_mpi_call_data.end()){
m_mpi_call_data[pc].m_kbytes_sent = 0;
m_mpi_call_data[pc].m_total_calls = 0;
m_mpi_call_data[pc].m_time_spent = 0;
m_mpi_call_data[pc].m_name = p_name;
}
m_mpi_call_data[pc].m_kbytes_sent += type_size;
m_mpi_call_data[pc].m_total_calls++;
m_mpi_call_data[pc].m_time_spent +=p_time;
m_global_call_data[p_name].m_kbytes_sent += type_size;
m_global_call_data[p_name].m_total_calls++;
m_global_call_data[p_name].m_time_spent +=p_time;
m_mpi_acc_time +=p_time;
}
void
mpid_data_stats::mpid_traffic_pattern(int dest, int p_count, int p_datatype, int comm, int p_name){
uint64_t pc;
int type_size;
if(!m_enabled) return;
PMPI_Type_size(p_datatype, &type_size);
uint64_t kbytes = type_size * p_count;
backtrace(&pc);
//PTP COMM
if(dest !=-1){
if(m_pattern.find(dest) == m_pattern.end()){
m_pattern[dest].m_kbytes = 0;
m_pattern[dest].m_count = 0;
}
if(m_call_pattern[pc].find(dest) == m_call_pattern[pc].end()){
m_call_pattern[pc][dest].m_kbytes = 0;
m_call_pattern[pc][dest].m_count = 0;
m_call_pattern[pc][dest].m_comm = comm;
}
m_pattern[dest].m_kbytes += kbytes;
m_pattern[dest].m_count++;
m_call_pattern[pc][dest].m_kbytes += kbytes;
m_call_pattern[pc][dest].m_count ++;
m_call_pattern[pc][dest].m_name = p_name;
} else if(comm!= MPI_COMM_WORLD){
for(uint32_t i=0;i<m_comm_rank[comm].size();i++){
int dest=m_comm_rank[comm][i];
if(dest == m_rank) continue;
if(m_pattern.find(dest) == m_pattern.end()){
m_pattern[dest].m_kbytes = 0;
m_pattern[dest].m_count = 0;
}
if(m_call_pattern[pc].find(dest) == m_call_pattern[pc].end()){
m_call_pattern[pc][dest].m_kbytes = 0;
m_call_pattern[pc][dest].m_count = 0;
m_call_pattern[pc][dest].m_comm = comm;
}
m_pattern[dest].m_kbytes += kbytes;
m_pattern[dest].m_count++;
m_call_pattern[pc][dest].m_kbytes += kbytes;
m_call_pattern[pc][dest].m_count ++;
m_call_pattern[pc][dest].m_name = p_name;
}
} else {
for(int i=0;i<m_num_ranks;i++){
int dest=i;
if(dest == m_rank) continue;
if(m_pattern.find(dest) == m_pattern.end()){
m_pattern[dest].m_kbytes = 0;
m_pattern[dest].m_count = 0;
}
if(m_call_pattern[pc].find(dest) == m_call_pattern[pc].end()){
m_call_pattern[pc][dest].m_kbytes = 0;
m_call_pattern[pc][dest].m_count = 0;
m_call_pattern[pc][dest].m_comm = comm;
}
m_pattern[dest].m_kbytes += kbytes;
m_pattern[dest].m_count++;
m_call_pattern[pc][dest].m_kbytes += kbytes;
m_call_pattern[pc][dest].m_count ++;
m_call_pattern[pc][dest].m_name = p_name;
}
}
}
void
mpid_data_stats::mpid_add_communicator(MPI_Comm* newcomm){
MPI_Group grp, world_grp;
int grp_size;
int *ranks;
int *world_ranks;
//Lets get a comm->world translation
PMPI_Comm_group(MPI_COMM_WORLD, &world_grp);
PMPI_Comm_group(*newcomm, &grp);
PMPI_Group_size(grp, &grp_size);
ranks = new int[grp_size];
world_ranks = new int[grp_size];
for (int i = 0; i < grp_size; i++)
ranks[i] = i;
PMPI_Group_translate_ranks(grp, grp_size, ranks, world_grp, world_ranks);
m_comm_rank[*newcomm].resize(grp_size);
for (int i = 0; i < grp_size; i++){
m_comm_rank[*newcomm][i] = world_ranks[i];
if(world_ranks[i] == m_rank)
m_my_comm_ranks[*newcomm] = i;
}
delete[] ranks;
delete[] world_ranks;
}
bool
mpid_data_stats::is_me(int rank, MPI_Comm newcomm){
bool is_me = false;
if(rank == MPI_COMM_WORLD){
is_me = rank == m_rank;
}else if(m_my_comm_ranks.find(newcomm)!=m_my_comm_ranks.end()){
is_me = rank == m_my_comm_ranks[newcomm];
}
return is_me;
}
uint64_t
mpid_data_stats::size_call_pattern(){
uint64_t size = 0;
for(auto it=m_call_pattern.begin();it!=m_call_pattern.end();it++)
size += it->second.size();
return size;
}
void
mpid_data_stats::calls_data(uint64_t *p_data_out){
int i=0;
for(auto it=m_global_call_data.begin();it!=m_global_call_data.end();it++){
//printf("%ld\n",it->first);
p_data_out[i*4+0] = it->first;
p_data_out[i*4+1] = it->second.m_total_calls;
p_data_out[i*4+2] = it->second.m_time_spent;
p_data_out[i*4+3] = it->second.m_kbytes_sent;
//if(m_rank==3){
// printf("%d %ld %ld %ld %ld\n",it->first,p_data_out[i*4+0],p_data_out[i*4+1],p_data_out[i*4+2], p_data_out[i*4+3]);
//}
i++;
}
}
void
mpid_data_stats::callsites_data(uint64_t *p_data_out){
int i=0;
for(auto it=m_mpi_call_data.begin();it!=m_mpi_call_data.end();it++){
//printf("%ld\n",it->first);
p_data_out[i*5+0] = it->first;
p_data_out[i*5+1] = it->second.m_name;
p_data_out[i*5+2] = it->second.m_total_calls;
p_data_out[i*5+3] = it->second.m_time_spent;
p_data_out[i*5+4] = it->second.m_kbytes_sent;
//if(m_rank==3){
// printf("%ld %ld %ld %ld %ld\n",p_data_out[i*4+0],p_data_out[i*4+1],p_data_out[i*4+2], p_data_out[i*4+3],p_data_out[i*4+4]);
//}
i++;
}
//printf("size is %d , *4 is %d i is %d\n",n_mpi_callsites(),n_mpi_callsites()*4,i);
//printf("rank %d size %d\n",m_rank,m_mpi_call_data.size());
}
void
mpid_data_stats::pattern_data(uint64_t *p_data_out){
int i=0;
for(auto it=m_pattern.begin();it!=m_pattern.end();it++){
p_data_out[i*3+0] = it->first;
p_data_out[i*3+1] = it->second.m_kbytes;
p_data_out[i*3+2] = it->second.m_count;
//if(m_rank==3){
// printf("%d %ld %ld\n %ld",it->first,p_data_out[i*4+0],p_data_out[i*4+1],p_data_out[i*4+2]);
//}
i++;
}
}
void
mpid_data_stats::call_pattern_data(uint64_t *p_data_out){
int i=0;
for(auto it=m_call_pattern.begin();it!=m_call_pattern.end();it++){
for(auto it2=it->second.begin();it2!=it->second.end();it2++){
p_data_out[i*4+0] = it->first; //PC
p_data_out[i*4+1] = it2->first; //DEST
p_data_out[i*4+2] = it2->second.m_kbytes;
p_data_out[i*4+3] = it2->second.m_count;
i++;
}
}
}