Browse Source

src: take into account CPUs reservation also when the number of CPUs is fixed

Nathalie Furmento 6 years ago
parent
commit
f33c634e1b
2 changed files with 17 additions and 22 deletions
  1. 15 21
      src/core/topology.c
  2. 2 1
      tests/main/bind.c

+ 15 - 21
src/core/topology.c

@@ -1447,6 +1447,7 @@ static unsigned _starpu_topology_count_ngpus(hwloc_obj_t obj)
 static int _starpu_init_machine_config(struct _starpu_machine_config *config, int no_mp_config STARPU_ATTRIBUTE_UNUSED)
 {
 	int i;
+
 	for (i = 0; i < STARPU_NMAXWORKERS; i++)
 	{
 		config->workers[i].workerid = i;
@@ -1749,33 +1750,26 @@ static int _starpu_init_machine_config(struct _starpu_machine_config *config, in
 			int nth_per_core = starpu_get_env_number_default("STARPU_NTHREADS_PER_CORE", 1);
 			avail_cpus *= nth_per_core;
 
-			if (config->conf.reserve_ncpus > 0)
+			ncpu = avail_cpus;
+		}
+
+		if (config->conf.reserve_ncpus > 0)
+		{
+			if (ncpu < config->conf.reserve_ncpus)
 			{
-				if (avail_cpus < config->conf.reserve_ncpus)
-				{
-					_STARPU_DISP("Warning: %d CPU cores were requested to be reserved, but only %ld were available,\n", config->conf.reserve_ncpus, avail_cpus);
-					avail_cpus = 0;
-				}
-				else
-				{
-					avail_cpus -= config->conf.reserve_ncpus;
-				}
+				_STARPU_DISP("Warning: %d CPU cores were requested to be reserved, but only %d were available,\n", config->conf.reserve_ncpus, ncpu);
+				ncpu = 0;
 			}
-
-			ncpu = avail_cpus;
-			if (ncpu > STARPU_MAXCPUS)
+			else
 			{
-				_STARPU_DISP("Warning: %d CPU cores detected. Only %d enabled. Use configure option --enable-maxcpus=xxx to update the maximum value of supported CPU devices.\n", ncpu, STARPU_MAXCPUS);
-				ncpu = STARPU_MAXCPUS;
+				ncpu -= config->conf.reserve_ncpus;
 			}
 		}
-		else
+
+		if (ncpu > STARPU_MAXCPUS)
 		{
-			if (ncpu > STARPU_MAXCPUS)
-			{
-				_STARPU_DISP("Warning: %d CPU cores requested. Only %d enabled. Use configure option --enable-maxcpus=xxx to update the maximum value of supported CPU devices.\n", ncpu, STARPU_MAXCPUS);
-				ncpu = STARPU_MAXCPUS;
-			}
+			_STARPU_DISP("Warning: %d CPU cores requested. Only %d enabled. Use configure option --enable-maxcpus=xxx to update the maximum value of supported CPU devices.\n", ncpu, STARPU_MAXCPUS);
+			ncpu = STARPU_MAXCPUS;
 		}
 	}
 

+ 2 - 1
tests/main/bind.c

@@ -52,7 +52,8 @@ int main(void)
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 
 	/* Make sure StarPU uses two core less */
-	STARPU_ASSERT(starpu_worker_get_count_by_type(STARPU_CPU_WORKER) == ncpus-2);
+	STARPU_ASSERT_MSG(starpu_worker_get_count_by_type(STARPU_CPU_WORKER) == ncpus-2, "Expected %d CPUs, got %d\n", ncpus-2, starpu_worker_get_count_by_type(STARPU_CPU_WORKER));
+	FPRINTF(stderr, "CPUS: %d as expected\n", starpu_worker_get_count_by_type(STARPU_CPU_WORKER));
 
 	/* Check we can grab a whole core */
 	active_bindid = starpu_get_next_bindid(STARPU_THREAD_ACTIVE, NULL, 0);