Browse Source

Add starpu_sched_ctx_get_workers_list_raw, much less costly than starpu_sched_ctx_get_workers_list

Samuel Thibault 8 years ago
parent
commit
b2afb73fe8

+ 7 - 0
doc/doxygen/chapters/api/scheduling_contexts.doxy

@@ -168,6 +168,13 @@ Returns the list of workers in the array \p workerids, the returned value is the
 number of workers. The user should free the \p workerids table after finishing
 using it (it is allocated inside the function with the proper size)
 
+\fn unsigned starpu_sched_ctx_get_workers_list_raw(unsigned sched_ctx_id, int **workerids)
+\ingroup API_Scheduling_Contexts
+Returns the list of workers in the array \p workerids, the returned value is the 
+number of workers. This list is provided in raw order, i.e. not sorted by tree or list order,
+and the user should not free the \p workerids table.
+This function is thus much less costly than starpu_sched_ctx_get_workers_list.
+
 \fn unsigned starpu_sched_ctx_get_nworkers(unsigned sched_ctx_id)
 \ingroup API_Scheduling_Contexts
 Return the number of workers managed by the specified contexts

+ 1 - 0
include/fstarpu_mod.f90

@@ -1733,6 +1733,7 @@ module fstarpu_mod
                 end subroutine fstarpu_sched_ctx_finished_submit
 
                 ! unsigned starpu_sched_ctx_get_workers_list(unsigned sched_ctx_id, int **workerids);
+                ! unsigned starpu_sched_ctx_get_workers_list_raw(unsigned sched_ctx_id, int **workerids);
 
                 ! unsigned starpu_sched_ctx_get_nworkers(unsigned sched_ctx_id);
                 function fstarpu_sched_ctx_get_nworkers (sched_ctx_id) &

+ 1 - 0
include/starpu_sched_ctx.h

@@ -63,6 +63,7 @@ void starpu_sched_ctx_stop_task_submission(void);
 void starpu_sched_ctx_finished_submit(unsigned sched_ctx_id);
 
 unsigned starpu_sched_ctx_get_workers_list(unsigned sched_ctx_id, int **workerids);
+unsigned starpu_sched_ctx_get_workers_list_raw(unsigned sched_ctx_id, int **workerids);
 
 unsigned starpu_sched_ctx_get_nworkers(unsigned sched_ctx_id);
 

+ 2 - 1
include/starpu_worker.h

@@ -55,7 +55,8 @@ enum starpu_worker_collection_type
 
 struct starpu_worker_collection
 {
-	void *workerids;
+	int *workerids;
+	void *collection_private;
 	unsigned nworkers;
 	void *unblocked_workers;
 	unsigned nunblocked_workers;

+ 7 - 0
src/core/sched_ctx.c

@@ -1665,6 +1665,13 @@ void starpu_sched_ctx_display_workers(unsigned sched_ctx_id, FILE *f)
 	free(workerids);
 }
 
+unsigned starpu_sched_ctx_get_workers_list_raw(unsigned sched_ctx_id, int **workerids)
+{
+	struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
+	*workerids = sched_ctx->workers->workerids;
+	return sched_ctx->workers->nworkers;
+}
+
 unsigned starpu_sched_ctx_get_workers_list(unsigned sched_ctx_id, int **workerids)
 {
 	struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);

+ 18 - 8
src/worker_collection/worker_tree.c

