Quellcode durchsuchen

src: fix cleaning when starpu_build_topology returns a non zero value

Nathalie Furmento vor 10 Jahren
Ursprung
Commit
6c18e864fa
4 geänderte Dateien mit 76 neuen und 63 gelöschten Zeilen
  1. 7 3
      src/core/debug.c
  2. 54 50
      src/core/topology.c
  3. 4 1
      src/core/topology.h
  4. 11 9
      src/core/workers.c

+ 7 - 3
src/core/debug.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2009-2013  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2013  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2013, 2015  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -22,7 +22,7 @@
 #ifdef STARPU_VERBOSE
 /* we want a single writer at the same time to have a log that is readable */
 static starpu_pthread_mutex_t logfile_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
-static FILE *logfile;
+static FILE *logfile = NULL;
 #endif
 
 /* Tell gdb whether FXT is compiled in or not */
@@ -52,7 +52,11 @@ void _starpu_open_debug_logfile(void)
 void _starpu_close_debug_logfile(void)
 {
 #ifdef STARPU_VERBOSE
-	fclose(logfile);
+	if (logfile)
+	{
+		fclose(logfile);
+		logfile = NULL;
+	}
 #endif
 }
 

+ 54 - 50
src/core/topology.c

@@ -772,7 +772,7 @@ _starpu_init_mp_config (struct _starpu_machine_config *config,
 		if (0 == _starpu_init_mic_node (config, i, &handles[i], &process[i]))
 			topology->nmicdevices++;
 
-	
+
 	for (i = 0; i < topology->nmicdevices; i++)
 		_starpu_init_mic_config (config, user_conf, i);
 #endif
@@ -801,7 +801,7 @@ _starpu_deinit_mp_config (struct _starpu_machine_config *config)
 #endif
 
 static int
-_starpu_init_machine_config (struct _starpu_machine_config *config, int no_mp_config STARPU_ATTRIBUTE_UNUSED)
+_starpu_init_machine_config(struct _starpu_machine_config *config, int no_mp_config STARPU_ATTRIBUTE_UNUSED)
 {
 	int i;
 	for (i = 0; i < STARPU_NMAXWORKERS; i++)
@@ -1110,6 +1110,56 @@ _starpu_init_machine_config (struct _starpu_machine_config *config, int no_mp_co
 	return 0;
 }
 
+void _starpu_destroy_machine_config(struct _starpu_machine_config *config)
+{
+	_starpu_close_debug_logfile();
+
+	unsigned worker;
+	for (worker = 0; worker < config->topology.nworkers; worker++)
+	{
+		struct _starpu_worker *workerarg = &config->workers[worker];
+		free(workerarg->perf_arch.devices);
+#ifdef STARPU_HAVE_HWLOC
+		hwloc_bitmap_free(workerarg->hwloc_cpu_set);
+		if (workerarg->bindid != -1)
+		{
+			hwloc_obj_t worker_obj = hwloc_get_obj_by_depth(config->topology.hwtopology,
+									config->pu_depth,
+									workerarg->bindid);
+			if (worker_obj->userdata)
+			{
+				_starpu_worker_list_delete(worker_obj->userdata);
+				worker_obj->userdata = NULL;
+			}
+		}
+#endif
+	}
+	unsigned combined_worker_id;
+	for(combined_worker_id=0 ; combined_worker_id < config->topology.ncombinedworkers ; combined_worker_id++)
+	{
+		struct _starpu_combined_worker *combined_worker = &config->combined_workers[combined_worker_id];
+		free(combined_worker->perf_arch.devices);
+	}
+
+#ifdef STARPU_HAVE_HWLOC
+	hwloc_topology_destroy(config->topology.hwtopology);
+#endif
+
+	topology_is_initialized = 0;
+#ifdef STARPU_USE_CUDA
+	struct handle_entry *entry, *tmp;
+	HASH_ITER(hh, devices_using_cuda, entry, tmp)
+	{
+		HASH_DEL(devices_using_cuda, entry);
+		free(entry);
+	}
+	devices_using_cuda = NULL;
+#endif
+#if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL)
+	may_bind_automatically = 0;
+#endif
+}
+
 void
 _starpu_bind_thread_on_cpu (
 	struct _starpu_machine_config *config STARPU_ATTRIBUTE_UNUSED,
@@ -1558,9 +1608,7 @@ _starpu_build_topology (struct _starpu_machine_config *config, int no_mp_config)
 	return 0;
 }
 
-void
-_starpu_destroy_topology (
-	struct _starpu_machine_config *config STARPU_ATTRIBUTE_UNUSED)
+void _starpu_destroy_topology(struct _starpu_machine_config *config STARPU_ATTRIBUTE_UNUSED)
 {
 #ifdef STARPU_USE_MIC
 	_starpu_deinit_mp_config(config);
@@ -1569,51 +1617,7 @@ _starpu_destroy_topology (
 	/* cleanup StarPU internal data structures */
 	_starpu_memory_nodes_deinit();
 
-	unsigned worker;
-	for (worker = 0; worker < config->topology.nworkers; worker++)
-	{
-		struct _starpu_worker *workerarg = &config->workers[worker];
-		free(workerarg->perf_arch.devices);
-#ifdef STARPU_HAVE_HWLOC
-		hwloc_bitmap_free(workerarg->hwloc_cpu_set);
-		if (workerarg->bindid != -1)
-		{
-			hwloc_obj_t worker_obj = hwloc_get_obj_by_depth(config->topology.hwtopology,
-									config->pu_depth,
-									workerarg->bindid);
-			if (worker_obj->userdata)
-			{
-				_starpu_worker_list_delete(worker_obj->userdata);
-				worker_obj->userdata = NULL;
-			}
-		}
-#endif
-	}
-
-	unsigned combined_worker_id;
-	for(combined_worker_id=0 ; combined_worker_id < config->topology.ncombinedworkers ; combined_worker_id++)
-	{
-		struct _starpu_combined_worker *combined_worker = &config->combined_workers[combined_worker_id];
-		free(combined_worker->perf_arch.devices);
-	}
-
-#ifdef STARPU_HAVE_HWLOC
-	hwloc_topology_destroy(config->topology.hwtopology);
-#endif
-
-	topology_is_initialized = 0;
-#ifdef STARPU_USE_CUDA
-	struct handle_entry *entry, *tmp;
-	HASH_ITER(hh, devices_using_cuda, entry, tmp)
-	{
-		HASH_DEL(devices_using_cuda, entry);
-		free(entry);
-	}
-	devices_using_cuda = NULL;
-#endif
-#if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL)
-	may_bind_automatically = 0;
-#endif
+	_starpu_destroy_machine_config(config);
 }
 
 void

+ 4 - 1
src/core/topology.h

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2009-2010, 2012, 2014  Université de Bordeaux
- * Copyright (C) 2010  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2015  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -29,6 +29,9 @@ struct _starpu_machine_config;
 /* Detect the number of memory nodes and where to bind the different workers. */
 int _starpu_build_topology(struct _starpu_machine_config *config, int no_mp_config);
 
+/* Should be called instead of _starpu_destroy_topology when _starpu_build_topology returns a non zero value. */
+void _starpu_destroy_machine_config(struct _starpu_machine_config *config);
+
 /* Destroy all resources used to store the topology of the machine. */
 void _starpu_destroy_topology(struct _starpu_machine_config *config);
 

+ 11 - 9
src/core/workers.c

@@ -99,10 +99,10 @@ static uint32_t _starpu_worker_exists_and_can_execute(struct starpu_task *task,
 	int i;
 	_starpu_codelet_check_deprecated_fields(task->cl);
 
-        /* make sure there is a worker on the machine able to execute the 
-	   task, independent of the sched_ctx, this latter may receive latter on 
+        /* make sure there is a worker on the machine able to execute the
+	   task, independent of the sched_ctx, this latter may receive latter on
 	   the necessary worker - the user or the hypervisor should take care this happens */
-	
+
 	int check_entire_platform = starpu_get_env_number("STARPU_CHECK_ENTIRE_PLATFORM");
 	struct _starpu_sched_ctx *sched_ctx = check_entire_platform == 1 ? _starpu_get_initial_sched_ctx() : _starpu_get_sched_ctx_struct(task->sched_ctx);
 	struct starpu_worker_collection *workers = sched_ctx->workers;
@@ -176,7 +176,7 @@ uint32_t _starpu_worker_exists(struct starpu_task *task)
 	{
 		if (!(task->cl->where & config.worker_mask))
 			return 0;
-		
+
 		if (!task->cl->can_execute)
 			return 1;
 	}
@@ -393,7 +393,7 @@ int starpu_combined_worker_can_execute_task(unsigned workerid, struct starpu_tas
 	}
 	else
 	{
-		if ((cl->type == STARPU_SPMD) 
+		if ((cl->type == STARPU_SPMD)
 #ifdef STARPU_HAVE_HWLOC
 				|| (cl->type == STARPU_FORKJOIN)
 #else
@@ -1204,7 +1204,9 @@ int starpu_initialize(struct starpu_conf *user_conf, int *argc, char ***argv)
 		starpu_perfmodel_free_sampling_directories();
 		STARPU_PTHREAD_MUTEX_LOCK(&init_mutex);
 		init_count--;
-		_starpu_destroy_topology(&config);
+
+		_starpu_destroy_machine_config(&config);
+
 #ifdef STARPU_USE_SCC
 		if (_starpu_scc_common_is_mp_initialized())
 			_starpu_scc_src_mp_deinit();
@@ -1623,10 +1625,10 @@ int starpu_asynchronous_mic_copy_disabled(void)
 unsigned starpu_mic_worker_get_count(void)
 {
 	int i = 0, count = 0;
-	
+
 	for (i = 0; i < STARPU_MAXMICDEVS; i++)
 		count += config.topology.nmiccores[i];
-	
+
 	return count;
 }
 
@@ -1737,7 +1739,7 @@ struct _starpu_sched_ctx *_starpu_get_sched_ctx_struct(unsigned id)
 struct _starpu_combined_worker *_starpu_get_combined_worker_struct(unsigned id)
 {
 	unsigned basic_worker_count = starpu_worker_get_count();
-	
+
 	//_STARPU_DEBUG("basic_worker_count:%d\n",basic_worker_count);
 
 	STARPU_ASSERT(id >= basic_worker_count);