Ebeworld’s Weblog

Trying to create

parallel_for example

#include<iostream>
#include <conio.h>
#include <ppl.h>
using namespace std;
using namespace Concurrency;

void makeDouble(int n){
	for(int i=0;i<n;i++){
		cout<<2*i<<" ";
	}
	cout<<endl<<endl<<endl<<endl;
}

void parallel_makeDouble(int n){
	parallel_for(0,n,[](int i){
		cout<<2*i<<" ";
	});

}

int main(int argc, char** argv){
	makeDouble(100);
	parallel_makeDouble(100);
	getch();
	return 0;
}

Output:

0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 5
6 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106
108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146
148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186
188 190 192 194 196 198

50 0 150 100 52 54 56 58 60 176 178 180 182 184 186 188 190 192 194 196 198 62 1
02 104 152 154 156 164 166 168 1702 64 66 68 70 72 172 174 158 106 108 110 112
114 116 118 120 162 4 122 124 126 128 130 132 134 136 138 140 28 74 76 78 80 82
84 86 88 90 92 94 96 98 30 32 34 36 38 40 42 44 46 48 142 6 144 160 146 8 10 12
18 20 148 22 14 24 16 26

March 23, 2011 - Posted by | Algorithms, CPP, Uncategorized

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.