Skip to content
Snippets Groups Projects
Commit d3bda985 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Don't limit auto chunk size to (int) handle > INT_MAX instead of overflowing

parent d1460bf8
No related branches found
No related tags found
1 merge request!1224Make the threadpool honour the int argument for number of elements to process
...@@ -149,7 +149,10 @@ static void threadpool_chomp(struct threadpool *tp, int tid) { ...@@ -149,7 +149,10 @@ static void threadpool_chomp(struct threadpool *tp, int tid) {
if (chunk_size < 1) chunk_size = 1; if (chunk_size < 1) chunk_size = 1;
/* A chunk cannot exceed INT_MAX, as we use int elements in map_function. */ /* 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. */ /* Get a chunk and check its size. */
size_t task_ind = atomic_add(&tp->map_data_count, chunk_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, ...@@ -321,7 +324,7 @@ void threadpool_map(struct threadpool *tp, threadpool_map_function map_function,
tp->map_data_count = 0; tp->map_data_count = 0;
if (chunk == threadpool_auto_chunk_size) { if (chunk == threadpool_auto_chunk_size) {
tp->map_data_chunk = 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) { } else if (chunk == threadpool_uniform_chunk_size) {
tp->map_data_chunk = threadpool_uniform_chunk_size; tp->map_data_chunk = threadpool_uniform_chunk_size;
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment