I need to implement a thread pool executor for generic tasks. My idea is to use OpenMP for thread management. The problem is that I'm not familar yet with OpenMP..
I tried to find an existing implementation of the generic ThreadPool with OpenMP, but I haven't find one so far. What I would like to have in the end is something very similar to java.util.concurrent.ThreadPoolExecutor
:
template <typename Return, typename Task>
class ThreadPoolExecutor
{
public:
ThreadPoolExecutor(int threadCount);
// asyncronous invoke
boost::unique_future<Return> submit(const TaskPtr & task);
// blocking call
std::vector<Return> invokeAll(const std::vector<TaskPtr> & tasks)
{
// submit all tasks + wait for completion
#pragma omp parallel default(shared)
{
// call tasks here
}
}
};
I have several questions about this approach:
Is there existing implementation of thread pool with OpenMP for C++? [I know I can implement threadpool with boost::asio::io_service, but I would prefer not depend on it]
With my design - how can we guarantee that the OpenMP threads will be 'owned' by the concrete ThreadPoolExecutor instance? They should not be static for all instances.
Thank you for any advice & constructive critics of this approach & proposals of other implementations.
Just to sum up: as described in the comments OpenMP is not an option for implementing generic thread pool or executor, because:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With