|
@@ -21,7 +21,7 @@
|
|
|
#include <hwloc.h>
|
|
|
#include "core/workers.h"
|
|
|
|
|
|
-static unsigned tree_has_next(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)
|
|
|
+static unsigned tree_has_next_unblocked_worker(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)
|
|
|
{
|
|
|
STARPU_ASSERT(it != NULL);
|
|
|
if(workers->nworkers == 0)
|
|
@@ -43,7 +43,7 @@ static unsigned tree_has_next(struct starpu_worker_collection *workers, struct s
|
|
|
int w;
|
|
|
for(w = 0; w < nworkers; w++)
|
|
|
{
|
|
|
- if(!it->visited[workerids[w]] && workers->present[workerids[w]])
|
|
|
+ if(!it->visited[workerids[w]] && workers->present[workerids[w]] && workers->is_unblocked[workerids[w]])
|
|
|
{
|
|
|
id = workerids[w];
|
|
|
it->possible_value = neighbour;
|
|
@@ -55,7 +55,7 @@ static unsigned tree_has_next(struct starpu_worker_collection *workers, struct s
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-static int tree_get_next(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)
|
|
|
+static int tree_get_next_unblocked_worker(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)
|
|
|
{
|
|
|
int ret = -1;
|
|
|
|
|
@@ -77,7 +77,7 @@ static int tree_get_next(struct starpu_worker_collection *workers, struct starpu
|
|
|
int w;
|
|
|
for(w = 0; w < nworkers; w++)
|
|
|
{
|
|
|
- if(!it->visited[workerids[w]] && workers->present[workerids[w]] )
|
|
|
+ if(!it->visited[workerids[w]] && workers->present[workerids[w]] && workers->is_unblocked[workerids[w]])
|
|
|
{
|
|
|
ret = workerids[w];
|
|
|
it->visited[workerids[w]] = 1;
|
|
@@ -85,18 +85,17 @@ static int tree_get_next(struct starpu_worker_collection *workers, struct starpu
|
|
|
}
|
|
|
}
|
|
|
STARPU_ASSERT_MSG(ret != -1, "bind id not correct");
|
|
|
-
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-static unsigned tree_has_next_unblocked_worker(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)
|
|
|
+static unsigned tree_has_next_master(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)
|
|
|
{
|
|
|
STARPU_ASSERT(it != NULL);
|
|
|
if(workers->nworkers == 0)
|
|
|
return 0;
|
|
|
|
|
|
struct starpu_tree *tree = (struct starpu_tree*)workers->workerids;
|
|
|
- struct starpu_tree *neighbour = starpu_tree_get_neighbour(tree, (struct starpu_tree*)it->value, it->visited, workers->present);
|
|
|
+ struct starpu_tree *neighbour = starpu_tree_get_neighbour(tree, (struct starpu_tree*)it->value, it->visited, workers->is_master);
|
|
|
|
|
|
if(!neighbour)
|
|
|
{
|
|
@@ -111,7 +110,7 @@ static unsigned tree_has_next_unblocked_worker(struct starpu_worker_collection *
|
|
|
int w;
|
|
|
for(w = 0; w < nworkers; w++)
|
|
|
{
|
|
|
- if(!it->visited[workerids[w]] && workers->present[workerids[w]] && workers->is_unblocked[workerids[w]])
|
|
|
+ if(!it->visited[workerids[w]] && workers->is_master[workerids[w]])
|
|
|
{
|
|
|
id = workerids[w];
|
|
|
it->possible_value = neighbour;
|
|
@@ -123,7 +122,7 @@ static unsigned tree_has_next_unblocked_worker(struct starpu_worker_collection *
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-static int tree_get_next_unblocked_worker(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)
|
|
|
+static int tree_get_next_master(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)
|
|
|
{
|
|
|
int ret = -1;
|
|
|
|
|
@@ -135,7 +134,7 @@ static int tree_get_next_unblocked_worker(struct starpu_worker_collection *worke
|
|
|
it->possible_value = NULL;
|
|
|
}
|
|
|
else
|
|
|
- neighbour = starpu_tree_get_neighbour(tree, (struct starpu_tree*)it->value, it->visited, workers->present);
|
|
|
+ neighbour = starpu_tree_get_neighbour(tree, (struct starpu_tree*)it->value, it->visited, workers->is_master);
|
|
|
|
|
|
STARPU_ASSERT_MSG(neighbour, "no element anymore");
|
|
|
|
|
@@ -145,7 +144,7 @@ static int tree_get_next_unblocked_worker(struct starpu_worker_collection *worke
|
|
|
int w;
|
|
|
for(w = 0; w < nworkers; w++)
|
|
|
{
|
|
|
- if(!it->visited[workerids[w]] && workers->present[workerids[w]] && workers->is_unblocked[workerids[w]])
|
|
|
+ if(!it->visited[workerids[w]] && workers->is_master[workerids[w]])
|
|
|
{
|
|
|
ret = workerids[w];
|
|
|
it->visited[workerids[w]] = 1;
|
|
@@ -157,14 +156,19 @@ static int tree_get_next_unblocked_worker(struct starpu_worker_collection *worke
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-static unsigned tree_has_next_master(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)
|
|
|
+static unsigned tree_has_next(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)
|
|
|
{
|
|
|
+ if(it->possibly_parallel == 1)
|
|
|
+ return tree_has_next_master(workers, it);
|
|
|
+ else if(it->possibly_parallel == 0)
|
|
|
+ return tree_has_next_unblocked_worker(workers, it);
|
|
|
+
|
|
|
STARPU_ASSERT(it != NULL);
|
|
|
if(workers->nworkers == 0)
|
|
|
return 0;
|
|
|
|
|
|
struct starpu_tree *tree = (struct starpu_tree*)workers->workerids;
|
|
|
- struct starpu_tree *neighbour = starpu_tree_get_neighbour(tree, (struct starpu_tree*)it->value, it->visited, workers->is_master);
|
|
|
+ struct starpu_tree *neighbour = starpu_tree_get_neighbour(tree, (struct starpu_tree*)it->value, it->visited, workers->present);
|
|
|
|
|
|
if(!neighbour)
|
|
|
{
|
|
@@ -179,7 +183,7 @@ static unsigned tree_has_next_master(struct starpu_worker_collection *workers, s
|
|
|
int w;
|
|
|
for(w = 0; w < nworkers; w++)
|
|
|
{
|
|
|
- if(!it->visited[workerids[w]] && workers->is_master[workerids[w]])
|
|
|
+ if(!it->visited[workerids[w]] && workers->present[workerids[w]])
|
|
|
{
|
|
|
id = workerids[w];
|
|
|
it->possible_value = neighbour;
|
|
@@ -191,8 +195,13 @@ static unsigned tree_has_next_master(struct starpu_worker_collection *workers, s
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-static int tree_get_next_master(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)
|
|
|
+static int tree_get_next(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it)
|
|
|
{
|
|
|
+ if(it->possibly_parallel == 1)
|
|
|
+ return tree_get_next_master(workers, it);
|
|
|
+ else if(it->possibly_parallel == 0)
|
|
|
+ return tree_get_next_unblocked_worker(workers, it);
|
|
|
+
|
|
|
int ret = -1;
|
|
|
|
|
|
struct starpu_tree *tree = (struct starpu_tree *)workers->workerids;
|
|
@@ -203,7 +212,7 @@ static int tree_get_next_master(struct starpu_worker_collection *workers, struct
|
|
|
it->possible_value = NULL;
|
|
|
}
|
|
|
else
|
|
|
- neighbour = starpu_tree_get_neighbour(tree, (struct starpu_tree*)it->value, it->visited, workers->is_master);
|
|
|
+ neighbour = starpu_tree_get_neighbour(tree, (struct starpu_tree*)it->value, it->visited, workers->present);
|
|
|
|
|
|
STARPU_ASSERT_MSG(neighbour, "no element anymore");
|
|
|
|
|
@@ -213,7 +222,7 @@ static int tree_get_next_master(struct starpu_worker_collection *workers, struct
|
|
|
int w;
|
|
|
for(w = 0; w < nworkers; w++)
|
|
|
{
|
|
|
- if(!it->visited[workerids[w]] && workers->is_master[workerids[w]])
|
|
|
+ if(!it->visited[workerids[w]] && workers->present[workerids[w]] )
|
|
|
{
|
|
|
ret = workerids[w];
|
|
|
it->visited[workerids[w]] = 1;
|
|
@@ -225,7 +234,6 @@ static int tree_get_next_master(struct starpu_worker_collection *workers, struct
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
static int tree_add(struct starpu_worker_collection *workers, int worker)
|
|
|
{
|
|
|
if(!workers->present[worker])
|
|
@@ -279,13 +287,25 @@ static void tree_init_iterator(struct starpu_worker_collection *workers, struct
|
|
|
{
|
|
|
it->value = NULL;
|
|
|
it->possible_value = NULL;
|
|
|
+ it->possibly_parallel = -1;
|
|
|
+ int i;
|
|
|
+ int nworkers = starpu_worker_get_count();
|
|
|
+ for(i = 0; i < nworkers; i++)
|
|
|
+ it->visited[i] = 0;
|
|
|
+}
|
|
|
+
|
|
|
+static void tree_init_iterator_for_parallel_tasks(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it, unsigned possibly_parallel)
|
|
|
+{
|
|
|
+ tree_init_iterator(workers, it);
|
|
|
+ it->possibly_parallel = possibly_parallel;
|
|
|
int i;
|
|
|
int nworkers = starpu_worker_get_count();
|
|
|
for(i = 0; i < nworkers; i++)
|
|
|
{
|
|
|
workers->is_unblocked[i] = (workers->present[i] && !starpu_worker_is_blocked(i));
|
|
|
+ if(!possibly_parallel) /* don't bother filling the table with masters we won't use it anyway */
|
|
|
+ continue;
|
|
|
workers->is_master[i] = (workers->present[i] && !starpu_worker_is_blocked(i) && !starpu_worker_is_slave_somewhere(i));
|
|
|
- it->visited[i] = 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -293,15 +313,12 @@ struct starpu_worker_collection worker_tree =
|
|
|
{
|
|
|
.has_next = tree_has_next,
|
|
|
.get_next = tree_get_next,
|
|
|
- .has_next_unblocked_worker = tree_has_next_unblocked_worker,
|
|
|
- .get_next_unblocked_worker = tree_get_next_unblocked_worker,
|
|
|
- .has_next_master = tree_has_next_master,
|
|
|
- .get_next_master = tree_get_next_master,
|
|
|
.add = tree_add,
|
|
|
.remove = tree_remove,
|
|
|
.init = tree_init,
|
|
|
.deinit = tree_deinit,
|
|
|
.init_iterator = tree_init_iterator,
|
|
|
+ .init_iterator_for_parallel_tasks = tree_init_iterator_for_parallel_tasks,
|
|
|
.type = STARPU_WORKER_TREE
|
|
|
};
|
|
|
|