From d3bda985a9de6770b9800720b30bf3347dd9dcb9 Mon Sep 17 00:00:00 2001 From: "Peter W. Draper" <p.w.draper@durham.ac.uk> Date: Wed, 11 Nov 2020 11:41:35 +0000 Subject: [PATCH] Don't limit auto chunk size to (int) handle > INT_MAX instead of overflowing --- src/threadpool.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/threadpool.c b/src/threadpool.c index d5fa6d1022..70bb1716d0 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -149,7 +149,10 @@ static void threadpool_chomp(struct threadpool *tp, int tid) { if (chunk_size < 1) chunk_size = 1; /* A chunk cannot exceed INT_MAX, as we use int elements in map_function. */ - if (chunk_size > INT_MAX) chunk_size = INT_MAX; + if (chunk_size > INT_MAX) { + chunk_size = INT_MAX; +. message("chunking down to INT_MAX"); + } /* Get a chunk and check its size. */ size_t task_ind = atomic_add(&tp->map_data_count, chunk_size); @@ -321,7 +324,7 @@ void threadpool_map(struct threadpool *tp, threadpool_map_function map_function, tp->map_data_count = 0; if (chunk == threadpool_auto_chunk_size) { tp->map_data_chunk = - max((int)(N / (tp->num_threads * threadpool_default_chunk_ratio)), 1); + max((N / (tp->num_threads * threadpool_default_chunk_ratio)), 1); } else if (chunk == threadpool_uniform_chunk_size) { tp->map_data_chunk = threadpool_uniform_chunk_size; } else { -- GitLab