aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/pthreadpool.h8
-rw-r--r--src/pthreadpool.c31
2 files changed, 39 insertions, 0 deletions
diff --git a/include/pthreadpool.h b/include/pthreadpool.h
index 150e4ad..fa2bb1e 100644
--- a/include/pthreadpool.h
+++ b/include/pthreadpool.h
@@ -6,6 +6,7 @@
typedef struct pthreadpool* pthreadpool_t;
typedef void (*pthreadpool_function_1d_t)(void*, size_t);
+typedef void (*pthreadpool_function_1d_tiled_t)(void*, size_t, size_t);
typedef void (*pthreadpool_function_2d_t)(void*, size_t, size_t);
typedef void (*pthreadpool_function_2d_tiled_t)(void*, size_t, size_t, size_t, size_t);
typedef void (*pthreadpool_function_3d_t)(void*, size_t, size_t, size_t);
@@ -57,6 +58,13 @@ void pthreadpool_compute_1d(
void* argument,
size_t range);
+void pthreadpool_compute_1d_tiled(
+ pthreadpool_t threadpool,
+ pthreadpool_function_1d_tiled_t function,
+ void* argument,
+ size_t range,
+ size_t tile);
+
void pthreadpool_compute_2d(
pthreadpool_t threadpool,
pthreadpool_function_2d_t function,
diff --git a/src/pthreadpool.c b/src/pthreadpool.c
index 5c4d1ae..a181621 100644
--- a/src/pthreadpool.c
+++ b/src/pthreadpool.c
@@ -306,6 +306,37 @@ void pthreadpool_compute_1d(
}
}
+struct compute_1d_tiled_context {
+ pthreadpool_function_1d_tiled_t function;
+ void* argument;
+ size_t range;
+ size_t tile;
+};
+
+static void compute_1d_tiled(const struct compute_1d_tiled_context* context, size_t linear_index) {
+ const size_t tile_index = linear_index;
+ const size_t index = tile_index * context->tile;
+ const size_t tile = min(context->tile, context->range - index);
+ context->function(context->argument, index, tile);
+}
+
+void pthreadpool_compute_1d_tiled(
+ pthreadpool_t threadpool,
+ pthreadpool_function_1d_tiled_t function,
+ void* argument,
+ size_t range,
+ size_t tile)
+{
+ const size_t tile_range = divide_round_up(range, tile);
+ struct compute_1d_tiled_context context = {
+ .function = function,
+ .argument = argument,
+ .range = range,
+ .tile = tile
+ };
+ pthreadpool_compute_1d(threadpool, (pthreadpool_function_1d_t) compute_1d_tiled, &context, tile_range);
+}
+
struct compute_2d_context {
pthreadpool_function_2d_t function;
void* argument;