Skip to content
/ paryfor Public

parallel_for based on atomic queues and C 11 threads

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.atomic_queue
Notifications You must be signed in to change notification settings

ekg/paryfor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

#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

About

parallel_for based on atomic queues and C 11 threads

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.atomic_queue

Stars

Watchers

Forks

Packages

No packages published