From ea3fbee7cb56c972a77b58fb79c4749ee2fdff00 Mon Sep 17 00:00:00 2001
From: "Peter W. Draper" <p.w.draper@durham.ac.uk>
Date: Mon, 18 Oct 2021 12:07:33 +0100
Subject: [PATCH] Honour -f flag

---
 swiftmpifakestepsim.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/swiftmpifakestepsim.c b/swiftmpifakestepsim.c
index 9939f1a..2aa75cd 100644
--- a/swiftmpifakestepsim.c
+++ b/swiftmpifakestepsim.c
@@ -288,15 +288,15 @@ static void *recv_thread(void *arg) {
 /**
  * @brief Comparison function for logged times.
  */
-// static int cmp_logs(const void *p1, const void *p2) {
-//  struct mpiuse_log_entry *l1 = *(struct mpiuse_log_entry **)p1;
-//  struct mpiuse_log_entry *l2 = *(struct mpiuse_log_entry **)p2;
-//
-//  /* Large unsigned values, so take care. */
-//  if (l1->tic > l2->tic) return 1;
-//  if (l1->tic < l2->tic) return -1;
-//  return 0;
-//}
+static int cmp_logs(const void *p1, const void *p2) {
+  struct mpiuse_log_entry *l1 = *(struct mpiuse_log_entry **)p1;
+  struct mpiuse_log_entry *l2 = *(struct mpiuse_log_entry **)p2;
+
+  /* Large unsigned values, so take care. */
+  if (l1->tic > l2->tic) return 1;
+  if (l1->tic < l2->tic) return -1;
+  return 0;
+}
 
 /**
  * @brief Pick out the relevant logging data for our rank, i.e. all
@@ -304,7 +304,7 @@ static void *recv_thread(void *arg) {
  * The final list is sorted into increasing time of activation if required,
  * otherwise the order is randomized.
  *
- * @param random randomize injection order, otherwise use order of thr
+ * @param random randomize injection order, otherwise use order of the
  *               original logs.
  */
 static void pick_logs(int random) {
@@ -330,11 +330,13 @@ static void pick_logs(int random) {
     }
   }
 
-  /* Sort into increasing time. */
-  // qsort(reqs_queue, nr_reqs, sizeof(struct mpiuse_log_entry *), cmp_logs);
-
-  /* Randomize the order, so ranks do not all work in sequence. */
-  mpiuse_shuffle_logs(reqs_queue, nr_reqs);
+  if (!random) {
+    /* Sort into increasing time. */
+    qsort(reqs_queue, nr_reqs, sizeof(struct mpiuse_log_entry *), cmp_logs);
+  } else {
+    /* Randomize the order, so ranks do not all work in sequence. */
+    mpiuse_shuffle_logs(reqs_queue, nr_reqs);
+  }
 
   /* Check. */
   if (!random) {
-- 
GitLab