- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I'm new to TBB and I would like to better uderstand the way parallel_for works.
I am using the example of the tutorial :
I'm new to TBB and I would like to better uderstand the way parallel_for works.
I am using the example of the tutorial :
====================================================================================
#include "tbb/blocked_range.h"
class ApplyFoo {
float *const my_a;
public:
void operator()( const blocked_range& r ) const {
float *a = my_a;
for( size_t i=r.begin(); i!=r.end(); ++i )
Foo(a);
}
ApplyFoo( float a[] ) :
my_a(a)
{}
};
...............................
#include "tbb/parallel_for.h"
void ParallelApplyFoo( float a[], size_t n ) {
parallel_for(blocked_range(0,n,IdealGrainSize), ApplyFoo(a) );
}
===================================================================================
Here are my questions :
- What really does parallel_for(blocked_range(0,n,IdealGrainSize), ApplyFoo(a) ); ?
Does it create multiple AppliFoo objects, which are handled by a thread, and then operator() is applied
on each object ?
Or does it create instead one single AppliFoo object ?
- I don't see where and how the operator() function operates : where are the parentheses ?
Well, I am a bit confused on parallel_for. I hope that your explanation will help me !
Thanks.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, Adrael
I'm afraid I cannot answer your first question in a more understandable way than TBB Tutorial does.
Regarding your second question, this forum is for discussing and helping with questions related to TBB and parallelism in general. To get assistance with C++ basics, please refer to one of the following forums:
I'm afraid I cannot answer your first question in a more understandable way than TBB Tutorial does.
Regarding your second question, this forum is for discussing and helping with questions related to TBB and parallelism in general. To get assistance with C++ basics, please refer to one of the following forums:
http://groups.google.com/group/alt.comp.lang.learn.c-c++/topics
http://www.cplusplus.com/forum/beginner/
http://www.programmersheaven.com/mb/beginnercpp/board.aspx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Answering the couple of more specific questions (though parallel_for can be used without knowing this level of details):
Adrael:Does it (parallel_for - A.K.) create multiple AppliFoo objects, which are handled by a thread, and then operator() is applied on each object ?
Or does it create instead one single AppliFoo object ?
In the current implementation of parallel_for, multiple objects are created (much more than the number of threads). But this is an implementation detail that might change; we could as well use a single object while calling its "function call operator" (a.k.a. operator()) from multiple threads maintained by TBB.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks. I am investigating...
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page