File: README.md

package info (click to toggle)
paryfor 0.1-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 236 kB
  • sloc: cpp: 1,932; sh: 16; makefile: 4
file content (41 lines) | stat: -rw-r--r-- 1,010 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# paryfor

a parallel_for implementation based on atomic queues

## usage

The `parallel_for` templates replace `#pragma omp parallel for`.
We use a callback that takes the iteration number.
To avoid compiler confusion, we can specify the iteration type in the template.

```c++
#include "paryfor.hpp"

int main(int argc, char** argv) {
    uint64_t todo_count = std::stoul(argv[1]);
    int thread_count = std::stoi(argv[2]);
    int chunk_size = std::stoi(argv[3]);
    paryfor::parallel_for<uint64_t>(
        0, todo_count, thread_count, chunk_size,
        [&](uint64_t i, int tid) {
            // do work
        });
}
```

We don't need to use `chunk_size`.
If omitted, we use a template that queues single iteration values, rather than ranges.

We can also pass a function that does not take its thread id as an argument.

## thanks

This utility depends on Maxim Egorushkin's atomic_queue library, which is included in the single header file `paryfor.hpp`.

## author

Erik Garrison

## license

MIT