Browse Source

starpu-mpi/simgrid: Make StarPU-MPI initialization wait for StarPU initialization

So we get a situation much more coherent with native execution
Samuel Thibault 6 years ago
parent
commit
3c579dc545

+ 5 - 1
doc/doxygen/chapters/api/initialization.doxy

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2010-2017                                CNRS
  * Copyright (C) 2011-2012,2014,2017                      Inria
- * Copyright (C) 2009-2011,2014                           Université de Bordeaux
+ * Copyright (C) 2009-2011,2014,2018                      Université de Bordeaux
  *
  * 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
@@ -281,6 +281,10 @@ the argument was <c>NULL</c>.
 \ingroup API_Initialization_and_Termination
 Return 1 if StarPU is already initialized.
 
+\fn int starpu_wait_initialized(void)
+\ingroup API_Initialization_and_Termination
+Wait for starpu_init() call to finish.
+
 \fn void starpu_shutdown(void)
 \ingroup API_Initialization_and_Termination
 This is StarPU termination method. It must be called at the end of the

+ 2 - 1
include/starpu.h

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2012-2017                                Inria
- * Copyright (C) 2009-2014,2016-2017                      Université de Bordeaux
+ * Copyright (C) 2009-2014,2016-2018                      Université de Bordeaux
  * Copyright (C) 2010-2015,2017                           CNRS
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -152,6 +152,7 @@ int starpu_conf_init(struct starpu_conf *conf);
 int starpu_init(struct starpu_conf *conf) STARPU_WARN_UNUSED_RESULT;
 int starpu_initialize(struct starpu_conf *user_conf, int *argc, char ***argv);
 int starpu_is_initialized(void);
+void starpu_wait_initialized(void);
 
 void starpu_pause(void);
 void starpu_resume(void);

+ 3 - 0
mpi/src/mpi/starpu_mpi_mpi.c

@@ -1144,6 +1144,9 @@ static void *_starpu_mpi_progress_thread_func(void *arg)
 		_STARPU_ERROR("Your version of simgrid does not provide smpi_process_set_user_data, we can not continue without it\n");
 	}
 	smpi_process_set_user_data(tsd);
+        /* And wait for StarPU to get initialized, to come back to the same
+         * situation as native execution where that's always the case. */
+	starpu_wait_initialized();
 #endif
 
 	_starpu_mpi_comm_amounts_init(argc_argv->comm);

+ 8 - 0
src/core/workers.c

@@ -97,6 +97,14 @@ int starpu_is_initialized(void)
 	return initialized == INITIALIZED;
 }
 
+void starpu_wait_initialized(void)
+{
+	STARPU_PTHREAD_MUTEX_LOCK(&init_mutex);
+	while (initialized != INITIALIZED)
+		STARPU_PTHREAD_COND_WAIT(&init_cond, &init_mutex);
+	STARPU_PTHREAD_MUTEX_UNLOCK(&init_mutex);
+}
+
 /* Makes sure that at least one of the workers of type <arch> can execute
  * <task>, for at least one of its implementations. */
 static uint32_t _starpu_worker_exists_and_can_execute(struct starpu_task *task,