瀏覽代碼

fix compatibility with simgrid 3.14

Samuel Thibault 8 年之前
父節點
當前提交
541061fada
共有 6 個文件被更改,包括 46 次插入21 次删除
  1. 1 0
      configure.ac
  2. 1 0
      include/starpu_config.h.in
  3. 4 0
      include/starpu_thread.h
  4. 1 1
      mpi/src/starpu_mpi.c
  5. 9 3
      src/common/thread.c
  6. 30 17
      src/core/simgrid.c

+ 1 - 0
configure.ac

@@ -1105,6 +1105,7 @@ if test x$enable_simgrid = xyes ; then
 		]
 	)
 	AC_CHECK_HEADERS([simgrid/msg.h], [AC_DEFINE([STARPU_HAVE_SIMGRID_MSG_H], [1], [Define to 1 if you have msg.h in simgrid/.])])
+	AC_CHECK_HEADERS([xbt/synchro.h], [AC_DEFINE([STARPU_HAVE_XBT_SYNCHRO_H], [1], [Define to 1 if you have synchro.h in xbt/.])])
    	AC_CHECK_FUNCS([MSG_process_join MSG_process_attach MSG_get_as_by_name MSG_environment_get_routing_root MSG_host_get_speed xbt_mutex_try_acquire smpi_process_set_user_data sg_link_name])
 	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_DECLS([smpi_process_set_user_data], [], [], [[#include <smpi/smpi.h>]])

+ 1 - 0
include/starpu_config.h.in

@@ -41,6 +41,7 @@
 #undef STARPU_SIMGRID
 #undef STARPU_SIMGRID_HAVE_XBT_BARRIER_INIT
 #undef STARPU_HAVE_SIMGRID_MSG_H
+#undef STARPU_HAVE_XBT_SYNCHRO_H
 
 #undef STARPU_HAVE_ICC
 

+ 4 - 0
include/starpu_thread.h

@@ -21,7 +21,11 @@
 #include <starpu_config.h>
 #include <starpu_util.h>
 #ifdef STARPU_SIMGRID
+#ifdef STARPU_HAVE_XBT_SYNCHRO_H
+#include <xbt/synchro.h>
+#else
 #include <xbt/synchro_core.h>
+#endif
 #ifdef STARPU_HAVE_SIMGRID_MSG_H
 #include <simgrid/msg.h>
 #else

+ 1 - 1
mpi/src/starpu_mpi.c

@@ -1303,7 +1303,7 @@ static void *_starpu_mpi_progress_thread_func(void *arg)
 	MSG_process_create_with_arguments("main", smpi_simulated_main_, NULL, _starpu_simgrid_get_host_by_name("MAIN"), *(argc_argv->argc), argv_cpy);
 	/* And set TSD for us */
 #ifdef HAVE_SMPI_PROCESS_SET_USER_DATA
-	smpi_process_set_user_data(calloc(MAX_TSD, sizeof(void*)));
+	smpi_process_set_user_data(calloc(MAX_TSD + 1, sizeof(void*)));
 #endif
 #endif
 #ifdef STARPU_USE_FXT

+ 9 - 3
src/common/thread.c

@@ -20,7 +20,11 @@
 #include <core/workers.h>
 
 #ifdef STARPU_SIMGRID
+#ifdef STARPU_HAVE_XBT_SYNCHRO_H
+#include <xbt/synchro.h>
+#else
 #include <xbt/synchro_core.h>
+#endif
 #include <smpi/smpi.h>
 #else
 
@@ -53,7 +57,7 @@ int starpu_pthread_create_on(char *name, starpu_pthread_t *thread, const starpu_
 	_args[2] = NULL;
 	if (!host)
 		host = MSG_get_host_by_name("MAIN");
-	*thread = MSG_process_create_with_arguments(name, _starpu_simgrid_thread_start, calloc(MAX_TSD, sizeof(void*)), host, 2, _args);
+	*thread = MSG_process_create_with_arguments(name, _starpu_simgrid_thread_start, calloc(MAX_TSD+1, sizeof(void*)), host, 2, _args);
 	return 0;
 }
 
@@ -181,6 +185,7 @@ int starpu_pthread_mutexattr_init(starpu_pthread_mutexattr_t *attr STARPU_ATTRIB
 }
 
 
+/* Indexed by key-1 */
 static int used_key[MAX_TSD];
 
 int starpu_pthread_key_create(starpu_pthread_key_t *key, void (*destr_function) (void *) STARPU_ATTRIBUTE_UNUSED)
@@ -195,13 +200,14 @@ int starpu_pthread_key_create(starpu_pthread_key_t *key, void (*destr_function)
 			break;
 		}
 	STARPU_ASSERT(i < MAX_TSD);
-	*key = i;
+	/* key 0 is for process pointer argument */
+	*key = i+1;
 	return 0;
 }
 
 int starpu_pthread_key_delete(starpu_pthread_key_t key)
 {
-	used_key[key] = 0;
+	used_key[key-1] = 0;
 	return 0;
 }
 

+ 30 - 17
src/core/simgrid.c

@@ -227,10 +227,9 @@ struct main_args
 };
 static int main_ret;
 
-int do_starpu_main(int argc STARPU_ATTRIBUTE_UNUSED, char *argv[])
+int do_starpu_main(int argc, char *argv[])
 {
-	struct main_args *args = (void*) argv;
-	main_ret = starpu_main(args->argc, args->argv);
+	main_ret = starpu_main(argc, argv);
 	return main_ret;
 }
 
@@ -249,11 +248,12 @@ int main(int argc, char **argv)
 	start_simgrid(&argc, argv);
 
 	/* Create a simgrid process for main */
-	struct main_args *args;
-	_STARPU_MALLOC(args, sizeof(*args));
-	args->argc = argc;
-	args->argv = argv;
-	MSG_process_create_with_arguments("main", &do_starpu_main, calloc(MAX_TSD, sizeof(void*)), MSG_get_host_by_name("MAIN"), 0, (char**) args);
+	char **argv_cpy;
+	_STARPU_MALLOC(argv_cpy, argc * sizeof(char*));
+	int i;
+	for (i = 0; i < argc; i++)
+		argv_cpy[i] = strdup(argv[i]);
+	MSG_process_create_with_arguments("main", &do_starpu_main, calloc(MAX_TSD+1, sizeof(void*)), MSG_get_host_by_name("MAIN"), argc, argv_cpy);
 
 	/* And run maestro in main thread */
 	MSG_main();
@@ -265,7 +265,7 @@ static void maestro(void *data STARPU_ATTRIBUTE_UNUSED)
 	MSG_main();
 }
 
