Browse Source

Add env vars STARPU_MAIN_THREAD_COREID and STARPU_MPI_THREAD_COREID

Philippe SWARTVAGHER 4 years ago
parent
commit
f59eb3645b

+ 2 - 1
ChangeLog

@@ -57,7 +57,8 @@ Small features:
     automatically called when the task does not define itself a
     callback function, in that case, it can still be called from the
     task callback function.
-  * New STARPU_WORKERS_COREID environment variable to bind workers to cores
+  * New STARPU_WORKERS_COREID, STARPU_MAIN_THREAD_COREID and
+    STARPU_MPI_THREAD_COREID environment variables to bind threads to cores
     instead of hyperthreads.
 
 StarPU 1.3.7

+ 16 - 0
doc/doxygen/chapters/501_environment_variables.doxy

@@ -254,6 +254,14 @@ When defined, this make StarPU bind the thread that calls starpu_initialize() to
 the given CPU ID.
 </dd>
 
+<dt>STARPU_MAIN_THREAD_COREID</dt>
+<dd>
+\anchor STARPU_MAIN_THREAD_COREID
+\addindex __env__STARPU_MAIN_THREAD_COREID
+Same as \ref STARPU_MAIN_THREAD_CPUID, but bind the thread that calls
+starpu_initialize() to the given core, instead of the PU (hyperthread).
+</dd>
+
 <dt>STARPU_MPI_THREAD_CPUID</dt>
 <dd>
 \anchor STARPU_MPI_THREAD_CPUID
@@ -263,6 +271,14 @@ it to -1 (the default value) will use a reserved CPU, subtracted from the CPU
 workers.
 </dd>
 
+<dt>STARPU_MPI_THREAD_COREID</dt>
+<dd>
+\anchor STARPU_MPI_THREAD_COREID
+\addindex __env__STARPU_MPI_THREAD_COREID
+Same as \ref STARPU_MPI_THREAD_CPUID, but bind the MPI thread to the given core
+ID, instead of the PU (hyperthread).
+</dd>
+
 <dt>STARPU_MPI_NOBIND</dt>
 <dd>
 \anchor STARPU_MPI_NOBIND

+ 11 - 0
mpi/src/starpu_mpi_private.c

@@ -15,6 +15,7 @@
  */
 
 #include <starpu_mpi_private.h>
+#include <core/topology.h>
 
 int _starpu_debug_rank=-1;
 int _starpu_debug_level_min=0;
@@ -70,4 +71,14 @@ void _starpu_mpi_env_init(void)
 	_starpu_mpi_mem_throttle = starpu_get_env_number_default("STARPU_MPI_MEM_THROTTLE", 0);
 	_starpu_debug_level_min = starpu_get_env_number_default("STARPU_MPI_DEBUG_LEVEL_MIN", 0);
 	_starpu_debug_level_max = starpu_get_env_number_default("STARPU_MPI_DEBUG_LEVEL_MAX", 0);
+
+	int mpi_thread_coreid = starpu_get_env_number_default("STARPU_MPI_THREAD_COREID", -1);
+	if (_starpu_mpi_thread_cpuid >= 0 && mpi_thread_coreid >= 0)
+	{
+		_STARPU_DISP("Warning: STARPU_MPI_THREAD_CPUID and STARPU_MPI_THREAD_COREID cannot be set at the same time. STARPU_MAIN_THREAD_CPUID will be used.\n");
+	}
+	if (_starpu_mpi_thread_cpuid == -1 && mpi_thread_coreid >= 0)
+	{
+		_starpu_mpi_thread_cpuid = mpi_thread_coreid * _starpu_get_nhyperthreads();
+	}
 }

+ 7 - 0
src/core/topology.c

@@ -3130,3 +3130,10 @@ hwloc_topology_t starpu_get_hwloc_topology(void)
 	return config->topology.hwtopology;
 }
 #endif
+
+unsigned _starpu_get_nhyperthreads()
+{
+	struct _starpu_machine_config *config = _starpu_get_machine_config();
+
+	return config->topology.nhwpus / config->topology.nhwcpus;
+}

+ 3 - 0
src/core/topology.h

@@ -59,6 +59,9 @@ unsigned _starpu_topology_get_nhwpu(struct _starpu_machine_config *config);
 /** returns the number of NUMA nodes */
 unsigned _starpu_topology_get_nnumanodes(struct _starpu_machine_config *config);
 
+/** returns the number of hyperthreads per core */
+unsigned _starpu_get_nhyperthreads();
+
 #ifdef STARPU_HAVE_HWLOC
 /** Small convenient function to filter hwloc topology depending on HWLOC API version */
 void _starpu_topology_filter(hwloc_topology_t topology);

+ 9 - 0
src/core/workers.c

@@ -1638,6 +1638,15 @@ int starpu_initialize(struct starpu_conf *user_conf, int *argc, char ***argv)
 	STARPU_PTHREAD_MUTEX_UNLOCK(&init_mutex);
 
 	int main_thread_cpuid = starpu_get_env_number_default("STARPU_MAIN_THREAD_CPUID", -1);
+	int main_thread_coreid = starpu_get_env_number_default("STARPU_MAIN_THREAD_COREID", -1);
+	if (main_thread_cpuid >= 0 && main_thread_coreid >= 0)
+	{
+		_STARPU_DISP("Warning: STARPU_MAIN_THREAD_CPUID and STARPU_MAIN_THREAD_COREID cannot be set at the same time. STARPU_MAIN_THREAD_CPUID will be used.\n");
+	}
+	if (main_thread_cpuid == -1 && main_thread_coreid >= 0)
+	{
+		main_thread_cpuid = main_thread_coreid * _starpu_get_nhyperthreads();
+	}
 	int main_thread_bind = starpu_get_env_number_default("STARPU_MAIN_THREAD_BIND", 0);
 	int main_thread_activity = STARPU_NONACTIVETHREAD;
 	if (main_thread_bind)