@@ -1361,18 +1361,24 @@ namespace driver {
1361
1361
// subprocesses than before. And significantly: it's doing so while
1362
1362
// not exceeding the RAM of a typical 2-core laptop.
1363
1363
1364
+ // An explanation of why the partition calculation isn't integer division.
1365
+ // Using an example, a module of 26 files exceeds the limit of 25 and must
1366
+ // be compiled in 2 batches. Integer division yields 26/25 = 1 batch, but
1367
+ // a single batch of 26 exceeds the limit. The calculation must round up,
1368
+ // which can be calculated using: `(x + y - 1) / y`
1369
+ //
1370
+ // Two key properties of this calculation are:
1371
+ // DivideUp(M*N, N) = M
1372
+ // DivideUp(M*N + 1, N) = M + 1
1373
+ auto DivideUp = [](size_t Num, size_t Div) -> size_t {
1374
+ return (Num + Div - 1 ) / Div;
1375
+ };
1376
+
1364
1377
size_t DefaultSizeLimit = 25 ;
1365
1378
size_t NumTasks = TQ->getNumberOfParallelTasks ();
1366
1379
size_t NumFiles = PendingExecution.size ();
1367
1380
size_t SizeLimit = Comp.getBatchSizeLimit ().getValueOr (DefaultSizeLimit);
1368
-
1369
- // An explanation of why the partition calculation isn't simple division.
1370
- // Using the default limit as an example, a module of 26 files must be
1371
- // compiled in 2 batches. Simple division yields 26/25 = 1 batch, but a
1372
- // single batch of 26 would exceed the limit of 25. To round up, the
1373
- // calculation is: `(x - 1) / y + 1`.
1374
- size_t NumPartitions = (NumFiles - 1 ) / SizeLimit + 1 ;
1375
- return std::max (NumTasks, NumPartitions);
1381
+ return std::max (NumTasks, DivideUp (NumFiles, SizeLimit));
1376
1382
}
1377
1383
1378
1384
// / Select jobs that are batch-combinable from \c PendingExecution, combine
0 commit comments