#include #include #include #include #include using namespace std; void partSumChunks(vector const& a, vector const& b, vector& c, size_t nrThreads, size_t t) { size_t const n = a.size(); size_t const begin = (t*n)/nrThreads; size_t const end = ((t+1)*n)/nrThreads; for(size_t i = begin ; i const& a, vector const& b, vector& c, size_t nrThreads, size_t t) { size_t const n = a.size(); for(size_t i = t ; i const& a, vector const& b, vector& c, unsigned nrThreads) { size_t const n = a.size(); vector > futures; futures.reserve(nrThreads); for(size_t i=0 ; ivoid{ partSumChunks(a, b, c, nrThreads, i); })); } for(auto& f : futures) { f.get(); } } void generate(vector& v, size_t n) { v.clear(); v.reserve(n); for(size_t i=0 ; i const& v) { printf("Vector ="); for(int val : v) printf(" %d", val); printf("\n"); } bool checkSum(vector const& a, vector const& b, vector const& s) { if(a.size() != s.size() || b.size() != s.size()) return false; for(size_t i = 0 ; i \n"); return 1; } vector a, b, c; generate(a, n); generate(b, n); c.resize(n); chrono::high_resolution_clock::time_point const beginTime = chrono::high_resolution_clock::now(); vectorSum(a, b, c, nrThreads); chrono::high_resolution_clock::time_point const endTime = chrono::high_resolution_clock::now(); printf("Result %s, time=%ldms\n", (checkSum(a, b, c) ? "ok" : "FAIL"), (chrono::duration_cast(endTime-beginTime)).count()); }