aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarat Dukhan <maratek@gmail.com>2015-11-02 17:47:04 -0500
committerMarat Dukhan <maratek@gmail.com>2015-11-02 17:47:04 -0500
commite76282f42e5f5443dd07ca73452f3eb912e542e7 (patch)
tree7755cb5ef854eb4af2d39a22f6a33acd23099d9f /src
parentad0ca6ade44155d342d2480c579c143751d5891c (diff)
downloadpthreadpool-e76282f42e5f5443dd07ca73452f3eb912e542e7.tar.gz
Tiled 1D loops
Diffstat (limited to 'src')
-rw-r--r--src/pthreadpool.c31
1 files changed, 31 insertions, 0 deletions
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;