浏览代码

reduce yet more the overhead of tree worker lists

Samuel Thibault 8 年之前
父节点
当前提交
6a6935b2df
共有 3 个文件被更改,包括 19 次插入26 次删除
  1. 1 1
      include/starpu_tree.h
  2. 16 23
      src/core/tree.c
  3. 2 2
      src/core/workers.c

+ 1 - 1
include/starpu_tree.h

@@ -25,7 +25,7 @@ extern "C"
 
 struct starpu_tree
 {
-	struct starpu_tree **nodes;
+	struct starpu_tree *nodes;
 	struct starpu_tree *father;
 	int arity;
 	int id;

+ 16 - 23
src/core/tree.c

@@ -32,15 +32,12 @@ void starpu_tree_reset_visited(struct starpu_tree *tree, char *visited)
 	}
 	int i;
 	for(i = 0; i < tree->arity; i++)
-		starpu_tree_reset_visited(tree->nodes[i], visited);
+		starpu_tree_reset_visited(&tree->nodes[i], visited);
 }
 
 void starpu_tree_prepare_children(unsigned arity, struct starpu_tree *father)
 {
-	unsigned i;
-	father->nodes = (struct starpu_tree**)malloc(arity*sizeof(struct starpu_tree*));
-	for(i = 0; i < arity; i++)
-		father->nodes[i] = (struct starpu_tree*)malloc(sizeof(struct starpu_tree));
+	father->nodes = (struct starpu_tree*)malloc(arity*sizeof(struct starpu_tree));
 }
 
 void starpu_tree_insert(struct starpu_tree *tree, int id, int level, int is_pu, int arity, struct starpu_tree *father)
@@ -67,7 +64,7 @@ struct starpu_tree* starpu_tree_get(struct starpu_tree *tree, int id)
 	int i;
 	for(i = 0; i < tree->arity; i++)
 	{
-		found_tree = starpu_tree_get(tree->nodes[i], id);
+		found_tree = starpu_tree_get(&tree->nodes[i], id);
 		if(found_tree)
 			return found_tree;
 	}
@@ -81,23 +78,23 @@ static struct starpu_tree* _get_down_to_leaves(struct starpu_tree *node, char *v
 	int i;
 	for(i = 0; i < node->arity; i++)
 	{
-		if(node->nodes[i]->arity == 0)
+		if(node->nodes[i].arity == 0)
 		{
-			if(node->nodes[i]->is_pu)
+			if(node->nodes[i].is_pu)
 			{
 				int *workerids;
-				int nworkers = starpu_bindid_get_workerids(node->nodes[i]->id, &workerids);
+				int nworkers = starpu_bindid_get_workerids(node->nodes[i].id, &workerids);
 				int w;
 				for(w = 0; w < nworkers; w++)
 				{
 					if(!visited[workerids[w]] && present[workerids[w]])
-						return node->nodes[i];
+						return &node->nodes[i];
 				}
 			}
 		}
 		else
 		{
-			found_tree =_get_down_to_leaves(node->nodes[i], visited, present);
+			found_tree =_get_down_to_leaves(&node->nodes[i], visited, present);
 			if(found_tree)
 				return found_tree;
 		}
@@ -113,32 +110,32 @@ struct starpu_tree* starpu_tree_get_neighbour(struct starpu_tree *tree, struct s
 
 	for(st = 0; st < father->arity; st++)
 	{
-		if(father->nodes[st] == node)
+		if(&father->nodes[st] == node)
 			break;
 	}
 
 	for(n = 0; n < father->arity; n++)
 	{
 		i = (st+n)%father->arity;
-		if(father->nodes[i] != node)
+		if(&father->nodes[i] != node)
 		{
-			if(father->nodes[i]->arity == 0)
+			if(father->nodes[i].arity == 0)
 			{
-				if(father->nodes[i]->is_pu)
+				if(father->nodes[i].is_pu)
 				{
 					int *workerids;
-					int nworkers = starpu_bindid_get_workerids(father->nodes[i]->id, &workerids);
+					int nworkers = starpu_bindid_get_workerids(father->nodes[i].id, &workerids);
 					int w;
 					for(w = 0; w < nworkers; w++)
 					{
 						if(!visited[workerids[w]] && present[workerids[w]])
-							return father->nodes[i];
+							return &father->nodes[i];
 					}
 				}
 			}
 			else
 			{
-				struct starpu_tree *leaf = _get_down_to_leaves(father->nodes[i], visited, present);
+				struct starpu_tree *leaf = _get_down_to_leaves(&father->nodes[i], visited, present);
 				if(leaf)
 					return leaf;
 			}
@@ -155,11 +152,7 @@ void starpu_tree_free(struct starpu_tree *tree)
 {
 	int i;
 	for(i = 0; i < tree->arity; i++)
-	{
-		starpu_tree_free(tree->nodes[i]);
-		free(tree->nodes[i]);
-		tree->nodes[i] = NULL;
-	}
+		starpu_tree_free(&tree->nodes[i]);
 	free(tree->nodes);
 	tree->nodes = NULL;
 	tree->arity = 0;

+ 2 - 2
src/core/workers.c

@@ -1016,11 +1016,11 @@ static void _fill_tree(struct starpu_tree *tree, hwloc_obj_t curr_obj, unsigned
 	starpu_tree_prepare_children(curr_obj->arity, tree);
 	for(i = 0; i < curr_obj->arity; i++)
 	{
-		starpu_tree_insert(tree->nodes[i], curr_obj->children[i]->logical_index, depth, curr_obj->children[i]->type == HWLOC_OBJ_PU, curr_obj->children[i]->arity, tree);
+		starpu_tree_insert(&tree->nodes[i], curr_obj->children[i]->logical_index, depth, curr_obj->children[i]->type == HWLOC_OBJ_PU, curr_obj->children[i]->arity, tree);
 /* 		char string[128]; */
 /* 		hwloc_obj_snprintf(string, sizeof(string), topology, curr_obj->children[i], "#", 0); */
 /* 		printf("%*s%s %d is_pu %d \n", 0, "", string, curr_obj->children[i]->logical_index, curr_obj->children[i]->type == HWLOC_OBJ_PU); */
-		_fill_tree(tree->nodes[i], curr_obj->children[i], depth+1, topology);
+		_fill_tree(&tree->nodes[i], curr_obj->children[i], depth+1, topology);
 	}
 }
 #endif