From c1f30119ee2abe953230bcb8c25b916c623afa92 Mon Sep 17 00:00:00 2001 From: "Peter W. Draper" <p.w.draper@durham.ac.uk> Date: Tue, 24 Sep 2019 17:43:32 +0100 Subject: [PATCH] Fix race condition, can increment no. of logs before assignment, so they need to be initially NULL --- swiftmpistepsim.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/swiftmpistepsim.c b/swiftmpistepsim.c index 68bef3b..394dea0 100644 --- a/swiftmpistepsim.c +++ b/swiftmpistepsim.c @@ -321,14 +321,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); + reqs_queue = (struct mpiuse_log_entry **)calloc( + nlogs, sizeof(struct mpiuse_log_entry *)); nr_reqs = 0; - sends_queue = (struct mpiuse_log_entry **)malloc( - sizeof(struct mpiuse_log_entry *) * nlogs); + sends_queue = (struct mpiuse_log_entry **)calloc( + nlogs, sizeof(struct mpiuse_log_entry *) * nlogs); nr_sends = 0; - recvs_queue = (struct mpiuse_log_entry **)malloc( - sizeof(struct mpiuse_log_entry *) * nlogs); + recvs_queue = (struct mpiuse_log_entry **)calloc( + nlogs, sizeof(struct mpiuse_log_entry *)); nr_recvs = 0; for (int k = 0; k < nlogs; k++) { @@ -354,8 +354,9 @@ static void pick_logs(void) { /* Check. */ for (int k = 0; k < nr_reqs - 1; k++) { - if (reqs_queue[k]->tic > reqs_queue[k+1]->tic) - message("reqs_queue: %lld > %lld", reqs_queue[k]->tic, reqs_queue[k+1]->tic); + if (reqs_queue[k]->tic > reqs_queue[k + 1]->tic) + message("reqs_queue: %lld > %lld", reqs_queue[k]->tic, + reqs_queue[k + 1]->tic); } } -- GitLab