parallel_for_each Example
#include<iostream>
#include <conio.h>
#include <ppl.h>
#include <windows.h>
#include <vector>
#include <algorithm>
using namespace std;
using namespace Concurrency;
__int64 GetTime(){
return GetTickCount();
}
void makeDouble(vector<int> vec){
for_each(vec.begin(),vec.end(),[&](int i){
cout<<2*i<<" ";
});
cout<<endl<<endl<<endl<<endl;
}
void parallel_makeDouble(vector<int> vec){
parallel_for_each(vec.begin(),vec.end(),[=](int i){
cout<<2*i<<" ";
});
cout<<endl<<endl<<endl<<endl;
}
int main(int argc, char** argv){
vector<int> v(200);
int n=0;
generate(v.begin(),v.end(),[&](){ return n++;});
__int64 begin=GetTime();
makeDouble(v);
__int64 end=GetTime();
cout<<"Seq:"<<end-begin<<endl;
begin=GetTime();
parallel_makeDouble(v);
end=GetTime();
cout<<"Parallel:"<<end-begin<<endl;
getch();
return 0;
}
No comments yet.
Leave a Reply
-
Recent
-
Links
-
Archives
- April 2011 (3)
- March 2011 (21)
- May 2010 (1)
- January 2010 (2)
- December 2009 (2)
- August 2009 (1)
- July 2009 (2)
- April 2009 (4)
- March 2009 (6)
- February 2009 (5)
- January 2009 (4)
- December 2008 (3)
-
Categories
-
RSS
Entries RSS
Comments RSS