From bec906fd79d82d0da35c594eb5373decccf57c16 Mon Sep 17 00:00:00 2001
From: "Peter W. Draper" <p.w.draper@durham.ac.uk>
Date: Mon, 16 Sep 2019 17:54:45 +0100
Subject: [PATCH] Add the correct global communicators

---
 mpistalls.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/mpistalls.c b/mpistalls.c
index 75eec48..14b89b8 100644
--- a/mpistalls.c
+++ b/mpistalls.c
@@ -15,12 +15,16 @@
 #include "error.h"
 #include "mpiuse.h"
 
+/* Global: Our rank for all to see. */
+int myrank = -1;
+
 /* Integer types of send and recv tasks, must match log. */
-static int task_type_send = 22;
-static int task_type_recv = 23;
+static const int task_type_send = 22;
+static const int task_type_recv = 23;
 
-/* Our rank for all to see. */
-int myrank = -1;
+/* Global communicators for each of the subtypes. */
+static const int task_subtype_count = 30; // Just some upper limit on subtype.
+static MPI_Comm subtypeMPI_comms[30];
 
 /* The local queues. */
 static struct mpiuse_log_entry **volatile reqs_queue;
@@ -53,7 +57,7 @@ static void *inject_thread(void *arg) {
     int err = 0;
     if (log->type == task_type_send) {
       err = MPI_Isend(log->data, log->size, MPI_BYTE, log->otherrank,
-                      log->tag, MPI_COMM_WORLD, &log->req);
+                      log->tag, subtypeMPI_comms[log->subtype], &log->req);
 
       /* Add a new send request. */
       int ind = atomic_inc(&nr_sends);
@@ -62,7 +66,7 @@ static void *inject_thread(void *arg) {
 
     } else {
       err = MPI_Irecv(log->data, log->size, MPI_BYTE, log->rank,
-                      log->tag, MPI_COMM_WORLD, &log->req);
+                      log->tag, subtypeMPI_comms[log->subtype], &log->req);
 
       /* Add a new recv request. */
       int ind = atomic_inc(&nr_recvs);
@@ -223,6 +227,10 @@ int main(int argc, char *argv[]) {
   if (res != MPI_SUCCESS)
     error("Call to MPI_Comm_rank failed with error %i.", res);
 
+  /* Create communicators for each subtype of the tasks. */
+  for (int i = 0; i < task_subtype_count; i++) {
+    MPI_Comm_dup(MPI_COMM_WORLD, &subtypeMPI_comms[i]);
+  }
   message("Starts");
 
   /* Each rank requires its own queue, so extract them. */
-- 
GitLab