• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

bench/H03-Mar-2021-501394

cmake/H03-Mar-2021-6452

examples/H03-Mar-2021-4937

include/H03-Mar-2021-1,163305

jni/H03-Mar-2021-2317

src/H03-Mar-2021-7,2955,785

test/H03-Mar-2021-7,3996,178

.gitignoreH A D03-Mar-2021268 2825

.travis.ymlH A D03-Mar-2021156 1312

BUILD.bazelH A D03-Mar-202110.7 KiB418369

LICENSEH A D03-Mar-20211.3 KiB2721

README.mdH A D03-Mar-20212.1 KiB6246

WORKSPACEH A D03-Mar-20211.3 KiB3931

configure.pyH A D03-Mar-20211.2 KiB3926

confu.yamlH A D03-Mar-2021195 98

README.md

1# pthreadpool
2
3[![BSD (2 clause) License](https://img.shields.io/badge/License-BSD%202--Clause%20%22Simplified%22%20License-blue.svg)](https://github.com/Maratyszcza/pthreadpool/blob/master/LICENSE)
4[![Build Status](https://img.shields.io/travis/Maratyszcza/pthreadpool.svg)](https://travis-ci.org/Maratyszcza/pthreadpool)
5
6**pthreadpool** is a portable and efficient thread pool implementation.
7It provides similar functionality to `#pragma omp parallel for`, but with additional features.
8
9## Features:
10
11* C interface (C++-compatible).
12* 1D-6D loops with step parameters.
13* Run on user-specified or auto-detected number of threads.
14* Work-stealing scheduling for efficient work balancing.
15* Wait-free synchronization of work items.
16* Compatible with Linux (including Android), macOS, iOS, Windows, Emscripten environments.
17* 100% unit tests coverage.
18* Throughput and latency microbenchmarks.
19
20## Example
21
22  The following example demonstates using the thread pool for parallel addition of two arrays:
23
24```c
25static void add_arrays(struct array_addition_context* context, size_t i) {
26  context->sum[i] = context->augend[i] + context->addend[i];
27}
28
29#define ARRAY_SIZE 4
30
31int main() {
32  double augend[ARRAY_SIZE] = { 1.0, 2.0, 4.0, -5.0 };
33  double addend[ARRAY_SIZE] = { 0.25, -1.75, 0.0, 0.5 };
34  double sum[ARRAY_SIZE];
35
36  pthreadpool_t threadpool = pthreadpool_create(0);
37  assert(threadpool != NULL);
38
39  const size_t threads_count = pthreadpool_get_threads_count(threadpool);
40  printf("Created thread pool with %zu threads\n", threads_count);
41
42  struct array_addition_context context = { augend, addend, sum };
43  pthreadpool_parallelize_1d(threadpool,
44    (pthreadpool_task_1d_t) add_arrays,
45    (void*) &context,
46    ARRAY_SIZE,
47    PTHREADPOOL_FLAG_DISABLE_DENORMALS /* flags */);
48
49  pthreadpool_destroy(threadpool);
50  threadpool = NULL;
51
52  printf("%8s\t%.2lf\t%.2lf\t%.2lf\t%.2lf\n", "Augend",
53    augend[0], augend[1], augend[2], augend[3]);
54  printf("%8s\t%.2lf\t%.2lf\t%.2lf\t%.2lf\n", "Addend",
55    addend[0], addend[1], addend[2], addend[3]);
56  printf("%8s\t%.2lf\t%.2lf\t%.2lf\t%.2lf\n", "Sum",
57    sum[0], sum[1], sum[2], sum[3]);
58
59  return 0;
60}
61```
62