What is the difference between parallel_for_each and parallel_for parameters in MSVC Concurrency Runtime?

parallel_for_each has the form:

 Concurrency::parallel_for_each(start_iterator, end_iterator, function_object); 

but parallel_for also has the same form:

 Concurrency::parallel_for(start_value, end_value, function_object); 

so what is the difference between the Concurrency::parallel_for and Concurrency::parallel_for_each algorithms used when programming for multiple cores?

+4
source share
1 answer

I don't know what library you are talking about, but it looks like it accepts iterators:

 Concurrency::parallel_for_each(start_iterator, end_iterator, function_object); 

And it probably has the same effect as this one (although not necessarily in the same order):

 for(sometype i = start_iterator; i != end_iterator; ++i) { function_object(*i); } 

For instance:

 void do_stuff(int x) { /* ... */ } vector<int> things; // presumably calls do_stuff() for each thing in things Concurrency::parallel_for_each(things.begin(), things.end(), do_stuff); 

The other takes values, so most likely it has a similar effect (but again, without a guaranteed order):

 for(sometype i = start_value; i != end_value; ++i) { function_object(i); } 

Try the following:

 void print_value(int value) { cout << value << endl; } int main() { // My guess is that this will print 0 ... 9 (not necessarily in order) Concurrency::parallel_for(0, 10, print_value); return 0; } 

EDIT. You can find confirmation of these actions in Links to parallel algorithms .

+7
source

Source: https://habr.com/ru/post/1386232/


All Articles