From 56bbc3c06331a5b0ea9491d55df08a90d7f9e061 Mon Sep 17 00:00:00 2001
From: "Peter W. Draper" <p.w.draper@durham.ac.uk>
Date: Tue, 17 Sep 2019 18:03:26 +0100
Subject: [PATCH] Formatting

---
 error.h     | 22 ++++++++---------
 inject.c    | 11 +--------
 mpistalls.c | 69 +++++++++++++++++++++++++----------------------------
 mpiuse.c    | 17 +++++--------
 mpiuse.h    |  1 -
 readlog.c   |  1 -
 6 files changed, 51 insertions(+), 70 deletions(-)

diff --git a/error.h b/error.h
index c3b9a11..d5e3314 100644
--- a/error.h
+++ b/error.h
@@ -4,18 +4,18 @@
 extern int myrank;
 
 /* Exit in error macro. */
-#define error(s, ...)                                                   \
-  ({                                                                    \
-    fflush(stdout);                                                     \
-    fprintf(stderr, "[%03i] %s %s:%s():%i: " s "\n", myrank,            \
-            clocks_get_timesincestart(),                                \
-            __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__);           \
-    MPI_Abort(MPI_COMM_WORLD, -1);                                      \
+#define error(s, ...)                                                      \
+  ({                                                                       \
+    fflush(stdout);                                                        \
+    fprintf(stderr, "[%03i] %s %s:%s():%i: " s "\n", myrank,               \
+            clocks_get_timesincestart(), __FILE__, __FUNCTION__, __LINE__, \
+            ##__VA_ARGS__);                                                \
+    MPI_Abort(MPI_COMM_WORLD, -1);                                         \
   })
 
 /* Print a message */
-#define message(s, ...)                                                 \
-  ({                                                                    \
-    printf("[%04i] %s %s: " s "\n", myrank,                             \
-           clocks_get_timesincestart(),__FUNCTION__, ##__VA_ARGS__);    \
+#define message(s, ...)                                                  \
+  ({                                                                     \
+    printf("[%04i] %s %s: " s "\n", myrank, clocks_get_timesincestart(), \
+           __FUNCTION__, ##__VA_ARGS__);                                 \
   })
diff --git a/inject.c b/inject.c
index b819e0f..a10ed15 100644
--- a/inject.c
+++ b/inject.c
@@ -1,13 +1,4 @@
 #include <stdio.h>
 
-
-
-
-
-
 /* Injection of MPI_Isends and MPI_Irecvs into the queues. */
-void inject_one(void) {
-}
-
-
-
+void inject_one(void) {}
diff --git a/mpistalls.c b/mpistalls.c
index 28e3135..2a2f8e6 100644
--- a/mpistalls.c
+++ b/mpistalls.c
@@ -8,9 +8,9 @@
  * exchanges of various data sizes and continuously checks the requests for
  * completion. Also need timers to record the time taken by all this...
  */
-#include <stdio.h>
 #include <mpi.h>
 #include <pthread.h>
+#include <stdio.h>
 #include <stdlib.h>
 
 #include "atomic.h"
@@ -32,7 +32,7 @@ static const int task_type_send = 22;
 static const int task_type_recv = 23;
 
 /* Global communicators for each of the subtypes. */
-static const int task_subtype_count = 30; // Just some upper limit on subtype.
+static const int task_subtype_count = 30;  // Just some upper limit on subtype.
 static MPI_Comm subtypeMPI_comms[30];
 
 /* The local queues. */
@@ -62,8 +62,7 @@ static double log_clocks_cpufreq = 2194844448.0;
  */
 static void *inject_thread(void *arg) {
 
-  if (verbose)
-    message("%d: injection thread starts", *((int *)arg));
+  if (verbose) message("%d: injection thread starts", *((int *)arg));
   ticks starttics = getticks();
 
   /* Ticks of our last attempt and ticks the first loop takes (usetics == 1). */
@@ -92,11 +91,11 @@ static void *inject_thread(void *arg) {
          * nanoseconds. */
         double ns = (double)(dt - looptics) / log_clocks_cpufreq * 1.0e9;
         if (ns < 1.0e9) {
-          sleep.tv_nsec = (long) ns;
+          sleep.tv_nsec = (long)ns;
         } else {
           /* Wait more than one second. Must be an error, but complain and
            * continue.  */
-          sleep.tv_nsec = (long) 1.0e9;
+          sleep.tv_nsec = (long)1.0e9;
           message("wait greater than one second");
         }
         nanosleep(&sleep, NULL);
@@ -106,8 +105,8 @@ static void *inject_thread(void *arg) {
     // Differences to SWIFT: MPI_BYTE might overflow, should use MPI_Type(?).
     int err = 0;
     if (log->type == task_type_send) {
-      err = MPI_Isend(log->data, log->size, MPI_BYTE, log->otherrank,
-                      log->tag, subtypeMPI_comms[log->subtype], &log->req);
+      err = MPI_Isend(log->data, log->size, MPI_BYTE, log->otherrank, log->tag,
+                      subtypeMPI_comms[log->subtype], &log->req);
 
       /* Add a new send request. */
       int ind = atomic_inc(&nr_sends);
@@ -115,8 +114,8 @@ static void *inject_thread(void *arg) {
       atomic_inc(&todo_send);
 
     } else {
-      err = MPI_Irecv(log->data, log->size, MPI_BYTE, log->otherrank,
-                      log->tag, subtypeMPI_comms[log->subtype], &log->req);
+      err = MPI_Irecv(log->data, log->size, MPI_BYTE, log->otherrank, log->tag,
+                      subtypeMPI_comms[log->subtype], &log->req);
 
       /* Add a new recv request. */
       int ind = atomic_inc(&nr_recvs);
@@ -166,7 +165,7 @@ static void *inject_thread(void *arg) {
  */
 static void queue_runner(struct mpiuse_log_entry **logs, int volatile *nr_logs,
                          int volatile *todos, double *sum, int *ncalls,
-                         ticks *mint, ticks *maxt ) {
+                         ticks *mint, ticks *maxt) {
 
   /* MPI_Test statistics. */
   int lncalls = 0;
@@ -217,8 +216,7 @@ static void queue_runner(struct mpiuse_log_entry **logs, int volatile *nr_logs,
  */
 static void *send_thread(void *arg) {
 
-  if (verbose)
-    message("%d: send thread starts (%d)", *((int *)arg), injecting);
+  if (verbose) message("%d: send thread starts (%d)", *((int *)arg), injecting);
   ticks starttics = getticks();
 
   int ncalls;
@@ -227,9 +225,11 @@ static void *send_thread(void *arg) {
   ticks maxt;
   queue_runner(sends_queue, &nr_sends, &todo_send, &sum, &ncalls, &mint, &maxt);
 
-  message("%d MPI_Test calls took: %.3f, mean time %.3f, min time %.3f, max time %.3f (%s)",
-          ncalls, clocks_from_ticks(sum), clocks_from_ticks(sum/ncalls),
-          clocks_from_ticks(mint), clocks_from_ticks(maxt), clocks_getunit());
+  message(
+      "%d MPI_Test calls took: %.3f, mean time %.3f, min time %.3f, max time "
+      "%.3f (%s)",
+      ncalls, clocks_from_ticks(sum), clocks_from_ticks(sum / ncalls),
+      clocks_from_ticks(mint), clocks_from_ticks(maxt), clocks_getunit());
   message("took %.3f %s.", clocks_from_ticks(getticks() - starttics),
           clocks_getunit());
 
@@ -242,8 +242,7 @@ static void *send_thread(void *arg) {
  */
 static void *recv_thread(void *arg) {
 
-  if (verbose)
-    message("%d: recv thread starts", *((int *)arg));
+  if (verbose) message("%d: recv thread starts", *((int *)arg));
   ticks starttics = getticks();
 
   int ncalls;
@@ -252,9 +251,11 @@ static void *recv_thread(void *arg) {
   ticks maxt;
   queue_runner(recvs_queue, &nr_recvs, &todo_recv, &sum, &ncalls, &mint, &maxt);
 
-  message("%d MPI_Test calls took: %.3f, mean time %.3f, min time %.3f, max time %.3f (%s)",
-          ncalls, clocks_from_ticks(sum), clocks_from_ticks(sum/ncalls),
-          clocks_from_ticks(mint), clocks_from_ticks(maxt), clocks_getunit());
+  message(
+      "%d MPI_Test calls took: %.3f, mean time %.3f, min time %.3f, max time "
+      "%.3f (%s)",
+      ncalls, clocks_from_ticks(sum), clocks_from_ticks(sum / ncalls),
+      clocks_from_ticks(mint), clocks_from_ticks(maxt), clocks_getunit());
   message("took %.3f %s.", clocks_from_ticks(getticks() - starttics),
           clocks_getunit());
 
@@ -270,10 +271,8 @@ static int cmp_logs(const void *p1, const void *p2) {
   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;
+  if (l1->tic > l2->tic) return 1;
+  if (l1->tic < l2->tic) return -1;
   return 0;
 }
 
@@ -286,14 +285,14 @@ static void pick_logs(void) {
   size_t nlogs = mpiuse_nr_logs();
 
   /* Duplicate of logs. */
-  reqs_queue = (struct mpiuse_log_entry **)
-    malloc(sizeof(struct mpiuse_log_entry *) * nlogs);
-  nr_reqs= 0;
-  sends_queue = (struct mpiuse_log_entry **)
-    malloc(sizeof(struct mpiuse_log_entry *) * nlogs);
-  nr_sends= 0;
-  recvs_queue = (struct mpiuse_log_entry **)
-    malloc(sizeof(struct mpiuse_log_entry *) * nlogs);
+  reqs_queue = (struct mpiuse_log_entry **)malloc(
+      sizeof(struct mpiuse_log_entry *) * nlogs);
+  nr_reqs = 0;
+  sends_queue = (struct mpiuse_log_entry **)malloc(
+      sizeof(struct mpiuse_log_entry *) * nlogs);
+  nr_sends = 0;
+  recvs_queue = (struct mpiuse_log_entry **)malloc(
+      sizeof(struct mpiuse_log_entry *) * nlogs);
   nr_recvs = 0;
 
   for (int k = 0; k < nlogs; k++) {
@@ -318,7 +317,6 @@ static void pick_logs(void) {
   qsort(reqs_queue, nr_reqs, sizeof(struct mpiuse_log_entry *), cmp_logs);
 }
 
-
 /**
  * @brief main function.
  */
@@ -338,8 +336,7 @@ int main(int argc, char *argv[]) {
 
   int nr_nodes = 0;
   res = MPI_Comm_size(MPI_COMM_WORLD, &nr_nodes);
-  if (res != MPI_SUCCESS)
-    error("MPI_Comm_size failed with error %i.", res);
+  if (res != MPI_SUCCESS) error("MPI_Comm_size failed with error %i.", res);
 
   /* This should match the expected size. */
   if (nr_nodes != nranks)
diff --git a/mpiuse.c b/mpiuse.c
index 3f614bf..fad598e 100644
--- a/mpiuse.c
+++ b/mpiuse.c
@@ -141,8 +141,7 @@ void mpiuse_log_restore(const char *filename) {
   /* Open the input file. */
   FILE *fd;
   if ((fd = fopen(filename, "r")) == NULL) {
-    message("Failed to open the MPI use log file '%s'.",
-            filename);
+    message("Failed to open the MPI use log file '%s'.", filename);
     return;
   }
 
@@ -155,9 +154,9 @@ void mpiuse_log_restore(const char *filename) {
   while (!feof(fd)) {
     if (fgets(line, 132, fd) != NULL) {
       if (line[0] != '#') {
-        sscanf(line, "%zd %zd %zd %d %d %d %s %d %s %d %d %d %zd %zd",
-               &stic, &etic, &dtic, &step, &rank, &otherrank, type, &itype,
-               subtype, &isubtype, &activation, &tag, &size, &sum);
+        sscanf(line, "%zd %zd %zd %d %d %d %s %d %s %d %d %d %zd %zd", &stic,
+               &etic, &dtic, &step, &rank, &otherrank, type, &itype, subtype,
+               &isubtype, &activation, &tag, &size, &sum);
 
         mpiuse_log_allocation(rank, step, stic, itype, isubtype, activation,
                               size, otherrank, tag);
@@ -172,18 +171,14 @@ void mpiuse_log_restore(const char *filename) {
  *
  * @result the number of log entries.
  */
-int mpiuse_nr_logs(void) {
-  return mpiuse_log_count;
-}
+int mpiuse_nr_logs(void) { return mpiuse_log_count; }
 
 /**
  * @brief return the number of ranks in log.
  *
  * @result the number of ranks we've seen.
  */
-int mpiuse_nr_ranks(void) {
-  return mpiuse_max_rank + 1;
-}
+int mpiuse_nr_ranks(void) { return mpiuse_max_rank + 1; }
 
 /**
  * @brief get a log entry.
diff --git a/mpiuse.h b/mpiuse.h
index 0bd8df6..0725bc9 100644
--- a/mpiuse.h
+++ b/mpiuse.h
@@ -58,7 +58,6 @@ struct mpiuse_log_entry {
 
   /* The request associated with the call. */
   MPI_Request req;
-
 };
 
 /* API. */
diff --git a/readlog.c b/readlog.c
index 3763572..84f63fa 100644
--- a/readlog.c
+++ b/readlog.c
@@ -1,6 +1,5 @@
 #include <stdio.h>
 
-
 /**
  * @brief read the output from a run of SWIFT with the MPI communication
  * logger enabled.
-- 
GitLab