-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.c
95 lines (71 loc) · 2.14 KB
/
profile.c
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
#include <time.h>
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <mpi.h>
#define ITERATIONS 10000L
#define USEC 1000L
int corrected_broadcast(void *const, int const, MPI_Datatype const, int const, MPI_Comm const);
int my_rank;
int numprocs;
uint64_t get_time()
{
struct timespec ts;
timespec_get(&ts, TIME_UTC);
return (uint64_t)ts.tv_sec * 1000000000L + ts.tv_nsec;
}
void print_stat(const uint64_t time)
{
uint64_t min_time, max_time, avg_time;
MPI_Reduce(&time, &min_time, 1, MPI_UINT64_T, MPI_MIN, 0, MPI_COMM_WORLD);
MPI_Reduce(&time, &max_time, 1, MPI_UINT64_T, MPI_MAX, 0, MPI_COMM_WORLD);
MPI_Reduce(&time, &avg_time, 1, MPI_UINT64_T, MPI_SUM, 0, MPI_COMM_WORLD);
// Compute time per iteration in microseconds
min_time = min_time / (ITERATIONS * USEC);
max_time = max_time / (ITERATIONS * USEC);
avg_time = avg_time / (ITERATIONS * USEC * (uint64_t)numprocs);
if (!my_rank) {
printf("%" PRIu64 "\t%" PRIu64 "\t%" PRIu64 "\n", min_time, max_time, avg_time);
}
}
int main(int argc, char **argv)
{
putenv("CORRT_COUNT_MAX=256");
putenv("CORRT_DISS_TYPE=tree_binomial");
putenv("CORRT_DIST=0");
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
if (!my_rank) {
printf("%d\n", numprocs);
printf("Min\tMax\tAvg\n");
}
static char buffer[4096];
int size = 256;
// Warmup
for (int i = 0; i < ITERATIONS; i++) {
MPI_Bcast(buffer, size, MPI_CHAR, 0, MPI_COMM_WORLD);
MPI_Barrier(MPI_COMM_WORLD);
}
uint64_t t_start, t_stop, t_elapsed = 0;
// Our bcast
for (int i = 0; i < ITERATIONS; i++) {
t_start = get_time();
corrected_broadcast(buffer, size, MPI_CHAR, 0, MPI_COMM_WORLD);
t_stop = get_time();
t_elapsed += t_stop - t_start;
MPI_Barrier(MPI_COMM_WORLD);
}
print_stat(t_elapsed);
// Normal bcast
t_elapsed = 0;
for (int i = 0; i < ITERATIONS; i++) {
t_start = get_time();
MPI_Bcast(buffer, size, MPI_CHAR, 0, MPI_COMM_WORLD);
t_stop = get_time();
t_elapsed += t_stop - t_start;
MPI_Barrier(MPI_COMM_WORLD);
}
print_stat(t_elapsed);
MPI_Finalize();
}