@@ -84,6 +84,7 @@ using std::vector;
8484using std::list;
8585
8686static double rec_sum;
87+ static int original_p_ncpus;
8788
8889// used in make_run_list() to keep track of resources used
8990// by jobs tentatively scheduled so far
@@ -1286,6 +1287,33 @@ bool CLIENT_STATE::enforce_run_list(vector<RESULT*>& run_list) {
12861287
12871288 ACTIVE_TASK *atp = lookup_active_task_by_result (rp);
12881289
1290+ // Skip jobs if they would cause too many CPUs to be used.
1291+ //
1292+ // An MT could overcommit the CPUs by > 1.
1293+ // Options are:
1294+ // 1) run it anyway, and overcommit the CPUs
1295+ // 2) don't run it.
1296+ // This can result in starvation.
1297+ // 3) don't run it if there are additional 1-CPU jobs.
1298+ // The problem here is that we may never run the MT job
1299+ // until it reaches deadline pressure.
1300+ // We'll go with 1) except if user has limited the #CPUs
1301+
1302+ // if user has limited the # of CPUs, don't use more than the limit
1303+ // (even if it means idle instances of CPU or GPU)
1304+ //
1305+ if (n_usable_cpus < original_p_ncpus
1306+ && ncpus_used + rp->resource_usage .avg_ncpus > n_usable_cpus
1307+ ) {
1308+ if (log_flags.cpu_sched_debug ) {
1309+ msg_printf (rp->project , MSG_INFO ,
1310+ " [cpu_sched_debug] skipping %s: would exceed user-specified CPU limit" ,
1311+ rp->name
1312+ );
1313+ }
1314+ continue ;
1315+ }
1316+
12891317 // if we're already using all the CPUs, don't allow additional CPU jobs;
12901318 // allow coproc jobs if the resulting CPU load is at most ncpus+1
12911319 //
@@ -1312,17 +1340,6 @@ bool CLIENT_STATE::enforce_run_list(vector<RESULT*>& run_list) {
13121340 }
13131341 }
13141342
1315- // There's a possibility that this job is MT
1316- // and would overcommit the CPUs by > 1.
1317- // Options are:
1318- // 1) run it anyway, and overcommit the CPUs
1319- // 2) don't run it.
1320- // This can result in starvation.
1321- // 3) don't run it if there are additional 1-CPU jobs.
1322- // The problem here is that we may never run the MT job
1323- // until it reaches deadline pressure.
1324- // So we'll go with 1).
1325-
13261343 // skip jobs whose 'expected working set size' (EWSS)
13271344 // is too large to fit in available RAM.
13281345 // To compute EWSS, we start with
@@ -1675,7 +1692,6 @@ void CLIENT_STATE::set_n_usable_cpus() {
16751692 // config file can say to act like host has N CPUs
16761693 //
16771694 static bool first = true ;
1678- static int original_p_ncpus;
16791695 if (first) {
16801696 original_p_ncpus = host_info.p_ncpus ;
16811697 first = false ;
0 commit comments