瀏覽代碼

Move most initializations to the singleton section

Samuel Thibault 9 年之前
父節點
當前提交
fac1e4fcf9
共有 2 個文件被更改,包括 28 次插入36 次删除
  1. 24 20
      src/core/workers.c
  2. 4 16
      src/util/openmp_runtime_support.c

+ 24 - 20
src/core/workers.c

@@ -1082,8 +1082,32 @@ int starpu_initialize(struct starpu_conf *user_conf, int *argc, char ***argv)
 			    * used, we cannot be a sink. */
 	unsigned worker;
 
+	(void)argc;
+	(void)argv;
+
+	/* This initializes _starpu_silent, thus needs to be early */
 	_starpu_util_init();
 
+#ifdef STARPU_SIMGRID
+	/* This initializes the simgrid thread library, thus needs to be early */
+	_starpu_simgrid_init();
+#endif
+
+	STARPU_PTHREAD_MUTEX_LOCK(&init_mutex);
+	while (initialized == CHANGING)
+		/* Wait for the other one changing it */
+		STARPU_PTHREAD_COND_WAIT(&init_cond, &init_mutex);
+	init_count++;
+	if (initialized == INITIALIZED)
+	{
+		/* He initialized it, don't do it again, and let the others get the mutex */
+		STARPU_PTHREAD_MUTEX_UNLOCK(&init_mutex);
+		return 0;
+	}
+	/* initialized == UNINITIALIZED */
+	initialized = CHANGING;
+	STARPU_PTHREAD_MUTEX_UNLOCK(&init_mutex);
+
 #ifdef STARPU_USE_MP
 	_starpu_set_argc_argv(argc, argv);
 
@@ -1097,10 +1121,6 @@ int starpu_initialize(struct starpu_conf *user_conf, int *argc, char ***argv)
 	 * kind on node we are running on : host or sink ? */
 	if (starpu_getenv("STARPU_SINK"))
 		is_a_sink = 1;
-#else
-	(void)argc;
-	(void)argv;
-
 #endif /* STARPU_USE_MP */
 
 	int ret;
@@ -1110,7 +1130,6 @@ int starpu_initialize(struct starpu_conf *user_conf, int *argc, char ***argv)
 #endif
 
 #ifdef STARPU_SIMGRID
-	_starpu_simgrid_init();
 	/* Warn when the lots of stacks malloc()-ated by simgrid for transfer
 	 * processes will take a long time to get initialized */
 	if (starpu_getenv("MALLOC_PERTURB_"))
@@ -1149,21 +1168,6 @@ int starpu_initialize(struct starpu_conf *user_conf, int *argc, char ***argv)
 #endif
 #endif
 
-	STARPU_PTHREAD_MUTEX_LOCK(&init_mutex);
-	while (initialized == CHANGING)
-		/* Wait for the other one changing it */
-		STARPU_PTHREAD_COND_WAIT(&init_cond, &init_mutex);
-	init_count++;
-	if (initialized == INITIALIZED)
-	{
-		/* He initialized it, don't do it again, and let the others get the mutex */
-		STARPU_PTHREAD_MUTEX_UNLOCK(&init_mutex);
-		return 0;
-	}
-	/* initialized == UNINITIALIZED */
-	initialized = CHANGING;
-	STARPU_PTHREAD_MUTEX_UNLOCK(&init_mutex);
-
 #if defined(_WIN32) && !defined(__CYGWIN__)
 	WSADATA wsadata;
 	WSAStartup(MAKEWORD(1,0), &wsadata);

+ 4 - 16
src/util/openmp_runtime_support.c

@@ -39,7 +39,6 @@ static struct starpu_omp_global _global_state;
 static starpu_pthread_key_t omp_thread_key;
 static starpu_pthread_key_t omp_task_key;
 static struct starpu_conf omp_starpu_conf;
-static int omp_dummy_init = 0;
 
 struct starpu_omp_global *_starpu_omp_global_state = NULL;
 double _starpu_omp_clock_ref = 0.0; /* clock reference for starpu_omp_get_wtick */
@@ -860,12 +859,8 @@ void _starpu_omp_dummy_init(void)
 {
 	if (_starpu_omp_global_state != &_global_state)
 	{
-		if (omp_dummy_init == 0)
-		{
-			STARPU_PTHREAD_KEY_CREATE(&omp_thread_key, NULL);
-			STARPU_PTHREAD_KEY_CREATE(&omp_task_key, NULL);
-		}
-		omp_dummy_init++;
+		STARPU_PTHREAD_KEY_CREATE(&omp_thread_key, NULL);
+		STARPU_PTHREAD_KEY_CREATE(&omp_task_key, NULL);
 	}
 }
 
@@ -874,15 +869,8 @@ void _starpu_omp_dummy_init(void)
  */
 void _starpu_omp_dummy_shutdown(void)
 {
-	if (omp_dummy_init > 0)
-	{
-		if (omp_dummy_init == 1)
-		{
-			STARPU_PTHREAD_KEY_DELETE(omp_thread_key);
-			STARPU_PTHREAD_KEY_DELETE(omp_task_key);
-		}
-		omp_dummy_init--;
-	}
+	STARPU_PTHREAD_KEY_DELETE(omp_thread_key);
+	STARPU_PTHREAD_KEY_DELETE(omp_task_key);
 }
 
 /*