Fix last batch when n_tasks in not a multiple of batch size.

This commit is contained in:
Paul Irofti 2025-03-30 15:48:13 +03:00
parent 5cf9e119c6
commit 5c34ae92de

View file

@ -233,7 +233,13 @@ SEXP CCubes(SEXP tt) {
int n_tasks_batch = 512;
for (int task = 0; task < n_tasks; task+=n_tasks_batch) {
/* adjust if batch size is larger than total job size */
int current_batch = n_tasks < n_tasks_batch ? n_tasks : n_tasks_batch;
int current_batch = n_tasks_batch;
/* single batch */
if (n_tasks < n_tasks_batch)
current_batch = n_tasks;
/* last batch */
if (n_tasks - task < n_tasks_batch)
current_batch = n_tasks - task;
log_debug("ccubes", "Tasks %d - %d out of %d",
task, task + current_batch - 1, n_tasks);