-void _starpu_simgrid_init(int *argc, char ***argv)
+void _starpu_simgrid_init(int *argc STARPU_ATTRIBUTE_UNUSED, char ***argv STARPU_ATTRIBUTE_UNUSED)
 {
 #ifdef HAVE_MSG_PROCESS_ATTACH
 	if (!simgrid_started && !(smpi_main && smpi_simulated_main_ != _starpu_smpi_simulated_main_))
@@ -336,9 +336,9 @@ struct task
 static struct task *last_task[STARPU_NMAXWORKERS];
 
 /* Actually execute the task.  */
-static int task_execute(int argc STARPU_ATTRIBUTE_UNUSED, char *argv[])
+static int task_execute(int argc STARPU_ATTRIBUTE_UNUSED, char *argv[] STARPU_ATTRIBUTE_UNUSED)
 {
-	struct task *task = (void*) argv;
+	struct task *task = starpu_pthread_getspecific(0);
 	_STARPU_DEBUG("task %p started\n", task);
 	MSG_task_execute(task->task);
 	MSG_task_destroy(task->task);
@@ -354,7 +354,11 @@ static int task_execute(int argc STARPU_ATTRIBUTE_UNUSED, char *argv[])
 	if (last_task[task->workerid] == task)
 		last_task[task->workerid] = NULL;
 	if (task->next)
-		MSG_process_create_with_arguments("task", task_execute, calloc(MAX_TSD, sizeof(void*)), MSG_host_self(), 0, (char**) task->next);
+	{
+		void **tsd = calloc(MAX_TSD+1, sizeof(void*));
+		tsd[0] = task->next;
+		MSG_process_create_with_arguments("task", task_execute, tsd, MSG_host_self(), 0, NULL);
+	}
 	/* Task is freed with process context */
 	return 0;
 }
@@ -433,8 +437,11 @@ void _starpu_simgrid_submit_job(int workerid, struct _starpu_job *j, struct star
 		}
 		else
 		{
+			void **tsd;
 			last_task[workerid] = task;
-			MSG_process_create_with_arguments("task", task_execute, calloc(MAX_TSD, sizeof(void*)), MSG_host_self(), 0, (char**) task);
+			tsd = calloc(MAX_TSD+1, sizeof(void*));
+			tsd[0] = task;
+			MSG_process_create_with_arguments("task", task_execute, tsd, MSG_host_self(), 0, NULL);
 		}
 	}
 }
@@ -517,9 +524,9 @@ static int transfers_are_sequential(struct transfer *new_transfer, struct transf
 }
 
 /* Actually execute the transfer, and then start transfers waiting for this one.  */
-static int transfer_execute(int argc STARPU_ATTRIBUTE_UNUSED, char *argv[])
+static int transfer_execute(int argc STARPU_ATTRIBUTE_UNUSED, char *argv[] STARPU_ATTRIBUTE_UNUSED)
 {
-	struct transfer *transfer = (void*) argv;
+	struct transfer *transfer = starpu_pthread_getspecific(0);
 	unsigned i;
 	_STARPU_DEBUG("transfer %p started\n", transfer);
 	MSG_task_execute(transfer->task);
@@ -543,8 +550,11 @@ static int transfer_execute(int argc STARPU_ATTRIBUTE_UNUSED, char *argv[])
 		wake->nwait--;
 		if (!wake->nwait)
 		{
+			void **tsd;
 			_STARPU_DEBUG("triggering transfer %p\n", wake);
-			MSG_process_create_with_arguments("transfer task", transfer_execute, calloc(MAX_TSD, sizeof(void*)), _starpu_simgrid_get_host_by_name("MAIN"), 0, (char**) wake);
+			tsd = calloc(MAX_TSD+1, sizeof(void*));
+			tsd[0] = wake;
+			MSG_process_create_with_arguments("transfer task", transfer_execute, tsd, _starpu_simgrid_get_host_by_name("MAIN"), 0, NULL);
 		}
 	}
 
@@ -581,8 +591,11 @@ static void transfer_submit(struct transfer *transfer)
 
 	if (!transfer->nwait)
 	{
+		void **tsd;
 		_STARPU_DEBUG("transfer %p waits for nobody, starting\n", transfer);
-		MSG_process_create_with_arguments("transfer task", transfer_execute, calloc(MAX_TSD, sizeof(void*)), _starpu_simgrid_get_host_by_name("MAIN"), 0, (char**) transfer);
+		tsd = calloc(MAX_TSD+1, sizeof(void*));
+		tsd[0] = transfer;
+		MSG_process_create_with_arguments("transfer task", transfer_execute, tsd, _starpu_simgrid_get_host_by_name("MAIN"), 0, NULL);
 	}
 }