template<typename FuncVec> int handle(const vector<int>& v, FuncVec f, int MAX_THREAD) { vector<future<int>> threads; std::vector<int> answers; int mid = v.size() / MAX_THREAD; int start = 0, end = start + mid; for (int i = 0; i < MAX_THREAD; ++i) { start = mid * i; end = start + mid; if (end != (int) v.size() && (int) v.size() - end < mid) end = v.size(); threads.emplace_back (std::async(std::launch::async, f, v, start, end)); } for (auto& thread : threads) { answers.push_back(thread.get()); } return f(answers, 0, answers.size()); } Actually, you need to speed up this function. Now on 4 streams issue such indicators:
We create 10000211 elements. (Single stream) Amount = 45012639 Time = 171.846ms. (Multithread) Amount = 45012639 Time = 193.831ms.
What are some ideas?
We found out that for some reason, only one core works. Full code here