Explorar o código

switch back to add_child and remove_child function for nodes
need brilliant and consistant idea to memoize undelaying workers

Simon Archipoff %!s(int64=12) %!d(string=hai) anos
pai
achega
8bab4b9aaa

+ 2 - 8
include/starpu_sched_node.h

@@ -77,14 +77,8 @@ struct starpu_sched_node
 	 */
 	void * data;
 
-	/* this function is called after all childs has been set, and the
-	 * workers member was filled, can be used to init data, or anything you want
-	 */
-	void (*init_data)(struct starpu_sched_node *);
-	/* this function is called to free data allocated by init_data
-	 * just before the call of starpu_sched_node_destroy(node)
-	 */
-	void (*deinit_data)(struct starpu_sched_node *);
+	void (*add_child)(struct starpu_sched_node * node, struct starpu_sched_node * child);
+	void (*remove_child)(struct starpu_sched_node * node, struct starpu_sched_node * child);
 
 #ifdef STARPU_HAVE_HWLOC
 	/* in case of a hierarchical scheduler, this is set to the part of

+ 6 - 6
src/sched_policies/node_best_implementation.c

@@ -4,7 +4,7 @@
 /* set implementation, task->predicted and task->predicted_transfer with the first worker of workers that can execute that task
  * or have to be calibrated
  */
-static void select_best_implementation_and_set_preds(struct starpu_bitmap * workers, struct starpu_task * task, int calibrating)
+static void select_best_implementation_and_set_preds(struct starpu_bitmap * workers, struct starpu_task * task)
 {
 	int best_impl = -1;
 	double len = DBL_MAX;
@@ -20,7 +20,7 @@ static void select_best_implementation_and_set_preds(struct starpu_bitmap * work
 			{
 				enum starpu_perfmodel_archtype archtype = starpu_worker_get_perf_archtype(workerid);
 				double d = starpu_task_expected_length(task, archtype, impl);
-				if(calibrating && isnan(d))
+				if(isnan(d))
 				{
 					best_impl = impl;
 					len = 0.0;
@@ -48,7 +48,7 @@ static void select_best_implementation_and_set_preds(struct starpu_bitmap * work
 static int select_best_implementation_push_task(struct starpu_sched_node * node, struct starpu_task * task)
 {
 	STARPU_ASSERT(node->nchilds == 1);
-	select_best_implementation_and_set_preds(node->workers_in_ctx, task, 0);
+	select_best_implementation_and_set_preds(node->workers_in_ctx, task);
 	return node->childs[0]->push_task(node->childs[0],task);
 }
 
@@ -60,7 +60,7 @@ static struct starpu_task * select_best_implementation_pop_task(struct starpu_sc
 		return NULL;
 	t = node->fathers[sched_ctx_id]->pop_task(node->fathers[sched_ctx_id], sched_ctx_id);
 	if(t)
-		select_best_implementation_and_set_preds(node->workers_in_ctx, t,0);
+		select_best_implementation_and_set_preds(node->workers_in_ctx, t);
 	return t;
 }
 
@@ -69,7 +69,7 @@ static struct starpu_task * select_best_implementation_pop_task(struct starpu_sc
 static int select_calibration_push_task(struct starpu_sched_node * node, struct starpu_task * task)
 {
 	STARPU_ASSERT(node->nchilds == 1);
-	select_best_implementation_and_set_preds(node->workers_in_ctx, task, 1);
+	select_best_implementation_and_set_preds(node->workers_in_ctx, task);
 	return node->childs[0]->push_task(node->childs[0],task);
 }
 
@@ -80,7 +80,7 @@ static struct starpu_task * select_calibration_pop_task(struct starpu_sched_node
 		return NULL;
 	t = node->fathers[sched_ctx_id]->pop_task(node->fathers[sched_ctx_id], sched_ctx_id);
 	if(t)
-		select_best_implementation_and_set_preds(node->workers_in_ctx, t, 1);
+		select_best_implementation_and_set_preds(node->workers_in_ctx, t);
 	return t;
 }
 

+ 0 - 5
src/sched_policies/node_composed.c

@@ -127,8 +127,6 @@ void composed_node_init_data(struct starpu_sched_node *node)
 );
 	c->bottom->nchilds = node->nchilds;
 	c->bottom->childs = node->childs;
-
-	node->init_data = NULL;
 }
 
 void composed_node_deinit_data(struct starpu_sched_node * _node)
@@ -141,7 +139,6 @@ void composed_node_deinit_data(struct starpu_sched_node * _node)
 	do
 	{
 		node->workers = NULL;
-		node->deinit_data(node);
 		next = node->childs ? node->childs[0] : NULL;
 		starpu_sched_node_destroy(node);
 	}while(next);
@@ -162,8 +159,6 @@ struct starpu_sched_node * starpu_sched_node_composed_node_create(struct _starpu
 	node->pop_task = composed_node_pop_task;
 	node->available = composed_node_available;
 	node->estimated_load = composed_node_estimated_load;
-	node->init_data = composed_node_init_data;
-	node->deinit_data = composed_node_deinit_data;
 
 	return node;
 }

+ 1 - 3
src/sched_policies/node_eager.c

@@ -19,10 +19,8 @@ static void initialize_eager_center_policy(unsigned sched_ctx_id)
 		if(!node)
 			continue;
 		node->fathers[sched_ctx_id] = data->root;
-		starpu_sched_node_add_child(data->root, node);
+		data->root->add_child(data->root, node);
 	}
-	_starpu_set_workers_bitmaps();
-	starpu_sched_tree_call_init_data(data);
 	starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)data);
 }
 

