From aa5c25df2b2d7b1290684f1ed7ae2da4956289f0 Mon Sep 17 00:00:00 2001
From: Pedro Gonnet <pedro.gonnet@durham.ac.uk>
Date: Fri, 5 Jul 2013 13:49:34 +0000
Subject: [PATCH] quit early if weight difference too large.

Former-commit-id: 1379eda80415dfb1210fddc902fabc2871b87f67
---
 src/queue.c | 7 ++++++-
 src/queue.h | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/queue.c b/src/queue.c
index d52a9ac2c4..382ec76fee 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -132,7 +132,7 @@ void queue_init ( struct queue *q , struct task *tasks ) {
  
 struct task *queue_gettask ( struct queue *q , struct cell *super , int blocking ) {
 
-    int k, temp, qcount, *qtid, gotcha;
+    int k, temp, qcount, *qtid, gotcha, maxweight;
     lock_type *qlock = &q->lock;
     struct task *qtasks, *res = NULL;
     
@@ -158,6 +158,7 @@ struct task *queue_gettask ( struct queue *q , struct cell *super , int blocking
         qtasks = q->tasks;
         qcount = q->count;
         gotcha = 0;
+        maxweight = qtasks[ qtid[0] ].weight;
             
         /* Loop over the task IDs looking for tasks with the same super-cell. */
         if ( super != NULL )
@@ -165,6 +166,10 @@ struct task *queue_gettask ( struct queue *q , struct cell *super , int blocking
 
                 /* Put a finger on the task. */
                 res = &qtasks[ qtid[k] ];
+                
+                /* Things getting too light? */
+                if ( res->weight * queue_maxrweight < maxweight )
+                    break;
 
                 /* Try to lock the task and exit if successful. */
                 if ( ( res->ci->super == super || ( res->cj != NULL && res->cj->super == super ) ) &&
diff --git a/src/queue.h b/src/queue.h
index 76ae9b6971..ac7efa145d 100644
--- a/src/queue.h
+++ b/src/queue.h
@@ -20,6 +20,7 @@
 
 /* Some constants. */
 #define queue_maxsuper           50
+#define queue_maxrweight         2
 #define queue_sizeinit           100
 #define queue_sizegrow           2
 
-- 
GitLab