From 60a49236f17f1a08d639f0a7cfe14d9edbdc2486 Mon Sep 17 00:00:00 2001
From: Pedro Gonnet <pedro.gonnet@durham.ac.uk>
Date: Fri, 23 Aug 2013 13:07:42 +0000
Subject: [PATCH] re-weight tasks now and then.

Former-commit-id: 2f5875f45efac6042798dc065b852e9c42168493
---
 src/engine.c | 10 +++++++++-
 src/engine.h |  4 ++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/engine.c b/src/engine.c
index 163c4710f5..84157e0545 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -932,10 +932,13 @@ void engine_maketasks ( struct engine *e ) {
         
     /* Rank the tasks. */
     scheduler_ranktasks( sched );
-            
+    
     /* Weight the tasks. */
     scheduler_reweight( sched );
             
+    /* Set the tasks age. */
+    e->tasks_age = 0;
+            
     }
     
     
@@ -1158,6 +1161,11 @@ void engine_prepare ( struct engine *e ) {
     /* Did this not go through? */
     if ( rebuild )
         engine_rebuild( e );
+        
+    /* Re-rank the tasks every now and then. */
+    if ( e->tasks_age % engine_tasksreweight == 1 )
+        scheduler_reweight( &e->sched );
+    e->tasks_age += 1;
 
     /* Start the scheduler. */
     // ticks tic2 = getticks();
diff --git a/src/engine.h b/src/engine.h
index a9f6e6d254..98e0daab1c 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -34,6 +34,7 @@
 #define engine_queue_scale          1.2
 #define engine_maxtaskspercell      32
 #define engine_maxproxies           64
+#define engine_tasksreweight        10
 
 
 /* The rank of the engine as a global variable (for messages). */
@@ -94,6 +95,9 @@ struct engine {
     /* Force the engine to rebuild? */
     int forcerebuild, forcerepart;
     
+    /* How many steps have we done with the same set of tasks? */
+    int tasks_age;
+    
     };
 
 
-- 
GitLab