From e2abdd59643cf674c71773753e3cdb2e0240d868 Mon Sep 17 00:00:00 2001
From: "Peter W. Draper" <p.w.draper@durham.ac.uk>
Date: Wed, 14 Sep 2022 12:38:41 +0100
Subject: [PATCH] Truncate large messages to 2GB, improve help

---
 mpiuse.c              | 12 +++++++++---
 swiftmpifakestepsim.c |  3 ++-
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/mpiuse.c b/mpiuse.c
index 07b6f6f..ab6a031 100644
--- a/mpiuse.c
+++ b/mpiuse.c
@@ -363,7 +363,7 @@ void mpiuse_log_generate(int nr_nodes, int nr_logs, int size, int random,
   for (int k = 0; k < nr_logs; k++) {
 
     /* Set size for this messages. */
-    int logsize = size;
+    double logsize = size;
     if (random) {
       if (cdf || odata) {
         /* CDF based randoms. */
@@ -391,12 +391,18 @@ void mpiuse_log_generate(int nr_nodes, int nr_logs, int size, int random,
       }
     }
 
+    /* Cannot send more than 2^31-1 bytes at a time, so truncate. */
+    if (logsize > 2147483647.0) {
+      message("CDF size too large : %f, truncating", logsize);
+      logsize = 2147483647.0;
+    }
+
     for (int i = 0; i < nr_nodes; i++) {
       for (int j = 0; j < nr_nodes; j++) {
         if (i != j) {
-          mpiuse_log_allocation(i, 1, k, SEND_TYPE, NO_SUBTYPE, 1, logsize, j,
+          mpiuse_log_allocation(i, 1, k, SEND_TYPE, NO_SUBTYPE, 1, (size_t)logsize, j,
                                 tag);
-          mpiuse_log_allocation(j, 1, k, RECV_TYPE, NO_SUBTYPE, 1, logsize, i,
+          mpiuse_log_allocation(j, 1, k, RECV_TYPE, NO_SUBTYPE, 1, (size_t)logsize, i,
                                 tag);
         }
       }
diff --git a/swiftmpifakestepsim.c b/swiftmpifakestepsim.c
index f5e0190..777531c 100644
--- a/swiftmpifakestepsim.c
+++ b/swiftmpifakestepsim.c
@@ -391,7 +391,8 @@ static void usage(char *argv[]) {
   fprintf(stderr, "Usage: %s [options] nr_messages logfile.dat\n", argv[0]);
   fprintf(stderr,
           " options: -v verbose, -d data check, -s size (bytes/scale), \n"
-          "\t -f randomize injection order, \n"
+          "\t -f <1|2> randomize injection order, 1 == just sends, "
+          "2 == sends and recvs\n"
           "\t[-r uniform random from 1 to size, | \n"
           "\t-r -g half gaussian random from 1 with 2.5 sigma size., | \n"
           "\t-r -c <file> use cdf from file, size is a scale factor., |\n"
-- 
GitLab