@@ -27,7 +27,7 @@ static unsigned tree_has_next_unblocked_worker(struct starpu_worker_collection *
 	if(workers->nworkers == 0)
 		return 0;
 
-	struct starpu_tree *tree = (struct starpu_tree*)workers->workerids;
+	struct starpu_tree *tree = (struct starpu_tree*)workers->collection_private;
 	struct starpu_tree *neighbour = starpu_tree_get_neighbour(tree, (struct starpu_tree*)it->value, it->visited, workers->present);
 
 	if(!neighbour)
@@ -70,7 +70,7 @@ static int tree_get_next_unblocked_worker(struct starpu_worker_collection *worke
 {
 	int ret = -1;
 
-	struct starpu_tree *tree = (struct starpu_tree *)workers->workerids;
+	struct starpu_tree *tree = (struct starpu_tree *)workers->collection_private;
 	struct starpu_tree *neighbour = NULL;
 	if(it->possible_value)
 	{
@@ -106,7 +106,7 @@ static unsigned tree_has_next_master(struct starpu_worker_collection *workers, s
 	if(workers->nworkers == 0)
 		return 0;
 
-	struct starpu_tree *tree = (struct starpu_tree*)workers->workerids;
+	struct starpu_tree *tree = (struct starpu_tree*)workers->collection_private;
 	struct starpu_tree *neighbour = starpu_tree_get_neighbour(tree, (struct starpu_tree*)it->value, it->visited, workers->is_master);
 
 	if(!neighbour)
@@ -139,7 +139,7 @@ static int tree_get_next_master(struct starpu_worker_collection *workers, struct
 {
 	int ret = -1;
 
-	struct starpu_tree *tree = (struct starpu_tree *)workers->workerids;
+	struct starpu_tree *tree = (struct starpu_tree *)workers->collection_private;
 	struct starpu_tree *neighbour = NULL;
 	if(it->possible_value)
 	{
@@ -181,7 +181,7 @@ static unsigned tree_has_next(struct starpu_worker_collection *workers, struct s
 	if(workers->nworkers == 0)
 		return 0;
 
-	struct starpu_tree *tree = (struct starpu_tree*)workers->workerids;
+	struct starpu_tree *tree = (struct starpu_tree*)workers->collection_private;
 	struct starpu_tree *neighbour = starpu_tree_get_neighbour(tree, (struct starpu_tree*)it->value, it->visited, workers->present);
 
 	if(!neighbour)
@@ -219,7 +219,7 @@ static int tree_get_next(struct starpu_worker_collection *workers, struct starpu
 
 	int ret = -1;
 
-	struct starpu_tree *tree = (struct starpu_tree *)workers->workerids;
+	struct starpu_tree *tree = (struct starpu_tree *)workers->collection_private;
 	struct starpu_tree *neighbour = NULL;
 	if(it->possible_value)
 	{
@@ -255,6 +255,7 @@ static int tree_add(struct starpu_worker_collection *workers, int worker)
 	if(!workers->present[worker])
 	{
 		workers->present[worker] = 1;
+		workers->workerids[workers->nworkers] = worker;
 		workers->nworkers++;
 		return worker;
 	}
@@ -267,6 +268,13 @@ static int tree_remove(struct starpu_worker_collection *workers, int worker)
 {
 	if(workers->present[worker])
 	{
+		int i;
+		for (i = 0; i < workers->nworkers--; i++)
+			if (workers->workerids[i] == worker)
+			{
+				memmove(&workers->workerids[i], &workers->workerids[i+1], (workers->nworkers-1-i) * sizeof(workers->workerids[i]));
+				break;
+			}
 		workers->present[worker] = 0;
 		workers->is_unblocked[worker] = 0;
 		workers->is_master[worker] = 0;
@@ -279,13 +287,15 @@ static int tree_remove(struct starpu_worker_collection *workers, int worker)
 
 static void tree_init(struct starpu_worker_collection *workers)
 {
-	workers->workerids = (void*)starpu_workers_get_tree();
+	workers->workerids = (int*)malloc((STARPU_NMAXWORKERS+STARPU_NMAX_COMBINEDWORKERS) * sizeof(int));
+	workers->collection_private = (void*)starpu_workers_get_tree();
 	workers->nworkers = 0;
 
 	int i;
 	int nworkers = starpu_worker_get_count();
 	for(i = 0; i < nworkers; i++)
 	{
+		workers->workerids[i] = -1;
 		workers->present[i] = 0;
 		workers->is_unblocked[i] = 0;
 		workers->is_master[i] = 0;
@@ -297,7 +307,7 @@ static void tree_init(struct starpu_worker_collection *workers)
 static void tree_deinit(struct starpu_worker_collection *workers)
 {
 	(void) workers;
-//	free(workers->workerids);
+	free(workers->workerids);
 }
 
 static void tree_init_iterator(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)