Skip to content

Commit 7d11ecc

Browse files
committed
testsuite: add one-line MPI timing output mode to t/mpi/hello
Problem: There is no way to easily collect a set of timing output from the MPI hello test in t/mpi/hello.c. Modify the MPI hello test to emit formatted timing output when FLUX_MPI_TEST_TIMING is set in the environment.
1 parent 3d3faae commit 7d11ecc

File tree

1 file changed

+52
-13
lines changed

1 file changed

+52
-13
lines changed

t/mpi/hello.c

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#if HAVE_CONFIG_H
1212
#include "config.h"
1313
#endif
14+
#include <stdint.h>
1415
#include <mpi.h>
1516
#include <stdio.h>
1617
#include <unistd.h>
@@ -19,30 +20,56 @@
1920

2021
#include "src/common/libutil/monotime.h"
2122

23+
static inline void monotime_diff (struct timespec *t0,
24+
struct timespec *result)
25+
{
26+
struct timespec now;
27+
monotime (&now);
28+
result->tv_sec = now.tv_sec - t0->tv_sec;
29+
result->tv_nsec = now.tv_nsec - t0->tv_nsec;
30+
if (result->tv_nsec < 0) {
31+
--result->tv_sec;
32+
result->tv_nsec += 1000000000L;
33+
}
34+
}
35+
36+
static void die (const char *msg)
37+
{
38+
fprintf (stderr, "%s\n", msg);
39+
exit (1);
40+
}
41+
2242
int main (int argc, char *argv[])
2343
{
2444
int id, ntasks;
25-
struct timespec t;
45+
struct timespec t0, t, times[4];
2646
const char *label;
47+
bool timing = getenv ("FLUX_MPI_TEST_TIMING");
2748

2849
if (!(label = getenv ("FLUX_JOB_CC")))
2950
if (!(label = getenv ("FLUX_JOB_ID")))
3051
label = "0";
3152

32-
monotime (&t);
33-
MPI_Init (&argc, &argv);
34-
MPI_Comm_rank (MPI_COMM_WORLD, &id);
35-
MPI_Comm_size (MPI_COMM_WORLD, &ntasks);
36-
if (id == 0) {
37-
printf ("%s: completed MPI_Init in %0.3fs. There are %d tasks\n",
53+
monotime (&t0);
54+
if (MPI_Init (&argc, &argv) != MPI_SUCCESS)
55+
die ("MPI_Init failed\n");
56+
if (MPI_Comm_rank (MPI_COMM_WORLD, &id) != MPI_SUCCESS
57+
|| MPI_Comm_size (MPI_COMM_WORLD, &ntasks) != MPI_SUCCESS)
58+
die ("MPI_Comm_rank/size failed");
59+
monotime_diff (&t0, &times[0]);
60+
if (!timing && id == 0) {
61+
printf ("%s: completed MPI_Init in %0.3fs. There are %d tasks\n",
3862
label,
39-
monotime_since (t) / 1000, ntasks);
63+
monotime_since (t0) / 1000,
64+
ntasks);
4065
fflush (stdout);
4166
}
4267

4368
monotime (&t);
44-
MPI_Barrier (MPI_COMM_WORLD);
45-
if (id == 0) {
69+
if (MPI_Barrier (MPI_COMM_WORLD) != MPI_SUCCESS)
70+
die ("MPI_Barrier failed");
71+
monotime_diff (&t, &times[1]);
72+
if (!timing && id == 0) {
4673
printf ("%s: completed first barrier in %0.3fs\n",
4774
label,
4875
monotime_since (t) / 1000);
@@ -51,10 +78,22 @@ int main (int argc, char *argv[])
5178

5279
monotime (&t);
5380
MPI_Finalize ();
81+
monotime_diff (&t, &times[2]);
82+
monotime_diff (&t0, &times[3]);
83+
5484
if (id == 0) {
55-
printf ("%s: completed MPI_Finalize in %0.3fs\n",
56-
label,
57-
monotime_since (t) / 1000);
85+
if (timing) {
86+
printf ("%6s %8d", getenv ("FLUX_JOB_NNODES"), ntasks);
87+
for (int i = 0; i < 4; i++)
88+
printf (" %4ju.%.9ld",
89+
(uintmax_t) times[i].tv_sec,
90+
times[i].tv_nsec);
91+
printf ("\n");
92+
}
93+
else
94+
printf ("%s: completed MPI_Finalize in %0.3fs\n",
95+
label,
96+
monotime_since (t) / 1000);
5897
fflush (stdout);
5998
}
6099
return 0;

0 commit comments

Comments
 (0)