+ 5 - 43
src/sched_policies/node_fifo.c

@@ -123,59 +123,21 @@ static struct starpu_task * pop_task(struct starpu_sched_node * node, unsigned s
 		return father->pop_task(father,sched_ctx_id);
 	return NULL;
 }
-/*
-struct starpu_task_list  starpu_sched_node_fifo_get_non_executable_tasks(struct starpu_sched_node * node)
-{
-	struct starpu_task_list list;
-	starpu_task_list_init(&list);
-	struct _starpu_fifo_data * data = node->data;
-	struct _starpu_prio_deque * fifo = data->fifo;
-	struct starpu_task * task;
-	for (task  = starpu_task_list_begin(&fifo->taskq);
-	     task != starpu_task_list_end(&fifo->taskq);
-	     task  = starpu_task_list_next(task))
-	{
-		STARPU_ASSERT(task);
-		if(!starpu_sched_node_can_execute_task(node, task))
-		{
-			starpu_task_list_erase(&fifo->taskq, task);
-			starpu_task_list_push_front(&list, task);
-			fifo->ntasks--;
-		}
-	}
-	return list;
-}
-*/
-void init_fifo_data(struct starpu_sched_node * node)
-{
-	STARPU_ASSERT(starpu_sched_node_is_fifo(node));
-	struct _starpu_fifo_data * data = malloc(sizeof(*data));
-	_starpu_prio_deque_init(&data->fifo);
-	STARPU_PTHREAD_MUTEX_INIT(&data->mutex,NULL);
-	node->data = data;
-	node->init_data = NULL;
-}
-void deinit_fifo_data(struct starpu_sched_node * node)
-{
-	struct _starpu_fifo_data * data = node->data;
-	STARPU_PTHREAD_MUTEX_DESTROY(&data->mutex);
-	_starpu_prio_deque_destroy(&data->fifo);
-	free(data);
-}
-
 
 int starpu_sched_node_is_fifo(struct starpu_sched_node * node)
 {
-	return node->deinit_data == deinit_fifo_data;
+	return node->push_task == push_task;
 }
 
 struct starpu_sched_node * starpu_sched_node_fifo_create(void * arg STARPU_ATTRIBUTE_UNUSED)
 {
 	struct starpu_sched_node * node = starpu_sched_node_create();
+	struct _starpu_fifo_data * data = malloc(sizeof(*data));
+	_starpu_prio_deque_init(&data->fifo);
+	STARPU_PTHREAD_MUTEX_INIT(&data->mutex,NULL);
+	node->data = data;
 	node->estimated_end = fifo_estimated_end;
 	node->estimated_load = estimated_load;
-	node->init_data = init_fifo_data;
-	node->deinit_data = deinit_fifo_data;
 	node->push_task = push_task;
 	node->pop_task = pop_task;
 	return node;

+ 55 - 91
src/sched_policies/node_heft.c

@@ -120,37 +120,26 @@ static void param_modified(struct starpu_top_param* d)
 }
 #endif /* !STARPU_USE_TOP */
 
-void init_heft_data(struct starpu_sched_node *node)
+void _heft_add_child(struct starpu_sched_node * node, struct starpu_sched_node * child)
 {
+	starpu_sched_node_add_child(node, child);
+	struct _starpu_heft_data * data = node->data;
+	starpu_sched_node_add_child(data->no_perf_model_node,child);
+	starpu_sched_node_add_child(data->calibrating_node, child);
+}
 
