Skip to content
Snippets Groups Projects
Commit bc2d9889 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

use a sliding window to find the task with the highest overlap with the previous task.

parent c8f8bb0b
No related branches found
No related tags found
2 merge requests!136Master,!75Overlapping tasks
...@@ -126,15 +126,14 @@ void queue_init(struct queue *q, struct task *tasks) { ...@@ -126,15 +126,14 @@ void queue_init(struct queue *q, struct task *tasks) {
* @brief Get a task free of dependencies and conflicts. * @brief Get a task free of dependencies and conflicts.
* *
* @param q The task #queue. * @param q The task #queue.
* @param super The super-cell tat might conflict with the #queue * @param prev The previous #task extracted from this #queue.
* @param blocking Block until access to the queue is granted. * @param blocking Block until access to the queue is granted.
*/ */
struct task *queue_gettask(struct queue *q, struct cell *super, int blocking) { struct task *queue_gettask(struct queue *q, const struct task *prev, int blocking) {
int k, qcount, *qtid, gotcha;
lock_type *qlock = &q->lock; lock_type *qlock = &q->lock;
struct task *qtasks, *res = NULL; struct task *res = NULL;
/* If there are no tasks, leave immediately. */ /* If there are no tasks, leave immediately. */
if (q->count == 0) return NULL; if (q->count == 0) return NULL;
...@@ -147,49 +146,75 @@ struct task *queue_gettask(struct queue *q, struct cell *super, int blocking) { ...@@ -147,49 +146,75 @@ struct task *queue_gettask(struct queue *q, struct cell *super, int blocking) {
} }
/* Set some pointers we will use often. */ /* Set some pointers we will use often. */
qtid = q->tid; int *qtid = q->tid;
qtasks = q->tasks; struct task *qtasks = q->tasks;
qcount = q->count; const int qcount = q->count;
gotcha = 0;
/* Data for the sliding window in which to try the task with the
/* Loop over the task IDs looking for tasks with the same super-cell. */ best overlap with the previous task. */
if (super != NULL) { struct {
for (k = 0; k < qcount && k < queue_maxsuper; k++) { int ind, tid;
float score;
/* Put a finger on the task. */ } window[queue_search_window];
res = &qtasks[qtid[k]]; int window_count = 0;
int tid = -1;
/* Try to lock the task and exit if successful. */ int ind = -1;
if ((res->ci->super == super ||
(res->cj != NULL && res->cj->super == super)) && /* Loop over the queue entries. */
task_lock(res)) { for (int k = 0; k < qcount; k++) {
gotcha = 1; if (k < queue_search_window) {
window[window_count].ind = k;
window[window_count].tid = qtid[k];
window[window_count].score = task_overlap(prev, &qtasks[qtid[k]]);
window_count += 1;
} else {
/* Find the task with the largest overlap. */
int ind_max = 0;
for (int i = 1; i < window_count; i++)
if (window[i].score > window[ind_max].score) ind_max = i;
/* Try to lock that task. */
if (task_lock(&qtasks[window[ind_max].tid])) {
tid = window[ind_max].tid;
ind = window[ind_max].ind;
// message("best task has overlap %f.", window[ind_max].score);
break; break;
}
} /* loop over the task IDs. */ /* Otherwise, replace it with a new one from the queue. */
} else {
window[ind_max].ind = k;
window[ind_max].tid = qtid[k];
window[ind_max].score = task_overlap(prev, &qtasks[qtid[k]]);
}
}
} }
/* Loop over the task IDs again if nothing was found, take anything. */ /* If we didn't get a task, loop through whatever is left in the window. */
if (!gotcha) { if (tid < 0) {
for (k = 0; k < qcount; k++) { while (window_count > 0) {
int ind_max = 0;
/* Put a finger on the task. */ for (int i = 1; i < window_count; i++)
res = &qtasks[qtid[k]]; if (window[i].score > window[ind_max].score) ind_max = i;
if (task_lock(&qtasks[window[ind_max].tid])) {
/* Try to lock the task and exit if successful. */ tid = window[ind_max].tid;
if (task_lock(res)) break; ind = window[ind_max].ind;
// message("best task has overlap %f.", window[ind_max].score);
} /* loop over the task IDs. */ break;
} else {
window_count -= 1;
window[ind_max] = window[window_count];
}
}
} }
/* Did we get a task? */ /* Did we get a task? */
if (k < qcount) { if (ind >= 0) {
/* Another one bites the dust. */ /* Another one bites the dust. */
qcount = q->count -= 1; const int qcount = q->count -= 1;
/* Swap this task with the last task and re-heap. */ /* Swap this task with the last task and re-heap. */
int k = ind;
if (k < qcount) { if (k < qcount) {
qtid[k] = qtid[qcount]; qtid[k] = qtid[qcount];
int w = qtasks[qtid[k]].weight; int w = qtasks[qtid[k]].weight;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#define queue_maxsuper 50 #define queue_maxsuper 50
#define queue_sizeinit 100 #define queue_sizeinit 100
#define queue_sizegrow 2 #define queue_sizegrow 2
#define queue_search_window 8
/* Counters. */ /* Counters. */
enum { enum {
...@@ -54,7 +55,7 @@ struct queue { ...@@ -54,7 +55,7 @@ struct queue {
} __attribute__((aligned(64))); } __attribute__((aligned(64)));
/* Function prototypes. */ /* Function prototypes. */
struct task *queue_gettask(struct queue *q, struct cell *super, int blocking); struct task *queue_gettask(struct queue *q, const struct task *prev, int blocking);
void queue_init(struct queue *q, struct task *tasks); void queue_init(struct queue *q, struct task *tasks);
void queue_insert(struct queue *q, struct task *t); void queue_insert(struct queue *q, struct task *t);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment