Browse Source

tools: close file and fix coding style

Nathalie Furmento 8 years ago
parent
commit
2da43716d5
2 changed files with 32 additions and 20 deletions
  1. 9 6
      tools/starpu_replay.c
  2. 23 14
      tools/starpu_replay_sched.c

+ 9 - 6
tools/starpu_replay.c

@@ -241,9 +241,9 @@ static void variable_data_register_check(size_t * array_of_size, int nb_handles)
 			STARPU_ASSERT(handles_cell != NULL);
 			STARPU_ASSERT(handles_cell != NULL);
 
 
 			handles_cell->handle = handles_ptr[h]; /* Get the hidden key (initial handle from the file) to store it as a key*/
 			handles_cell->handle = handles_ptr[h]; /* Get the hidden key (initial handle from the file) to store it as a key*/
-			
+
 			starpu_variable_data_register(handles_ptr+h, STARPU_MAIN_RAM, (uintptr_t) 1, array_of_size[h]);
 			starpu_variable_data_register(handles_ptr+h, STARPU_MAIN_RAM, (uintptr_t) 1, array_of_size[h]);
-			
+
 			handles_cell->mem_ptr = handles_ptr[h]; /* Store the new value of the handle into the hash table */
 			handles_cell->mem_ptr = handles_ptr[h]; /* Store the new value of the handle into the hash table */
 
 
 			HASH_ADD(hh, handles_hash, handle, sizeof(handles_ptr[h]), handles_cell);
 			HASH_ADD(hh, handles_hash, handle, sizeof(handles_ptr[h]), handles_cell);
@@ -304,9 +304,12 @@ void reset(void)
 
 
 void fix_wontuse_handle(struct task * wontuseTask)
 void fix_wontuse_handle(struct task * wontuseTask)
 {
 {
-	struct handle * handle_tmp;
-	HASH_FIND(hh, handles_hash, &wontuseTask->task.handles[0], sizeof(wontuseTask->task.handles[0]), handle_tmp);
+	struct handle *handle_tmp;
 	STARPU_ASSERT(wontuseTask);
 	STARPU_ASSERT(wontuseTask);
+
+	HASH_FIND(hh, handles_hash, &wontuseTask->task.handles[0], sizeof(wontuseTask->task.handles[0]), handle_tmp);
+	STARPU_ASSERT(handle_tmp);
+
 	wontuseTask->task.handles[0] = handle_tmp->mem_ptr;
 	wontuseTask->task.handles[0] = handle_tmp->mem_ptr;
 }
 }
 
 
@@ -314,7 +317,7 @@ void fix_wontuse_handle(struct task * wontuseTask)
 int submit_tasks(void)
 int submit_tasks(void)
 {
 {
 	/* Add dependencies */
 	/* Add dependencies */
-	
+
 	const struct starpu_rbtree * tmptree = &tree;
 	const struct starpu_rbtree * tmptree = &tree;
 	struct starpu_rbtree_node * currentNode = starpu_rbtree_first(tmptree);
 	struct starpu_rbtree_node * currentNode = starpu_rbtree_first(tmptree);
 	unsigned long last_submitorder = 0;
 	unsigned long last_submitorder = 0;
@@ -793,7 +796,7 @@ eof:
 		HASH_DEL(handles_hash, handle);
 		HASH_DEL(handles_hash, handle);
 		free(handle);
 		free(handle);
         }
         }
-	
+
 	struct perfmodel * model_s, * modeltmp;
 	struct perfmodel * model_s, * modeltmp;
 	HASH_ITER(hh, model_hash, model_s, modeltmp)
 	HASH_ITER(hh, model_hash, model_s, modeltmp)
 	{
 	{

+ 23 - 14
tools/starpu_replay_sched.c

@@ -66,12 +66,14 @@ static unsigned ndependson;
 static unsigned params[STARPU_NMAXBUFS];
 static unsigned params[STARPU_NMAXBUFS];
 static unsigned nparams;
 static unsigned nparams;
 
 
-static enum sched_type {
+static enum sched_type
+{
 	NormalTask,
 	NormalTask,
 	PrefetchTask,
 	PrefetchTask,
 } sched_type;
 } sched_type;
 
 
-static struct starpu_codelet cl_prefetch = {
+static struct starpu_codelet cl_prefetch =
+{
         .where = STARPU_NOWHERE,
         .where = STARPU_NOWHERE,
         .nbuffers = 1,
         .nbuffers = 1,
         .modes = { STARPU_R },
         .modes = { STARPU_R },
@@ -105,13 +107,15 @@ LIST_TYPE(dep,
 	unsigned i;
 	unsigned i;
 );
 );
 
 
-struct deps {
+struct deps
+{
 	UT_hash_handle hh;
 	UT_hash_handle hh;
 	unsigned long submitorder;
 	unsigned long submitorder;
 	struct dep_list list;
 	struct dep_list list;
 } *dependencies = NULL;
 } *dependencies = NULL;
 
 
-static void reset(void) {
+static void reset(void)
+{
 	submitorder = 0;
 	submitorder = 0;
 	priority = INT_MIN;
 	priority = INT_MIN;
 	eosw = -1;
 	eosw = -1;
@@ -156,7 +160,7 @@ static void checkField(char * s)
 		char * delim = " ";
 		char * delim = " ";
 		char * token = strtok(s, delim);
 		char * token = strtok(s, delim);
 		int i = 0;
 		int i = 0;
-		 
+
 		while (token != NULL)
 		while (token != NULL)
 		{
 		{
 			int k = strtol(token, NULL, 10);
 			int k = strtol(token, NULL, 10);
@@ -171,13 +175,13 @@ static void checkField(char * s)
 
 
 	else if (TEST("DependsOn"))
 	else if (TEST("DependsOn"))
 	{
 	{
-		/* NOTE : dependsons (in the sched.rec)  should be the submit orders of the dependencies, 
+		/* NOTE : dependsons (in the sched.rec)  should be the submit orders of the dependencies,
 		   otherwise it can occur an undefined behaviour
 		   otherwise it can occur an undefined behaviour
 		   (contrary to the tasks.rec where dependencies are jobids */
 		   (contrary to the tasks.rec where dependencies are jobids */
 		unsigned i = 0;
 		unsigned i = 0;
 		char * delim = " ";
 		char * delim = " ";
 		char * token = strtok(s+strlen("DependsOn: "), delim);
 		char * token = strtok(s+strlen("DependsOn: "), delim);
-		
+
 		while (token != NULL)
 		while (token != NULL)
 		{
 		{
 			dependson[i] = strtol(token, NULL, 10);
 			dependson[i] = strtol(token, NULL, 10);
@@ -200,7 +204,7 @@ static void checkField(char * s)
 		char * delim = " ";
 		char * delim = " ";
 		char * token = strtok(s, delim);
 		char * token = strtok(s, delim);
 		int i = 0;
 		int i = 0;
-		 
+
 		while (token != NULL)
 		while (token != NULL)
 		{
 		{
 			params[i] = strtol(token, NULL, 10);
 			params[i] = strtol(token, NULL, 10);
@@ -215,7 +219,7 @@ static void checkField(char * s)
 		s = s + strlen("MemoryNode: ");
 		s = s + strlen("MemoryNode: ");
 		memnode = strtol(s, NULL, 10);
 		memnode = strtol(s, NULL, 10);
 	}
 	}
-	
+
 	else if (TEST("Workerorder"))
 	else if (TEST("Workerorder"))
 	{
 	{
 		s = s + strlen("Workerorder: ");
 		s = s + strlen("Workerorder: ");
@@ -227,7 +231,7 @@ static void checkField(char * s)
 void schedRecInit(const char * filename)
 void schedRecInit(const char * filename)
 {
 {
 	FILE * f = fopen(filename, "r");
 	FILE * f = fopen(filename, "r");
-	
+
 	if(f == NULL)
 	if(f == NULL)
 	{
 	{
 		fprintf(stderr,"unable to open file %s: %s\n", filename, strerror(errno));
 		fprintf(stderr,"unable to open file %s: %s\n", filename, strerror(errno));
@@ -237,7 +241,7 @@ void schedRecInit(const char * filename)
 	size_t lnsize = 128;
 	size_t lnsize = 128;
 	char * s = malloc(sizeof(*s) * lnsize);
 	char * s = malloc(sizeof(*s) * lnsize);
 	int eof = 0;
 	int eof = 0;
-	
+
 	reset();
 	reset();
 
 
 	while(!eof && !feof(f))
 	while(!eof && !feof(f))
@@ -274,7 +278,8 @@ void schedRecInit(const char * filename)
 			task->ndependson = ndependson;
 			task->ndependson = ndependson;
 
 
 			/* Also record submitorder of tasks that this one will need to depend on */
 			/* Also record submitorder of tasks that this one will need to depend on */
-			for (i = 0; i < ndependson; i++) {
+			for (i = 0; i < ndependson; i++)
+			{
 				struct dep *dep;
 				struct dep *dep;
 				struct starpu_task *starpu_task;
 				struct starpu_task *starpu_task;
 				_STARPU_MALLOC(dep, sizeof(*dep));
 				_STARPU_MALLOC(dep, sizeof(*dep));
@@ -283,7 +288,8 @@ void schedRecInit(const char * filename)
 
 
 				struct deps *deps;
 				struct deps *deps;
 				HASH_FIND(hh, dependencies, &task->dependson[i], sizeof(submitorder), deps);
 				HASH_FIND(hh, dependencies, &task->dependson[i], sizeof(submitorder), deps);
-				if (!deps) {
+				if (!deps)
+				{
 					/* No task depends on this one yet, add a cell for it */
 					/* No task depends on this one yet, add a cell for it */
 					_STARPU_MALLOC(deps, sizeof(*deps));
 					_STARPU_MALLOC(deps, sizeof(*deps));
 					dep_list_init(&deps->list);
 					dep_list_init(&deps->list);
@@ -335,6 +341,8 @@ void schedRecInit(const char * filename)
 		}
 		}
 		else checkField(s);
 		else checkField(s);
 	}
 	}
+
+	fclose(f);
 }
 }
 
 
 static void do_prefetch(void *arg)
 static void do_prefetch(void *arg)
@@ -366,7 +374,8 @@ void applySchedRec(struct starpu_task *starpu_task, unsigned long submit_order)
 	}
 	}
 
 
 	HASH_FIND(hh, prefetch_tasks, &submit_order, sizeof(submit_order), task);
 	HASH_FIND(hh, prefetch_tasks, &submit_order, sizeof(submit_order), task);
-	if (task) {
+	if (task)
+	{
 		/* We want to submit a prefetch for this task */
 		/* We want to submit a prefetch for this task */
 		debug("task %lu has a prefetch for parameter %d to node %d\n", submit_order, task->params[0], task->memnode);
 		debug("task %lu has a prefetch for parameter %d to node %d\n", submit_order, task->params[0], task->memnode);
 		struct starpu_task *pref_task;
 		struct starpu_task *pref_task;