Procházet zdrojové kódy

Call SMPI_thread_create when available instead of tinkering with data

Samuel Thibault před 5 roky
rodič
revize
9802edc7b6
4 změnil soubory, kde provedl 31 přidání a 4 odebrání
  1. 1 1
      configure.ac
  2. 1 1
      include/starpu_thread.h
  3. 1 1
      src/common/thread.c
  4. 28 1
      src/core/simgrid_cpp.cpp

+ 1 - 1
configure.ac

@@ -196,7 +196,7 @@ if test x$enable_simgrid = xyes ; then
 
 	# Latest functions
 	AC_CHECK_FUNCS([MSG_process_attach sg_actor_attach sg_actor_init MSG_zone_get_hosts sg_zone_get_hosts MSG_process_self_name MSG_process_userdata_init sg_actor_data])
-	AC_CHECK_FUNCS([xbt_mutex_try_acquire smpi_process_set_user_data sg_zone_get_by_name sg_link_name sg_host_route sg_host_self sg_host_speed simcall_process_create sg_config_continue_after_help])
+	AC_CHECK_FUNCS([xbt_mutex_try_acquire smpi_process_set_user_data SMPI_thread_create sg_zone_get_by_name sg_link_name sg_host_route sg_host_self sg_host_speed simcall_process_create sg_config_continue_after_help])
 	AC_CHECK_FUNCS([simgrid_init], [AC_DEFINE([STARPU_SIMGRID_HAVE_SIMGRID_INIT], [1], [Define to 1 if you have the `simgrid_init' function.])])
 	AC_CHECK_FUNCS([xbt_barrier_init], [AC_DEFINE([STARPU_SIMGRID_HAVE_XBT_BARRIER_INIT], [1], [Define to 1 if you have the `xbt_barrier_init' function.])])
 	AC_CHECK_FUNCS([sg_actor_sleep_for sg_actor_self sg_actor_ref sg_host_get_properties sg_host_send_to sg_cfg_set_int sg_actor_self_execute simgrid_get_clock])

+ 1 - 1
include/starpu_thread.h

@@ -84,7 +84,7 @@ typedef msg_host_t starpu_sg_host_t;
 #endif
 int starpu_pthread_equal(starpu_pthread_t t1, starpu_pthread_t t2);
 starpu_pthread_t starpu_pthread_self(void);
-int starpu_pthread_create_on(char *name, starpu_pthread_t *thread, const starpu_pthread_attr_t *attr, void *(*start_routine) (void *), void *arg, starpu_sg_host_t host);
+int starpu_pthread_create_on(const char *name, starpu_pthread_t *thread, const starpu_pthread_attr_t *attr, void *(*start_routine) (void *), void *arg, starpu_sg_host_t host);
 int starpu_pthread_create(starpu_pthread_t *thread, const starpu_pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
 starpu_pthread_t _starpu_simgrid_actor_create(const char *name, xbt_main_func_t code, starpu_sg_host_t host, int argc, char *argv[]);
 int starpu_pthread_join(starpu_pthread_t thread, void **retval);

+ 1 - 1
src/common/thread.c

@@ -72,7 +72,7 @@ starpu_pthread_t starpu_pthread_self(void)
 #endif
 }
 
-int starpu_pthread_create_on(char *name, starpu_pthread_t *thread, const starpu_pthread_attr_t *attr STARPU_ATTRIBUTE_UNUSED, void *(*start_routine) (void *), void *arg, starpu_sg_host_t host)
+int starpu_pthread_create_on(const char *name, starpu_pthread_t *thread, const starpu_pthread_attr_t *attr STARPU_ATTRIBUTE_UNUSED, void *(*start_routine) (void *), void *arg, starpu_sg_host_t host)
 {
 	char **_args;
 	_STARPU_MALLOC(_args, 3*sizeof(char*));

+ 28 - 1
src/core/simgrid_cpp.cpp

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2016,2017                                CNRS
- * Copyright (C) 2012-2019                                Université de Bordeaux
+ * Copyright (C) 2012-2020                                Université de Bordeaux
  * Copyright (C) 2016,2017                                Inria
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -26,6 +26,7 @@
 #else
 #include <simgrid/simix.h>
 #endif
+#include <smpi/smpi.h>
 
 /* thread_create function which implements inheritence of MPI privatization */
 /* See https://github.com/simgrid/simgrid/issues/139 */
@@ -34,9 +35,26 @@ typedef struct
 {
 	void_f_pvoid_t code;
 	void *userparam;
+#if SIMGRID_VERSION >= 32501
 	void *father_data;
+#endif
 } thread_data_t;
 
+#if SIMGRID_VERSION >= 32501
+static void *_starpu_simgrid_xbt_thread_create_wrapper(void *arg)
+{
+	thread_data_t *t = (thread_data_t *) arg;
+	/* FIXME: Ugly work-around for bug in simgrid: the MPI context is not properly set at MSG process startup */
+	starpu_sleep(0.000001);
+#ifdef HAVE_SMPI_THREAD_CREATE
+	/* Make this actor inherit SMPI data from father actor */
+	SMPI_thread_create();
+#endif
+	t->code(t->userparam);
+	free(t);
+	return NULL;
+}
+#else
 #if SIMGRID_VERSION >= 32190
 static void _starpu_simgrid_xbt_thread_create_wrapper(void)
 #else
@@ -66,9 +84,17 @@ static int _starpu_simgrid_xbt_thread_create_wrapper(int argc STARPU_ATTRIBUTE_U
 	return 0;
 #endif
 }
+#endif
 
 void _starpu_simgrid_xbt_thread_create(const char *name, void_f_pvoid_t code, void *param)
 {
+#if SIMGRID_VERSION >= 32501
+	starpu_pthread_t t;
+	thread_data_t *res = (thread_data_t *) malloc(sizeof(thread_data_t));
+	res->userparam = param;
+	res->code = code;
+	starpu_pthread_create_on(name, &t, NULL, _starpu_simgrid_xbt_thread_create_wrapper, res, sg_host_self());
+#else
 #if SIMGRID_VERSION >= 32190 || defined(HAVE_SIMCALL_PROCESS_CREATE) || defined(simcall_process_create)
 #ifdef HAVE_SMX_ACTOR_T
 	smx_actor_t process STARPU_ATTRIBUTE_UNUSED;
@@ -114,6 +140,7 @@ void _starpu_simgrid_xbt_thread_create(const char *name, void_f_pvoid_t code, vo
 #else
 	STARPU_ABORT_MSG("Can't run StarPU-Simgrid-MPI with a Simgrid version which does not provide simcall_process_create and does not fix https://github.com/simgrid/simgrid/issues/139 , sorry.");
 #endif
+#endif
 }
 
 #endif