Skip to content

Commit 7afa3f1

Browse files
author
Simon Pickartz
committed
add bcast_lat bench
1 parent 4958582 commit 7afa3f1

File tree

2 files changed

+200
-5
lines changed

2 files changed

+200
-5
lines changed

Makefile

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
CC := mpicc
22
LD := mpicc
3-
CFLAGS := -Wall -Wextra -O3 -openmp
3+
CFLAGS := -Wall -Wextra -O3 -fopenmp -g
44
CPPFLAGS := -I ./
5-
LDFLAGS :=
6-
LIBS := -openmp
5+
LDFLAGS := -lm
6+
LIBS := -fopenmp
77
RM := rm -f
88

99
SRCS := $(wildcard *.c)
1010
OBJS := $(patsubst %.c,%.o,$(SRCS))
11-
BINS := pingpong_lat pingpong_length
11+
BINS := pingpong_lat pingpong_length bcast_lat
1212

1313
.PHONY: clean
1414

15-
all: $(BINS)
15+
all: $(BINS)
1616

1717
pingpong_lat: pingpong_lat.o stat_eval.o
1818
$(LD) $(LIBS) $(LDFLAGS) -o $@ $^
1919

20+
bcast_lat: bcast_lat.o stat_eval.o
21+
$(LD) $(LIBS) $(LDFLAGS) -o $@ $^
22+
2023
%.o: %.c
2124
$(CC) $(CPPFLAGS) -c $(CFLAGS) -o $@ $<
2225

bcast_lat.c

