55#include < faasm/compare.h>
66#include < faasm/faasm.h>
77#include < faasm/migrate.h>
8+ #include < faasm/time.h>
89
9- #define NUM_LOOPS 50000
1010int checkEvery = 1 ;
11+ int numLoops = 0 ;
1112
1213int doAlltoAll (int rank, int worldSize, int i, int nLoops, int checkEvery)
1314{
@@ -48,7 +49,7 @@ int doAlltoAll(int rank, int worldSize, int i, int nLoops, int checkEvery)
4849// Outer wrapper, and re-entry point after migration
4950void doBenchmark (int nLoops)
5051{
51- bool mustCheck = nLoops == NUM_LOOPS ;
52+ bool mustCheck = nLoops == numLoops ;
5253
5354 // Initialisation
5455 int res = MPI_Init (NULL , NULL );
@@ -62,6 +63,13 @@ void doBenchmark(int nLoops)
6263 MPI_Comm_rank (MPI_COMM_WORLD, &rank);
6364 MPI_Comm_size (MPI_COMM_WORLD, &worldSize);
6465
66+ // Measure time spent migrating
67+ double timeStartSec = 0 ;
68+ double timeEndSec = 0 ;
69+
70+ // Time point for the migrated ranks
71+ printf (" Rank %i - time now: %f\n " , rank, faasm::getSecondsSinceEpoch ());
72+
6573 for (int i = 0 ; i < nLoops; i++) {
6674 if (rank == 0 && i % (nLoops / 10 ) == 0 ) {
6775 printf (" Starting iteration %i/%i\n " , i, nLoops);
@@ -71,6 +79,15 @@ void doBenchmark(int nLoops)
7179 // migrated)
7280 MPI_Barrier (MPI_COMM_WORLD);
7381
82+ // Time after migration
83+ if (!mustCheck && i % checkEvery == 1 && i / checkEvery > 0 ) {
84+ printf (" Time start ms: %f\n " , timeStartSec);
85+ timeEndSec = faasm::getSecondsSinceEpoch ();
86+ printf (" Rank %i spent %f sec migrating\n " ,
87+ rank,
88+ timeEndSec - timeStartSec);
89+ }
90+
7491 doAlltoAll (rank, worldSize, i, nLoops, checkEvery);
7592
7693 if (mustCheck && i % checkEvery == 0 && i / checkEvery > 0 ) {
@@ -83,6 +100,11 @@ void doBenchmark(int nLoops)
83100 // benchmark on another host for the remaining iterations.
84101 // This would eventually be MPI_Barrier
85102 MPI_Barrier (MPI_COMM_WORLD);
103+
104+ // Timing
105+ timeStartSec = faasm::getSecondsSinceEpoch ();
106+ printf (" Time start ms: %f\n " , timeStartSec);
107+
86108 __faasm_migrate_point (&doBenchmark, (nLoops - i - 1 ));
87109 }
88110 }
@@ -96,8 +118,9 @@ void doBenchmark(int nLoops)
96118
97119int main (int argc, char * argv[])
98120{
99- if (argc != 2 ) {
100- printf (" Must provide one input argument: <check_period>\n " );
121+ if (argc != 3 ) {
122+ printf (
123+ " Must provide two input arguments: <check_period> <num_loops>\n " );
101124 return 1 ;
102125 }
103126
@@ -106,13 +129,16 @@ int main(int argc, char* argv[])
106129 // value as we don't migrate global variables, but that's OK as we don't
107130 // support migrating a function twice.
108131 int checkEveryIn = atoi (argv[1 ]);
132+ int numLoopsIn = atoi (argv[2 ]);
133+ int * numLoopsPtr = &numLoops;
134+ *numLoopsPtr = numLoopsIn;
109135 int * checkEveryPtr = &checkEvery;
110- *checkEveryPtr = (int )(NUM_LOOPS * ((float )checkEveryIn / 10.0 ));
136+ *checkEveryPtr = (int )(numLoops * ((float )checkEveryIn / 10.0 ));
111137
112138 printf (
113- " Starting MPI migration checking at iter %i/%i\n " , checkEvery, NUM_LOOPS );
139+ " Starting MPI migration checking at iter %i/%i\n " , checkEvery, numLoops );
114140
115- doBenchmark (NUM_LOOPS );
141+ doBenchmark (numLoops );
116142
117143 printf (" MPI migration benchmark finished succesfully\n " );
118144}
0 commit comments