Skip to content

Commit 51bbaeb

Browse files
authored
Merge pull request #28972 from kastiglione/dl/correct-batch-mode-partitiion-count-calculation
Adjust batch mode partition count calculation
2 parents d6eebe9 + 477763e commit 51bbaeb

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/Driver/Compilation.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,11 +1361,20 @@ namespace driver {
13611361
// subprocesses than before. And significantly: it's doing so while
13621362
// not exceeding the RAM of a typical 2-core laptop.
13631363

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+
auto DivideRoundingUp = [](size_t Num, size_t Div) -> size_t {
1370+
return (Num + Div - 1) / Div;
1371+
};
1372+
13641373
size_t DefaultSizeLimit = 25;
13651374
size_t NumTasks = TQ->getNumberOfParallelTasks();
13661375
size_t NumFiles = PendingExecution.size();
13671376
size_t SizeLimit = Comp.getBatchSizeLimit().getValueOr(DefaultSizeLimit);
1368-
return std::max(NumTasks, NumFiles / SizeLimit);
1377+
return std::max(NumTasks, DivideRoundingUp(NumFiles, SizeLimit));
13691378
}
13701379

13711380
/// Select jobs that are batch-combinable from \c PendingExecution, combine

0 commit comments

Comments
 (0)