Calculating the sum of a large vector in parallel

前端 未结 2 994
隐瞒了意图╮
隐瞒了意图╮ 2021-01-06 05:03

Problem background

I have a program that currently takes way too long to sum up large std::vectors of ~100 million elements using std::accumulat

2条回答
  •  死守一世寂寞
    2021-01-06 05:23

    You can use Boost Asio as a thread pool. But there's not a lot of sense in it unless you have... asynchronous IO operations to coordinate.

    In this answer to "c++ work queues with blocking" I show two thread_pool implementations:

    • Solution #1: one based on boost::asio::io_service
    • Solution #2: the other based on boost::thread primitives

    Both accept any void() signature compatible task. This means, you could wrap your function-that-returns-the-important-results in a packaged_task<...> and get the future from it.

提交回复
热议问题