-	const char *strval_alpha = getenv("STARPU_SCHED_ALPHA");
-	if (strval_alpha)
-		alpha = atof(strval_alpha);
-
-	const char *strval_beta = getenv("STARPU_SCHED_BETA");
-	if (strval_beta)
-		beta = atof(strval_beta);
-
-	const char *strval_gamma = getenv("STARPU_SCHED_GAMMA");
-	if (strval_gamma)
-		_gamma = atof(strval_gamma);
-
-	const char *strval_idle_power = getenv("STARPU_IDLE_POWER");
-	if (strval_idle_power)
-		idle_power = atof(strval_idle_power);
+void _heft_remove_child(struct starpu_sched_node * node, struct starpu_sched_node * child)
+{
+	starpu_sched_node_remove_child(node, child);
+	struct _starpu_heft_data * data = node->data;
+	starpu_sched_node_remove_child(data->no_perf_model_node,child);
+	starpu_sched_node_remove_child(data->calibrating_node, child);
+}
 
-#ifdef STARPU_USE_TOP
-	starpu_top_register_parameter_float("DMDA_ALPHA", &alpha,
-					    alpha_minimum, alpha_maximum, param_modified);
-	starpu_top_register_parameter_float("DMDA_BETA", &beta,
-					    beta_minimum, beta_maximum, param_modified);
-	starpu_top_register_parameter_float("DMDA_GAMMA", &_gamma,
-					    gamma_minimum, gamma_maximum, param_modified);
-	starpu_top_register_parameter_float("DMDA_IDLE_POWER", &idle_power,
-					    idle_power_minimum, idle_power_maximum, param_modified);
-#endif /* !STARPU_USE_TOP */
+struct starpu_sched_node * starpu_sched_node_heft_create(struct starpu_heft_data * params)
+{
+	struct starpu_sched_node * node = starpu_sched_node_create();
 
-	struct starpu_heft_data * params = node->data;
 	struct _starpu_heft_data * data = malloc(sizeof(*data));
 	data->alpha = params->alpha;
 	data->beta = params->beta;
@@ -158,57 +147,20 @@ void init_heft_data(struct starpu_sched_node *node)
 	data->idle_power = params->idle_power;
 
 	data->no_perf_model_node = params->no_perf_model_node_create(params->arg_no_perf_model);
-	data->calibrating_node = params->calibrating_node_create(params->arg_calibrating_node);
-
-	int i;
-	for(i = 0; i < node->nchilds; i++)
-	{
-		starpu_sched_node_add_child(data->no_perf_model_node, node->childs[i]);
-		starpu_sched_node_add_child(data->calibrating_node, node->childs[i]);
-	}
-	starpu_bitmap_destroy(data->no_perf_model_node->workers_in_ctx);
 	starpu_bitmap_destroy(data->no_perf_model_node->workers);
-	data->no_perf_model_node->workers_in_ctx = node->workers_in_ctx;
+	starpu_bitmap_destroy(data->no_perf_model_node->workers_in_ctx);
 	data->no_perf_model_node->workers = node->workers;
+	data->no_perf_model_node->workers_in_ctx = node->workers_in_ctx;
 
+	data->calibrating_node = params->calibrating_node_create(params->arg_calibrating_node);
 	starpu_bitmap_destroy(data->calibrating_node->workers);
 	starpu_bitmap_destroy(data->calibrating_node->workers_in_ctx);
-	data->calibrating_node->workers = data->calibrating_node->workers_in_ctx = node->workers;
-
-	data->no_perf_model_node->init_data(data->no_perf_model_node);
-	data->calibrating_node->init_data(data->calibrating_node);
-
-	node->data = data;
-	node->init_data = NULL;
-}
-
-
-void deinit_heft_data(struct starpu_sched_node * node)
-{
-	struct _starpu_heft_data * data = node->data;
-	data->calibrating_node->workers = NULL;
-	data->calibrating_node->workers_in_ctx = NULL;
-
-	data->no_perf_model_node->workers = NULL;
-	data->no_perf_model_node->workers_in_ctx = NULL;
-
-	data->calibrating_node->deinit_data(data->calibrating_node);
-	data->no_perf_model_node->deinit_data(data->no_perf_model_node);
-
-	starpu_sched_node_destroy(data->no_perf_model_node);
-	starpu_sched_node_destroy(data->calibrating_node);
-
-	free(node->data);
-}
-
-
-struct starpu_sched_node * starpu_sched_node_heft_create(struct starpu_heft_data * data)
-{
-	struct starpu_sched_node * node = starpu_sched_node_create();
+	data->calibrating_node->workers = node->workers;
+	data->calibrating_node->workers_in_ctx = node->workers_in_ctx;
 
 	node->push_task = push_task;
-	node->init_data = init_heft_data;
-	node->deinit_data = deinit_heft_data;
+	node->add_child = _heft_add_child;
+	node->remove_child = _heft_remove_child;
 	node->data = data;
 
 	return node;
@@ -216,7 +168,7 @@ struct starpu_sched_node * starpu_sched_node_heft_create(struct starpu_heft_data
 
 int starpu_sched_node_is_heft(struct starpu_sched_node * node)
 {
-	return node->deinit_data == deinit_heft_data;
+	return node->push_task == push_task;
 }
 
 
@@ -224,15 +176,41 @@ int starpu_sched_node_is_heft(struct starpu_sched_node * node)
 static void initialize_heft_center_policy(unsigned sched_ctx_id)
 {
 	starpu_sched_ctx_create_worker_collection(sched_ctx_id, STARPU_WORKER_LIST);
+	const char *strval_alpha = getenv("STARPU_SCHED_ALPHA");
+	if (strval_alpha)
+		alpha = atof(strval_alpha);
+
+	const char *strval_beta = getenv("STARPU_SCHED_BETA");
+	if (strval_beta)
+		beta = atof(strval_beta);
+
+	const char *strval_gamma = getenv("STARPU_SCHED_GAMMA");
+	if (strval_gamma)
+		_gamma = atof(strval_gamma);
+
+	const char *strval_idle_power = getenv("STARPU_IDLE_POWER");
+	if (strval_idle_power)
+		idle_power = atof(strval_idle_power);
+
+#ifdef STARPU_USE_TOP
+	starpu_top_register_parameter_float("DMDA_ALPHA", &alpha,
+					    alpha_minimum, alpha_maximum, param_modified);
+	starpu_top_register_parameter_float("DMDA_BETA", &beta,
+					    beta_minimum, beta_maximum, param_modified);
+	starpu_top_register_parameter_float("DMDA_GAMMA", &_gamma,
+					    gamma_minimum, gamma_maximum, param_modified);
+	starpu_top_register_parameter_float("DMDA_IDLE_POWER", &idle_power,
+					    idle_power_minimum, idle_power_maximum, param_modified);
+#endif /* !STARPU_USE_TOP */
+
 	
 	struct starpu_sched_tree * t = starpu_sched_tree_create();
-	struct starpu_sched_node * random = starpu_sched_node_random_create(NULL);
 	struct starpu_heft_data data =
 		{
-			.alpha = 1.0,
-			.beta = 1.0,
-			.gamma = 1.0,
-			.idle_power = 200,
+			.alpha = alpha,
+			.beta = beta,
+			.gamma = _gamma,
+			.idle_power = idle_power,
 			.no_perf_model_node_create = starpu_sched_node_random_create,
 			. arg_no_perf_model = NULL,
 			.calibrating_node_create = starpu_sched_node_random_create,
@@ -252,22 +230,9 @@ static void initialize_heft_center_policy(unsigned sched_ctx_id)
 
 		starpu_sched_node_add_child(t->root, impl_node);
 		starpu_sched_node_set_father(impl_node, t->root, sched_ctx_id);
-
-
-		struct starpu_sched_node * calibration_node = starpu_sched_node_calibration_create(NULL);
-		starpu_sched_node_add_child(calibration_node, worker_node);
-		calibration_node->workers_in_ctx = impl_node->workers;
-		starpu_sched_node_add_child(random, calibration_node);
-
-
 	}
 
 	starpu_sched_node_init_rec(t->root);
-	starpu_sched_node_init_rec(random);
-//	_starpu_set_workers_bitmaps();
-//	starpu_sched_tree_call_init_data(t);
-	starpu_bitmap_destroy(random->workers_in_ctx);
-	random->workers_in_ctx = t->root->workers_in_ctx;
 	starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)t);
 }
 