+192
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/*
2+
* Copyright 2017, Simon Pickartz Institute for Automation of Complex Power
3+
* Systems,
4+
* RWTH Aachen University
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
*/
19+
20+
#include <errno.h>
21+
#include <stdbool.h>
22+
#include <stdint.h>
23+
#include <stdio.h>
24+
#include <stdlib.h>
25+
#include <string.h>
26+
#include <time.h>
27+
#include <unistd.h>
28+
29+
#include <mpi.h>
30+
31+
#include <stat_eval.h>
32+
33+
#undef _WATCH_DOG_
34+
#undef _CACHE_WARM_UP_
35+
#undef _USE_SEPARATED_BUFFERS_
36+
#define _PRINT_INDIVIDUAL_RES_
37+
38+
#define MAXBUFSIZE (2097152)
39+
#define DEFAULTLEN (0)
40+
#define DEFAULTDELAY (0)
41+
#define DEFAULTROUNDS (10000)
42+
#define DEFAULTITER (1)
43+
#define WARMUPITER (10000)
44+
45+
#ifdef _USE_SEPARATED_BUFFERS_
46+
unsigned char send_buffer[MAXBUFSIZE + 1];
47+
unsigned char recv_buffer[MAXBUFSIZE + 1];
48+
#else
49+
#define send_buffer buffer
50+
#define recv_buffer buffer
51+
unsigned char buffer[MAXBUFSIZE + 1];
52+
#endif
53+
unsigned char dummy = 0;
54+
55+
int main(int argc, char **argv) {
56+
int arg;
57+
uint32_t i;
58+
int32_t num_ranks;
59+
int32_t my_rank;
60+
61+
uint32_t length = DEFAULTLEN;
62+
uint32_t iterations = DEFAULTITER;
63+
int32_t numrounds = DEFAULTROUNDS;
64+
int32_t round;
65+
66+
double timer;
67+
double *time_stamps = NULL;
68+
stat_eval_t stat_eval;
69+
bool run_infinitely;
70+
char *filename = NULL;
71+
72+
/* initialize MPI environment */
73+
MPI_Init(&argc, &argv);
74+
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
75+
MPI_Comm_size(MPI_COMM_WORLD, &num_ranks);
76+
77+
/* determine arguments */
78+
while ((arg = getopt(argc, argv, "i:r:l:hf:")) != -1) {
79+
switch (arg) {
80+
case 'r':
81+
numrounds = atoi(optarg);
82+
break;
83+
case 'f':
84+
filename = optarg;
85+
break;
86+
case 'l':
87+
length = atoi(optarg);
88+
if (length > MAXBUFSIZE) {
89+
if (my_rank == 0) {
90+
fprintf(stderr, "ERROR: message length (%d) exceeds MAXBUFSIZE (%d). Abort!\n", length, MAXBUFSIZE);
91+
}
92+
exit(-1);
93+
}
94+
break;
95+
case 'i':
96+
iterations = atoi(optarg);
97+
break;
98+
case 'h':
99+
if (my_rank == 0) {
100+
printf(
101+
"usage %s [-l message_length (def: %d)] "
102+
"[-i iterations (def: %d)] "
103+
"[-r rounds (def: %d)] "
104+
"[-f filename]\n",
105+
argv[0], DEFAULTLEN, DEFAULTITER,
106+
DEFAULTROUNDS);
107+
fflush(stdout);
108+
}
109+
exit(0);
110+
}
111+
}
112+
113+
/* perform a warm-up of the cache */
114+
#ifdef _CACHE_WARM_UP_
115+
for (i = 0; i < length; i++) {
116+
/* cache warm-up: */
117+
dummy += send_buffer[i];
118+
dummy += recv_buffer[i];
119+
}
120+
#endif
121+
122+
/* check for infinite test */
123+
if (numrounds == -1) {
124+
run_infinitely = true;
125+
} else {
126+
run_infinitely = false;
127+
time_stamps = (double *)calloc(sizeof(double), numrounds);
128+
}
129+
130+
if (my_rank == 0) {
131+
printf("Starting the benchmark:\n");
132+
if (numrounds == -1) {
133+
printf("Rounds : inf\n");
134+
} else {
135+
printf("Rounds : %10d\n", numrounds);
136+
}
137+
printf("Iterations : %10d\n", iterations);
138+
printf("Msg Length : %10d\n", length);
139+
if (filename) {
140+
printf("Filename : %s\n", filename);
141+
} else {
142+
printf("Filename : stdout\n");
143+
}
144+
}
145+
146+
/* synchronize and start the benchmark */
147+
MPI_Barrier(MPI_COMM_WORLD);
148+
for (i = 0; i < WARMUPITER; ++i) {
149+
MPI_Bcast(buffer, length, MPI_CHAR, 0, MPI_COMM_WORLD);
150+
}
151+
152+
for (round = 0; run_infinitely || (round < numrounds); ++round) {
153+
/* start timer: */
154+
timer = MPI_Wtime();
155+
156+
for (i=0; i<iterations; ++i) {
157+
MPI_Bcast(buffer, length, MPI_CHAR, 0, MPI_COMM_WORLD);
158+
}
159+
160+
/* stop timer: */
161+
timer = (MPI_Wtime() - timer);
162+
if (run_infinitely == false)
163+
time_stamps[round] = timer * 1e6 / iterations;
164+
#ifdef _PRINT_INDIVIDUAL_RES_
165+
printf("%d\t\t%1.2lf\n", length, timer / iterations * 1000000);
166+
fflush(stdout);
167+
168+
#endif
169+
#ifdef _WATCH_DOG_
170+
if (!(round % 100)) printf("Round %d ...\n", round);
171+
#endif
172+
}
173+
174+
/* Statistical evaluation */
175+
if ((my_rank == 0) && (run_infinitely == false)) {
176+
statistical_eval(time_stamps, numrounds, &stat_eval);
177+
178+
/* print the results */
179+
FILE *output = stdout;
180+
if (filename) {
181+
output = fopen(filename, "w+");
182+
}
183+
print_statistics(&stat_eval, numrounds, output);
184+
if (filename) {
185+
fclose(output);
186+
}
187+
}
188+
189+
MPI_Finalize();
190+
191+
return 0;
192+
}

0 commit comments

Comments
 (0)