浏览代码

Use sg_actor_set_stacksize to set simgrid stack size when available

Samuel Thibault 5 年之前
父节点
当前提交
d61e2970cb
共有 6 个文件被更改,包括 35 次插入9 次删除
  1. 1 1
      configure.ac
  2. 3 1
      include/starpu_thread.h
  3. 4 3
      mpi/src/mpi/starpu_mpi_mpi.c
  4. 20 1
      src/common/thread.c
  5. 1 1
      src/core/simgrid.h
  6. 6 2
      src/core/simgrid_cpp.cpp

+ 1 - 1
configure.ac

@@ -188,7 +188,7 @@ if test x$enable_simgrid = xyes ; then
 	AC_CHECK_TYPES([smx_actor_t], [AC_DEFINE([STARPU_HAVE_SMX_ACTOR_T], [1], [Define to 1 if you have the smx_actor_t type.])], [], [[#include <simgrid/simix.h>]])
 
 	# 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([MSG_process_attach sg_actor_attach sg_actor_init sg_actor_set_stacksize 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 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.])])

+ 3 - 1
include/starpu_thread.h

@@ -76,7 +76,9 @@ typedef sg_actor_t starpu_pthread_t;
 #else
 typedef msg_process_t starpu_pthread_t;
 #endif
-typedef int starpu_pthread_attr_t;
+typedef struct {
+	size_t stacksize;
+} starpu_pthread_attr_t;
 
 #ifdef STARPU_HAVE_SIMGRID_ACTOR_H
 typedef sg_host_t starpu_sg_host_t;

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

@@ -353,9 +353,10 @@ void _starpu_mpi_simgrid_wait_req(MPI_Request *request, MPI_Status *status, star
 	sim_req->done = done;
 	*done = 0;
 
-	_starpu_simgrid_set_stack_size(32786);
-	_starpu_simgrid_xbt_thread_create("wait for mpi transfer", _starpu_mpi_simgrid_wait_req_func, sim_req);
-	_starpu_simgrid_set_stack_size(_starpu_default_stack_size);
+	starpu_pthread_attr_t attr;
+	starpu_pthread_attr_init(&attr);
+	starpu_pthread_attr_setstacksize(&attr, 32786);
+	_starpu_simgrid_xbt_thread_create("wait for mpi transfer", &attr, _starpu_mpi_simgrid_wait_req_func, sim_req);
 }
 #endif
 

+ 20 - 1
src/common/thread.c

@@ -90,8 +90,16 @@ int starpu_pthread_create_on(const char *name, starpu_pthread_t *thread, const s
 	void *tsd;
 	_STARPU_CALLOC(tsd, MAX_TSD+1, sizeof(void*));
 
+#ifndef HAVE_SG_ACTOR_SET_STACKSIZE
+	if (attr && attr->stacksize)
+		_starpu_simgrid_set_stack_size(attr->stacksize);
+#endif
 #ifdef HAVE_SG_ACTOR_INIT
 	*thread= sg_actor_init(name, host);
+#ifdef HAVE_SG_ACTOR_SET_STACKSIZE
+	if (attr && attr->stacksize)
+		sg_actor_set_stacksize(*thread, attr->stacksize);
+#endif
 	sg_actor_data_set(*thread, tsd);
 	sg_actor_start(*thread, _starpu_simgrid_thread_start, 2, _args);
 #else
@@ -100,6 +108,10 @@ int starpu_pthread_create_on(const char *name, starpu_pthread_t *thread, const s
 	sg_actor_data_set(*thread, tsd);
 #endif
 #endif
+#ifndef HAVE_SG_ACTOR_SET_STACKSIZE
+	if (attr && attr->stacksize)
+		_starpu_simgrid_set_stack_size(_starpu_default_stack_size);
+#endif
 
 #if SIMGRID_VERSION >= 31500 && SIMGRID_VERSION != 31559
 #  ifdef HAVE_SG_ACTOR_REF
@@ -148,8 +160,9 @@ int starpu_pthread_exit(void *retval STARPU_ATTRIBUTE_UNUSED)
 }
 
 
-int starpu_pthread_attr_init(starpu_pthread_attr_t *attr STARPU_ATTRIBUTE_UNUSED)
+int starpu_pthread_attr_init(starpu_pthread_attr_t *attr)
 {
+	attr->stacksize = 0;
 	return 0;
 }
 
@@ -158,6 +171,12 @@ int starpu_pthread_attr_destroy(starpu_pthread_attr_t *attr STARPU_ATTRIBUTE_UNU
 	return 0;
 }
 
+int starpu_pthread_attr_setstacksize(starpu_pthread_attr_t *attr, size_t stacksize)
+{
+	attr->stacksize = stacksize;
+	return 0;
+}
+
 int starpu_pthread_attr_setdetachstate(starpu_pthread_attr_t *attr STARPU_ATTRIBUTE_UNUSED, int detachstate STARPU_ATTRIBUTE_UNUSED)
 {
 	return 0;

+ 1 - 1
src/core/simgrid.h

@@ -105,7 +105,7 @@ void _starpu_simgrid_count_ngpus(void);
 
 extern size_t _starpu_default_stack_size;
 void _starpu_simgrid_set_stack_size(size_t stack_size);
-void _starpu_simgrid_xbt_thread_create(const char *name, void_f_pvoid_t code,
+void _starpu_simgrid_xbt_thread_create(const char *name, starpu_pthread_attr_t *attr, void_f_pvoid_t code,
 				       void *param);
 
 #define _SIMGRID_TIMER_BEGIN(cond)			\

+ 6 - 2
src/core/simgrid_cpp.cpp

@@ -84,15 +84,17 @@ static int _starpu_simgrid_xbt_thread_create_wrapper(int argc STARPU_ATTRIBUTE_U
 }
 #endif
 
-void _starpu_simgrid_xbt_thread_create(const char *name, void_f_pvoid_t code, void *param)
+void _starpu_simgrid_xbt_thread_create(const char *name, starpu_pthread_attr_t *attr, 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());
+	starpu_pthread_create_on(name, &t, attr, _starpu_simgrid_xbt_thread_create_wrapper, res, sg_host_self());
 #else
+	if (attr && attr->stacksize)
+		_starpu_simgrid_set_stack_size(attr->stacksize);
 #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;
@@ -138,6 +140,8 @@ 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
+	if (attr && attr->stacksize)
+		_starpu_simgrid_set_stack_size(_starpu_default_stack_size);
 #endif
 }