From a64f50b22d2c7af2700fff7ca6e0f55453b6a80e Mon Sep 17 00:00:00 2001 From: Pedro Gonnet <gonnet@google.com> Date: Thu, 17 Mar 2016 22:24:45 +0100 Subject: [PATCH] only increase the waiting counter once the task is safely in a queue. --- src/scheduler.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/scheduler.c b/src/scheduler.c index 722e344b5a..f1fccc7f74 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -28,6 +28,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> /* MPI headers. */ #ifdef WITH_MPI @@ -986,8 +987,7 @@ void scheduler_start(struct scheduler *s, unsigned int mask, const int waiting_old = s->waiting; /* We are going to use the task structure in a modified way to pass - information - to the task. Don't do this at home ! + information to the task. Don't do this at home ! - ci and cj will give the range of tasks to which the waits will be applied - the flags will be used to transfer the mask - the rank will be used to transfer the submask @@ -1133,14 +1133,14 @@ void scheduler_enqueue(struct scheduler *s, struct task *t) { if (qid >= s->nr_queues) error("Bad computed qid."); - /* If no previous owner, find the shortest queue. */ + /* If no previous owner, pick a random queue. */ if (qid < 0) qid = rand() % s->nr_queues; - /* Increase the waiting counter. */ - atomic_inc(&s->waiting); - /* Insert the task into that queue. */ queue_insert(&s->queues[qid], t); + + /* Increase the waiting counter. */ + atomic_inc(&s->waiting); } } -- GitLab