Skip to content

Commit 23349ec

Browse files
committed
break timings into 10 buckets
1 parent 0b73ba9 commit 23349ec

File tree

1 file changed

+45
-14
lines changed

1 file changed

+45
-14
lines changed

MPI/alltoallw.c

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,16 @@ void run_alltoallw(int ntimes,
128128
int *recvBuf)
129129
{
130130
int *sendPtr;
131-
int i, j, err, nprocs, rank, num_recvers;
131+
int i, j, err, nprocs, rank, num_recvers, bucket_len;
132132
int *sendCounts, *recvCounts, *sendDisps, *recvDisps;
133133
MPI_Datatype *sendTypes, *recvTypes;
134-
double timing, maxt;
134+
double start_t, end_t, timing[10], maxt[10];
135+
136+
bucket_len = ntimes / 10;
137+
if (ntimes % 10) bucket_len++;
135138

136139
MPI_Barrier(MPI_COMM_WORLD);
137-
timing = MPI_Wtime();
140+
timing[0] = MPI_Wtime();
138141

139142
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
140143
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
@@ -176,6 +179,7 @@ void run_alltoallw(int ntimes,
176179
printf("%2d send to %2d of %d\n",rank,i,sendCounts[i]);
177180
}
178181

182+
start_t = MPI_Wtime();
179183
sendPtr = sendBuf;
180184
for (i=0; i<ntimes; i++) {
181185
if (debug && is_receiver)
@@ -188,17 +192,28 @@ void run_alltoallw(int ntimes,
188192

189193
if (debug && is_receiver)
190194
check_recv_buf("alltoallw", len, gap, recvBuf);
195+
196+
if (i > 0 && i % bucket_len == 0) {
197+
end_t = MPI_Wtime();
198+
timing[i / bucket_len] = end_t - start_t;
199+
start_t = end_t;
200+
}
191201
}
202+
end_t = MPI_Wtime();
203+
timing[9] = end_t - start_t;
204+
timing[0] = end_t - timing[0]; /* end-to-end time */
192205

193206
err_out:
194207
free(sendTypes);
195208
free(sendCounts);
196209
free(sendDisps);
197210

198-
timing = MPI_Wtime() - timing;
199-
MPI_Reduce(&timing, &maxt, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
200-
if (rank == 0)
201-
printf("Time for using MPI_alltoallw = %.2f sec\n", maxt);
211+
MPI_Reduce(&timing, &maxt, 10, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
212+
if (rank == 0) {
213+
printf("Time for using MPI_alltoallw = %.2f sec\n", maxt[0]);
214+
for (i=1; i<10; i++)
215+
printf("\tTime bucket[%d] = %.2f sec\n", i, maxt[i]);
216+
}
202217
}
203218

204219
/* all-to-many personalized communication by calling MPI_Issend/Irecv() */
@@ -211,13 +226,16 @@ void run_async_send_recv(int ntimes,
211226
int *recvBuf)
212227
{
213228
int *sendPtr, *recvPtr;
214-
int i, j, err, nprocs, rank, nreqs, num_recvers;
229+
int i, j, err, nprocs, rank, nreqs, num_recvers, bucket_len;
215230
MPI_Request *reqs;
216231
MPI_Status *st;
217-
double timing, maxt;
232+
double start_t, end_t, timing[10], maxt[10];
233+
234+
bucket_len = ntimes / 10;
235+
if (ntimes % 10) bucket_len++;
218236

219237
MPI_Barrier(MPI_COMM_WORLD);
220-
timing = MPI_Wtime();
238+
timing[0] = MPI_Wtime();
221239

222240
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
223241
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
@@ -227,6 +245,7 @@ void run_async_send_recv(int ntimes,
227245
reqs = (MPI_Request*) malloc(sizeof(MPI_Request) * (nprocs + num_recvers));
228246
st = (MPI_Status*) malloc(sizeof(MPI_Status) * (nprocs + num_recvers));
229247

248+
start_t = MPI_Wtime();
230249
sendPtr = sendBuf;
231250
for (i=0; i<ntimes; i++) {
232251
if (debug && is_receiver)
@@ -262,16 +281,27 @@ void run_async_send_recv(int ntimes,
262281

263282
if (debug && is_receiver)
264283
check_recv_buf("issend/irecv", len, gap, recvBuf);
284+
285+
if (i > 0 && i % bucket_len == 0) {
286+
end_t = MPI_Wtime();
287+
timing[i / bucket_len] = end_t - start_t;
288+
start_t = end_t;
289+
}
265290
}
291+
end_t = MPI_Wtime();
292+
timing[9] = end_t - start_t;
293+
timing[0] = end_t - timing[0]; /* end-to-end time */
266294

267295
err_out:
268296
free(st);
269297
free(reqs);
270298

271-
timing = MPI_Wtime() - timing;
272-
MPI_Reduce(&timing, &maxt, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
273-
if (rank == 0)
274-
printf("Time for using MPI_Issend/Irecv = %.2f sec\n", maxt);
299+
MPI_Reduce(&timing, &maxt, 10, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
300+
if (rank == 0) {
301+
printf("Time for using MPI_Issend/Irecv = %.2f sec\n", maxt[0]);
302+
for (i=1; i<10; i++)
303+
printf("\tTime bucket[%d] = %.2f sec\n", i, maxt[i]);
304+
}
275305
}
276306

277307
/*----< usage() >------------------------------------------------------------*/
@@ -386,3 +416,4 @@ int main(int argc, char **argv) {
386416
return 0;
387417
}
388418

419+

0 commit comments

Comments
 (0)