@@ -281,7 +246,6 @@ static void deinitialize_heft_center_policy(unsigned sched_ctx_id)
 
 
 
-
 struct starpu_sched_policy _starpu_sched_tree_heft_policy =
 {
 	.init_sched = initialize_heft_center_policy,

+ 18 - 51
src/sched_policies/node_random.c

@@ -1,67 +1,41 @@
 #include <core/workers.h>
 #include <starpu_sched_node.h>
 
-struct _starpu_random_data
-{
-	double * relative_speedup;
-};
-
-
 static double compute_relative_speedup(struct starpu_sched_node * node)
 {
-	if(starpu_sched_node_is_simple_worker(node))
+	double sum = 0.0;
+	int id;
+	for(id = starpu_bitmap_first(node->workers_in_ctx);
+	    id != -1;
+	    id = starpu_bitmap_next(node->workers_in_ctx, id))
 	{
-		int id = starpu_sched_node_worker_get_workerid(node);
 		enum starpu_perfmodel_archtype perf_arch = starpu_worker_get_perf_archtype(id);
-		return starpu_worker_get_relative_speedup(perf_arch);
-	}
-	if(starpu_sched_node_is_combined_worker(node))
-	{
-		struct _starpu_combined_worker * c = starpu_sched_node_combined_worker_get_combined_worker(node);
-		return starpu_worker_get_relative_speedup(c->perf_arch);
-		
+		sum += starpu_worker_get_relative_speedup(perf_arch);
+
 	}
-	double sum = 0.0;
-	int i;
-	for(i = 0; i < node->nchilds; i++)
-		sum += compute_relative_speedup(node->childs[i]);
+	STARPU_ASSERT(sum != 0.0);
 	return sum;
 }
 
-static void init_data_random(struct starpu_sched_node * node)
-{
-	struct _starpu_random_data * rd = malloc(sizeof(struct _starpu_random_data));
-	node->data = rd;
-	rd->relative_speedup = malloc(sizeof(double) * node->nchilds);
-	int i;
-	for(i = 0; i < node->nchilds; i++)
-		rd->relative_speedup[i] = compute_relative_speedup(node->childs[i]);
-	node->init_data = NULL;
-}
-
-static void deinit_data_random(struct starpu_sched_node * node)
-{
-	struct _starpu_random_data * rd = node->data;
-	free(rd->relative_speedup);
-	free(rd);
-	
-}
 
 static int push_task(struct starpu_sched_node * node, struct starpu_task * task)
 {
-	struct _starpu_random_data * rd = node->data;
-
 	int indexes_nodes[node->nchilds];
+	double speedup[node->nchilds];
 	int size=0,i;
 	double alpha_sum = 0.0;
 	for(i = 0; i < node->nchilds ; i++)
 	{
 		if(starpu_sched_node_can_execute_task(node->childs[i],task))
 		{
-			indexes_nodes[size++] = i;
-			alpha_sum += rd->relative_speedup[i];
+			speedup[size] = compute_relative_speedup(node->childs[i]);
+			alpha_sum += speedup[size];
+			indexes_nodes[size] = i;
+			size++;
 		}
 	}
+	if(size == 0)
+		return -ENODEV;
 
 	double random = starpu_drand48()*alpha_sum;
 	double alpha = 0.0;
@@ -70,12 +44,12 @@ static int push_task(struct starpu_sched_node * node, struct starpu_task * task)
 	for(i = 0; i < size ; i++)
 	{
 		int index = indexes_nodes[i];
-		if(alpha + rd->relative_speedup[index] >= random)
+		if(alpha + speedup[i] >= random)
 		{	
 			select = node->childs[index];
 			break;
 		}
-		alpha += rd->relative_speedup[index];
+		alpha += speedup[i];
 	}
 	STARPU_ASSERT(select != NULL);
 	int ret_val = select->push_task(select,task);
@@ -84,7 +58,6 @@ static int push_task(struct starpu_sched_node * node, struct starpu_task * task)
 	return ret_val;
 }
 
-
 double random_estimated_end(struct starpu_sched_node * node)
 {
 	double sum = 0.0;
@@ -96,18 +69,14 @@ double random_estimated_end(struct starpu_sched_node * node)
 struct starpu_sched_node * starpu_sched_node_random_create(void * arg STARPU_ATTRIBUTE_UNUSED)
 {
 	struct starpu_sched_node * node = starpu_sched_node_create();
-	node->data = NULL;
-	node->init_data = init_data_random;
 	node->estimated_end = random_estimated_end;
-	node->deinit_data = deinit_data_random;
 	node->push_task = push_task;
-	starpu_srand48(time(NULL));
 	return node;
 }
 
 int starpu_sched_node_is_random(struct starpu_sched_node *node)
 {
-	return node->deinit_data == deinit_data_random;
+	return node->push_task == push_task;
 }
 
 
@@ -128,8 +97,6 @@ static void initialize_random_center_policy(unsigned sched_ctx_id)
 		node->fathers[sched_ctx_id] = data->root;
 		starpu_sched_node_add_child(data->root, node);
 	}
-	_starpu_set_workers_bitmaps();
-	starpu_sched_tree_call_init_data(data);
 	starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)data);
 }
 static void deinitialize_random_center_policy(unsigned sched_ctx_id)

