Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <thread>
- #include <vector>
- #include <future>
- using namespace std;
- typedef vector<double>::const_iterator vci;
- double s(vci begin, vci end) {
- double sum_async=0;
- for(; begin!=end; ++begin) {
- sum_async+= *begin;
- }
- return sum_async;
- }
- int main()
- {
- double sum=0;
- double sum_async=0;
- int n=10;
- vector<double>v ={1,2,3,4,5,6,7,8,9,10};
- for(int i=0; i<v.size()/2; ++i) {
- sum+=v[i];
- }
- for(int i=0; i<v.size()/2; ++i) {
- auto x = async(s, v.begin()+v.size()/2, v.end());
- sum_async = x.get();
- }
- sum+=sum_async;
- cout<<sum<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement