From a19e0095672c70ea315e787c9ed1a4adb0b2f655 Mon Sep 17 00:00:00 2001
From: "Peter W. Draper" <p.w.draper@durham.ac.uk>
Date: Tue, 24 Sep 2019 15:58:55 +0100
Subject: [PATCH] Attempt to synchronize old and new times for better
 comparison

Still have a problem keeping up with the initial injections
---
 mpiuse.c          |  7 +++++--
 swiftmpistepsim.c | 18 ++++++++++++------
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/mpiuse.c b/mpiuse.c
index ed6007a..6bd7b31 100644
--- a/mpiuse.c
+++ b/mpiuse.c
@@ -204,15 +204,18 @@ void mpiuse_dump_logs(int nranks, const char *dumpfile) {
       fd = fopen(dumpfile, "a");
 
       /* And append our logs. Note log->tic is not necessarily from this
-         machine, so the conversion to ms may be suspect. */
+       * machine, so the conversion to ms may be suspect. We also rebase a
+       * version to match the expected injection times for this new run. */
       size_t nlogs = mpiuse_log_count;
+      ticks basetics = 0;
       for (size_t k = 0; k < nlogs; k++) {
         struct mpiuse_log_entry *log = &mpiuse_log[k];
         if (log->rank == myrank && log->endtic > 0) {
+          if (basetics == 0) basetics = log->tic;
           fprintf(fd,
                   "%lld %.4f %.4f %.4f %.6f %d %d %d %d %d %d %zd %d %.4f %.6f "
                   "%.6f\n",
-                  log->tic, clocks_from_ticks(log->tic),
+                  log->tic, clocks_from_ticks(log->tic - basetics),
                   clocks_from_ticks(log->injtic - clocks_start_ticks),
                   clocks_from_ticks(log->endtic - clocks_start_ticks),
                   clocks_from_ticks(log->endtic - log->injtic), log->step,
diff --git a/swiftmpistepsim.c b/swiftmpistepsim.c
index ae9a976..68bef3b 100644
--- a/swiftmpistepsim.c
+++ b/swiftmpistepsim.c
@@ -80,6 +80,8 @@ static void *inject_thread(void *arg) {
   ticks basetic = reqs_queue[0]->tic;
   ticks looptics = 0;
   double deadtime = 0.0;
+  struct timespec sleep;
+  sleep.tv_sec = 0;
 
   while (ind_req < nr_reqs) {
     struct mpiuse_log_entry *log = reqs_queue[ind_req];
@@ -96,8 +98,6 @@ static void *inject_thread(void *arg) {
        * ticks of the log file into nanoseconds, that requires the original
        * CPU frequency. */
       if (dt > looptics) {
-        struct timespec sleep;
-        sleep.tv_sec = 0;
 
         /* Remember to be fair and remove the looptics, then convert to
          * nanoseconds. */
@@ -149,12 +149,11 @@ static void *inject_thread(void *arg) {
     ind_req++;
 
     /* Set looptics on the first pass. Assumes MPI_Isend and MPI_Irecv are
-     * equally timed. Note we include a nanosleep, they are slow, and a fudge
-     * factor. */
+     * equally timed. Note we include a nanosleep, they are slow. */
     if (looptics == 0 && usetics) {
       sleep.tv_nsec = 1;
       nanosleep(&sleep, NULL);
-      looptics = (getticks() - starttics) * 2;
+      looptics = (getticks() - starttics);
       if (verbose)
         message("injection loop took %.3f %s.", clocks_from_ticks(looptics),
                 clocks_getunit());
@@ -352,6 +351,12 @@ static void pick_logs(void) {
 
   /* Sort into increasing time. */
   qsort(reqs_queue, nr_reqs, sizeof(struct mpiuse_log_entry *), cmp_logs);
+
+  /* Check. */
+  for (int k = 0; k < nr_reqs - 1; k++) {
+    if (reqs_queue[k]->tic > reqs_queue[k+1]->tic)
+      message("reqs_queue: %lld > %lld", reqs_queue[k]->tic, reqs_queue[k+1]->tic);
+  }
 }
 
 /**
@@ -426,7 +431,8 @@ int main(int argc, char *argv[]) {
   /* Each rank requires its own queue, so extract them. */
   pick_logs();
 
-  /* Time to start time. */
+  /* Time to start time. Try to make it synchronous across the ranks. */
+  MPI_Barrier(MPI_COMM_WORLD);
   clocks_set_cpufreq(0);
   if (myrank == 0) {
     message("Start of MPI tests");
-- 
GitLab