+ 2 - 23
src/sched_policies/node_sched.c

@@ -155,8 +155,6 @@ void starpu_sched_node_destroy_rec(struct starpu_sched_node * node, unsigned sch
 			if(!shared)//if not shared we want to destroy it and his childs
 				PUSH(child);
 		}
-		if(n->deinit_data)
-			n->deinit_data(n);
 		starpu_sched_node_destroy(n);
 	}
 	free(stack);
@@ -390,8 +388,8 @@ struct starpu_sched_node * starpu_sched_node_create(void)
 	node->workers = starpu_bitmap_create();
 	node->workers_in_ctx = starpu_bitmap_create();
 	node->available = available;
-	node->init_data = take_node_and_does_nothing;
-	node->deinit_data = take_node_and_does_nothing;
+	node->add_child = starpu_sched_node_add_child;
+	node->remove_child = starpu_sched_node_remove_child;
 	node->pop_task = pop_task_node;
 	node->estimated_load = estimated_load;
 	node->estimated_end = _starpu_sched_node_estimated_end_min;
@@ -450,8 +448,6 @@ void starpu_sched_node_init_rec(struct starpu_sched_node * node)
 	for(i = 0; i < node->nchilds; i++)
 		starpu_bitmap_or(node->workers, node->childs[i]->workers);
 	set_is_homogeneous(node);
