Advertisement
nex036ara

vektor_sum_niti

Mar 28th, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <thread>
  3. #include <vector>
  4. #include <future>
  5. using namespace std;
  6.  
  7. typedef vector<double>::const_iterator vci;
  8.  
  9. double s(vci begin, vci end) {
  10.         double sum_async=0;
  11.         for(; begin!=end; ++begin) {
  12.         sum_async+= *begin;
  13.         }
  14.         return sum_async;
  15. }
  16.  
  17.  
  18. int main()
  19. {
  20.     double sum=0;
  21.     double sum_async=0;
  22.  
  23.     int n=10;
  24.     vector<double>v ={1,2,3,4,5,6,7,8,9,10};
  25.  
  26.     for(int i=0; i<v.size()/2; ++i) {
  27.     sum+=v[i];
  28.     }
  29.  
  30.     for(int i=0; i<v.size()/2; ++i) {
  31.     auto x = async(s, v.begin()+v.size()/2, v.end());
  32.     sum_async = x.get();
  33.     }
  34.  
  35.     sum+=sum_async;
  36.     cout<<sum<<endl;
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement