From 82473678282711cad044aa7c4b9a42382a0713c1 Mon Sep 17 00:00:00 2001
From: "Peter W. Draper" <p.w.draper@durham.ac.uk>
Date: Tue, 10 Mar 2020 13:15:25 +0000
Subject: [PATCH] Also check sent data is unmodified

---
 swiftmpiproxies.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/swiftmpiproxies.c b/swiftmpiproxies.c
index 4de022a..e33e47e 100644
--- a/swiftmpiproxies.c
+++ b/swiftmpiproxies.c
@@ -266,7 +266,7 @@ int main(int argc, char *argv[]) {
     pcells_in[pid] = calloc(pcells_size[pid], 1);
 
     /* Fill data with a pattern for checking when overwritten. */
-    datacheck_fill(1, log->size, log->data);
+    datacheck_fill(1, pcells_size[pid], pcells_in[pid]);
     res = MPI_Irecv(pcells_in[pid], pcells_size[pid], MPI_BYTE, log->otherrank,
                     basetag + proxy_tag_cells, MPI_COMM_WORLD,
                     &req_pcells_in[pid]);
@@ -290,8 +290,8 @@ int main(int argc, char *argv[]) {
 
     /* Check the data received is correct. */
     struct mpiuse_log_entry *log = send_pcells[pid];
-    if (!datacheck_test(1, log->size, log->data)) {
-      if (datacheck_test(0, log->size, log->data)) {
+    if (!datacheck_test(0, pcells_size[pid], pcells_in[pid])) {
+      if (!datacheck_test(1, pcells_size[pid], pcells_in[pid])) {
         error("Received data is not modified");
       } else {
         error("Received data is corrupt");
@@ -299,6 +299,7 @@ int main(int argc, char *argv[]) {
     } else {
       message("Received data is correct");
     }
+    free(pcells_in[pid]);
   }
   message("All proxy cells have arrived");
 
@@ -306,6 +307,17 @@ int main(int argc, char *argv[]) {
   res = MPI_Waitall(nr_send_pcells, req_pcells_out, MPI_STATUSES_IGNORE);
   if (res != MPI_SUCCESS) error("Waitall for pcells Isend failed.");
 
+  /* Check data is unmodified. */
+  for (int k = 0; k < nr_send_pcells; k++) {
+    struct mpiuse_log_entry *log = send_pcells[k];
+    if (!datacheck_test(0, log->size, log->data)) {
+      error("Sent data has been corrupted");
+    } else {
+      message("Sent data is correct");
+    }
+    free(log->data);
+  }
+
   /* Shutdown MPI. */
   res = MPI_Finalize();
   if (res != MPI_SUCCESS)
-- 
GitLab