-	if(node->init_data)
-		node->init_data(node);
 }
 
 
@@ -479,29 +475,12 @@ void _starpu_set_workers_bitmaps(void)
 	}
 }
 
-static void helper_starpu_call_init_data(struct starpu_sched_node *node)
-{
-	int i;
-	for(i = 0; i < node->nchilds; i++)
-		helper_starpu_call_init_data(node->childs[i]);
-	if(node->init_data)
-		node->init_data(node);
-}
-
-void starpu_sched_tree_call_init_data(struct starpu_sched_tree * t)
-{
-	helper_starpu_call_init_data(t->root);
-}
-
 
 static int push_task_to_first_suitable_parent(struct starpu_sched_node * node, struct starpu_task * task, int sched_ctx_id)
 {
 	if(node == NULL || node->fathers[sched_ctx_id] == NULL)
 		return 1;
 
-//	struct starpu_sched_tree *t = starpu_sched_ctx_get_policy_data(sched_ctx_id);
-
-	
 	struct starpu_sched_node * father = node->fathers[sched_ctx_id];
 	if(starpu_sched_node_can_execute_task(father,task))
 		return father->push_task(father, task);

+ 64 - 53
src/sched_policies/node_work_stealing.c

@@ -11,8 +11,9 @@ struct _starpu_work_stealing_data
 	unsigned performed_total;
 	unsigned last_pop_child;
 	unsigned last_push_child;
-	struct _starpu_prio_deque * fifos;	
-	starpu_pthread_mutex_t * mutexes;
+	struct _starpu_prio_deque ** fifos;	
+	starpu_pthread_mutex_t ** mutexes;
+	int size;
 };
 
 
