Browse Source

Fix various things around the use of sched_ctx_lists. Also try to fix the problem shown by example sched_ctx.c

Terry Cojean 9 years ago
parent
commit
f8651e7c98

+ 2 - 1
examples/sched_ctx/sched_ctx_without_sched_policy.c

@@ -122,7 +122,8 @@ int main(int argc, char **argv)
 	/*create contexts however you want*/
 	unsigned sched_ctx1 = starpu_sched_ctx_create(procs1, nprocs1, "ctx1", 0);
 	unsigned sched_ctx2 = starpu_sched_ctx_create(procs2, nprocs2, "ctx2", 0);
-
+	starpu_sched_ctx_display_workers(sched_ctx1, stderr);
+	starpu_sched_ctx_display_workers(sched_ctx2, stderr);
 	int i;
 	for (i = 0; i < ntasks; i++)
 	{

+ 7 - 6
src/core/sched_ctx.c

@@ -73,8 +73,8 @@ void _starpu_worker_gets_out_of_ctx(unsigned sched_ctx_id, struct _starpu_worker
 		/* 	sched_ctx->sched_policy->remove_workers(sched_ctx_id, &worker->workerid, 1); */
 		/* 	_STARPU_TRACE_WORKER_SCHEDULING_POP; */
 		/* } */
-		_starpu_sched_ctx_list_remove(&worker->sched_ctx_list, sched_ctx_id);
-		worker->nsched_ctxs--;
+		if (!_starpu_sched_ctx_list_remove(&worker->sched_ctx_list, sched_ctx_id))
+			worker->nsched_ctxs--;
 	}
 	return;
 }
@@ -143,7 +143,7 @@ void starpu_sched_ctx_worker_shares_tasks_lists(int workerid, int sched_ctx_id)
 }
 
 static void _starpu_add_workers_to_sched_ctx(struct _starpu_sched_ctx *sched_ctx, int *workerids, int nworkers,
-				       int *added_workers, int *n_added_workers)
+					     int *added_workers, int *n_added_workers)
 {
 	struct starpu_worker_collection *workers = sched_ctx->workers;
 	struct _starpu_machine_config *config = (struct _starpu_machine_config *)_starpu_get_machine_config();
@@ -569,8 +569,8 @@ struct _starpu_sched_ctx* _starpu_create_sched_ctx(struct starpu_sched_policy *p
 		for(i = 0; i < nworkers; i++)
 		{
 			struct _starpu_worker *worker = _starpu_get_worker_struct(i);
-			_starpu_sched_ctx_list_add(&worker->sched_ctx_list, sched_ctx->id);
-			worker->nsched_ctxs++;
+			if(!_starpu_sched_ctx_list_add(&worker->sched_ctx_list, sched_ctx->id))
+				worker->nsched_ctxs++;
 		}
 	}
 
@@ -1994,12 +1994,13 @@ struct _starpu_sched_ctx *_starpu_sched_ctx_get_sched_ctx_for_worker_and_job(str
 {
 	struct _starpu_sched_ctx_elt *e = NULL;
 	struct _starpu_sched_ctx_list_iterator list_it;
+	struct _starpu_sched_ctx *sched_ctx = NULL;
 
 	_starpu_sched_ctx_list_iterator_init(worker->sched_ctx_list, &list_it);
 	while (_starpu_sched_ctx_list_iterator_has_next(&list_it))
 	{
 		e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
-		struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(e->sched_ctx);
+		sched_ctx = _starpu_get_sched_ctx_struct(e->sched_ctx);
 		if (j->task->sched_ctx == sched_ctx->id)
 			return sched_ctx;
 	}

+ 7 - 3
src/core/sched_ctx_list.c

@@ -233,7 +233,7 @@ struct _starpu_sched_ctx_elt* _starpu_sched_ctx_list_add_prio(struct _starpu_sch
 int _starpu_sched_ctx_list_add(struct _starpu_sched_ctx_list **list,
 			       unsigned sched_ctx)
 {
-	return _starpu_sched_ctx_list_add_prio(list, 0, sched_ctx) != NULL ? 0 : 1;
+	return _starpu_sched_ctx_list_add_prio(list, 0, sched_ctx) != NULL ? 0 : -1;
 }
 
 void _starpu_sched_ctx_list_remove_elt(struct _starpu_sched_ctx_list **list,
@@ -365,8 +365,12 @@ struct _starpu_sched_ctx_elt* _starpu_sched_ctx_list_iterator_get_next(struct _s
 			if (parent->next != NULL)
 			{
 				it->cursor = parent->next->head;
-				ret = parent->next->head;
-			} //else ret = NULL (end)
+				ret = it->cursor;
+			}
+			else
+			{
+				it->cursor = NULL;
+			}
 		}
 		else
 		{