@@ -30,10 +31,10 @@ static struct starpu_task *  steal_task_round_robin(struct starpu_sched_node *no
 	struct starpu_task * task = NULL;
 	while (1)
 	{
-		struct _starpu_prio_deque * fifo = wsd->fifos + i;
-		STARPU_PTHREAD_MUTEX_LOCK(wsd->mutexes + i);
+		struct _starpu_prio_deque * fifo = wsd->fifos[i];
+		STARPU_PTHREAD_MUTEX_LOCK(wsd->mutexes[i]);
 		task = _starpu_prio_deque_deque_task_for_worker(fifo, workerid);
-		STARPU_PTHREAD_MUTEX_UNLOCK(wsd->mutexes + i);
+		STARPU_PTHREAD_MUTEX_UNLOCK(wsd->mutexes[i]);
 		if(task)
 		{
 			fifo->nprocessed--;
@@ -103,17 +104,17 @@ static struct starpu_task * pop_task(struct starpu_sched_node * node, unsigned s
 	}
 	STARPU_ASSERT(i < node->nchilds);
 	struct _starpu_work_stealing_data * wsd = node->data;
-	STARPU_PTHREAD_MUTEX_LOCK(wsd->mutexes + i);
-	struct starpu_task * task = _starpu_prio_deque_pop_task(wsd->fifos + i);
-	STARPU_PTHREAD_MUTEX_UNLOCK(wsd->mutexes + i);
+	STARPU_PTHREAD_MUTEX_LOCK(wsd->mutexes[i]);
+	struct starpu_task * task = _starpu_prio_deque_pop_task(wsd->fifos[i]);
+	STARPU_PTHREAD_MUTEX_UNLOCK(wsd->mutexes[i]);
 	if(task)
 		return task;
 	task  = steal_task(node, workerid);
 	if(task)
 	{
-		STARPU_PTHREAD_MUTEX_LOCK(wsd->mutexes + i);
-		wsd->fifos[i].nprocessed++;
-		STARPU_PTHREAD_MUTEX_UNLOCK(wsd->mutexes + i);
+		STARPU_PTHREAD_MUTEX_LOCK(wsd->mutexes[i]);
+		wsd->fifos[i]->nprocessed++;
+		STARPU_PTHREAD_MUTEX_UNLOCK(wsd->mutexes[i]);
 		return task;
 	}
 	if(node->fathers[sched_ctx_id])
@@ -128,15 +129,14 @@ static int push_task(struct starpu_sched_node * node, struct starpu_task * task)
 {
 	struct _starpu_work_stealing_data * wsd = node->data;
 	int ret = -1;
-	int start = wsd->last_push_child;
-	int i = start;
+	int i = wsd->last_push_child;
 	i = (i+1)%node->nchilds;
 
-	STARPU_PTHREAD_MUTEX_LOCK(wsd->mutexes + i);
-	ret = _starpu_prio_deque_push_task(wsd->fifos + i, task);
-	STARPU_PTHREAD_MUTEX_UNLOCK(wsd->mutexes + i);
+	STARPU_PTHREAD_MUTEX_LOCK(wsd->mutexes[i]);
+	ret = _starpu_prio_deque_push_task(wsd->fifos[i], task);
+	STARPU_PTHREAD_MUTEX_UNLOCK(wsd->mutexes[i]);
 
-	wsd->last_push_child = (start + 1) % node->nchilds;
+	wsd->last_push_child = i;
 	node->available(node);
 	return ret;
 }
@@ -163,9 +163,9 @@ int _starpu_ws_push_task(struct starpu_task *task)
 			STARPU_ASSERT(i < node->nchilds);
 			
 			struct _starpu_work_stealing_data * wsd = node->data;
-			STARPU_PTHREAD_MUTEX_LOCK(wsd->mutexes + i);
-			int ret = _starpu_prio_deque_push_task(wsd->fifos + i , task);
-			STARPU_PTHREAD_MUTEX_UNLOCK(wsd->mutexes + i);
+			STARPU_PTHREAD_MUTEX_LOCK(wsd->mutexes[i]);
+			int ret = _starpu_prio_deque_push_task(wsd->fifos[i] , task);
+			STARPU_PTHREAD_MUTEX_UNLOCK(wsd->mutexes[i]);
 			
 			//we need to wake all workers
 			int j;
@@ -185,57 +185,70 @@ int _starpu_ws_push_task(struct starpu_task *task)
 }
 
 
-static void init_ws_data(struct starpu_sched_node *node)
-{
-	struct _starpu_work_stealing_data * wsd = malloc(sizeof(*wsd));
-	memset(wsd, 0, sizeof(*wsd));
-	node->data = wsd;
-	int i;
-	for(i = 0; i < node->nchilds; i++){
-		STARPU_ASSERT(node->childs[i] != node);
-		STARPU_ASSERT(node->childs[i] != NULL);
-	}
-	int size = node->nchilds;
-	wsd->fifos = malloc(sizeof(struct _starpu_prio_deque) * size);
-	wsd->mutexes = malloc(sizeof(starpu_pthread_rwlock_t) * size);
 
-	for(i = 0; i < size; i++)
+void _ws_add_child(struct starpu_sched_node * node, struct starpu_sched_node * child)
+{
+	struct _starpu_work_stealing_data * wsd = node->data;
+	starpu_sched_node_add_child(node, child);
+	if(wsd->size < node->nchilds)
 	{
-		_starpu_prio_deque_init(wsd->fifos + i);
-		STARPU_PTHREAD_MUTEX_INIT(wsd->mutexes + i, NULL);
+		STARPU_ASSERT(wsd->size == node->nchilds - 1);
+		wsd->fifos = realloc(wsd->fifos, node->nchilds * sizeof(*wsd->fifos));
+		wsd->mutexes = realloc(wsd->mutexes, node->nchilds * sizeof(*wsd->mutexes));
+		wsd->size = node->nchilds;
 	}
-	node->init_data = NULL;
+
+	struct _starpu_prio_deque * fifo = malloc(sizeof(*fifo));
+	_starpu_prio_deque_init(fifo);
+	wsd->fifos[node->nchilds - 1] = fifo;
+
+	starpu_pthread_mutex_t * mutex = malloc(sizeof(*mutex));
+	STARPU_PTHREAD_MUTEX_INIT(mutex,NULL);
+	wsd->mutexes[node->nchilds - 1] = mutex;
 }
 
-static void deinit_ws_data(struct starpu_sched_node *node)
+void _ws_remove_child(struct starpu_sched_node * node, struct starpu_sched_node * child)
 {
 	struct _starpu_work_stealing_data * wsd = node->data;
-	int i;
-	for(i = 0; i < node->nchilds; i++)
+
+	STARPU_PTHREAD_MUTEX_DESTROY(wsd->mutexes[node->nchilds - 1]);
+	free(wsd->mutexes[node->nchilds - 1]);
+
+	int i_node;
+	for(i_node = 0; i_node < node->nchilds; i_node++)
 	{
-		STARPU_PTHREAD_MUTEX_DESTROY(wsd->mutexes + i);
-		_starpu_prio_deque_destroy(wsd->fifos + i);
+		if(node->childs[i_node] == child)
+			break;
 	}
-	free(wsd->mutexes);
-	free(wsd->fifos);
-	free(wsd);
-	node->data = NULL;
-}
+	STARPU_ASSERT(i_node != node->nchilds);
+	struct _starpu_prio_deque * tmp_fifo = wsd->fifos[i_node];
+	wsd->fifos[i_node] = wsd->fifos[node->nchilds - 1];
 
+	
+	node->childs[i_node] = node->childs[node->nchilds - 1];
+	node->nchilds--;
+	struct starpu_task * task;
+	while((task = _starpu_prio_deque_pop_task(tmp_fifo)))
+		node->push_task(node, task);
+	_starpu_prio_deque_destroy(tmp_fifo);
+	free(tmp_fifo);
+}
 
 struct starpu_sched_node * starpu_sched_node_work_stealing_create(void)
 {
 	struct starpu_sched_node * node = starpu_sched_node_create();
+	struct _starpu_work_stealing_data * wsd = malloc(sizeof(*wsd));
+	memset(wsd, 0, sizeof(*wsd));
 	node->pop_task = pop_task;
-	node->init_data = init_ws_data;
-	node->deinit_data = deinit_ws_data;
 	node->push_task = push_task;
-	return node;
+	node->add_child = _ws_add_child;
+	node->remove_child = _ws_remove_child;
+	return  node;
 }
 
 int starpu_sched_node_is_work_stealing(struct starpu_sched_node * node)
 {
-	return node->deinit_data == deinit_ws_data;
+	return node->push_task == push_task;
 }
 
 
@@ -257,8 +270,6 @@ static void initialize_ws_center_policy(unsigned sched_ctx_id)
 		node->fathers[sched_ctx_id] = ws;
 		starpu_sched_node_add_child(ws, node);
 	}
-	_starpu_set_workers_bitmaps();
-	starpu_sched_tree_call_init_data(data);
 	starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)data);
 }
 

+ 1 - 18
src/sched_policies/node_worker.c

@@ -210,7 +210,7 @@ static inline struct starpu_task * _starpu_worker_task_list_pop(struct _starpu_w
 			struct starpu_task * task = t->task;
 			t->task = NULL;
 			int * p = t->left ? t->pntasks : &t->ntasks;
-			STARPU_ATOMIC_ADD(p, -1);
+			(void) STARPU_ATOMIC_ADD(p, -1);
 			if(*p == 0)
 				_starpu_task_grid_unset_left_right_member(t);
 			l->ntasks--;
@@ -481,21 +481,6 @@ static double combined_worker_estimated_load(struct starpu_sched_node * node)
 	return load;
 }
 
-static void worker_deinit_data(struct starpu_sched_node * node)
-{
-	struct _starpu_worker_node_data * data = node->data;
-	if(data->list)
-		_starpu_worker_task_list_destroy(data->list);
-	free(data);
-	node->data = NULL;
-	int i;
-	for(i = 0; i < STARPU_NMAXWORKERS; i++)
-		if(_worker_nodes[i] == node)
-			break;
-	STARPU_ASSERT(i < STARPU_NMAXWORKERS);
-	_worker_nodes[i] = NULL;
-}
-
 
 static int starpu_sched_node_combined_worker_push_task(struct starpu_sched_node * node, struct starpu_task *task)
 {
@@ -588,7 +573,6 @@ static struct starpu_sched_node * starpu_sched_node_worker_create(int workerid)
 	node->estimated_end = simple_worker_estimated_end;
 	node->estimated_load = simple_worker_estimated_load;
 	node->available = simple_worker_available;
-	node->deinit_data = worker_deinit_data;
 	node->workers = starpu_bitmap_create();
 	starpu_bitmap_set(node->workers, workerid);
 	starpu_bitmap_or(node->workers_in_ctx, node->workers);
@@ -627,7 +611,6 @@ static struct starpu_sched_node  * starpu_sched_node_combined_worker_create(int
 	node->estimated_end = combined_worker_estimated_end;
 	node->estimated_load = combined_worker_estimated_load;
 	node->available = combined_worker_available;
-	node->deinit_data = worker_deinit_data;
 	node->workers = starpu_bitmap_create();
 	starpu_bitmap_set(node->workers, workerid);
 	starpu_bitmap_or(node->workers_in_ctx, node->workers);

+ 0 - 2
src/sched_policies/scheduler_maker.c

@@ -244,8 +244,6 @@ struct starpu_sched_tree * _starpu_make_scheduler(unsigned sched_ctx_id, struct
 		set_worker_leaf(tree->root,worker_node, sched_ctx_id, specs);
 	}
 
-	_starpu_set_workers_bitmaps();
-	starpu_sched_tree_call_init_data(tree);
 #ifdef STARPU_DEVEL
 	fprintf(stderr, "scheduler created :\n");
 	helper_display_scheduler(stderr, 0, tree->root);