- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think there's a error in the tutorial document (http://cache-www.intel.com/cd/00/00/30/11/301132_301132.pdf). On page 57, it gives an example using recycling as a demonstration of how to sometimes avoid allocating other tasks, but then it goes and allocates all of the tasks anyway. I'm pretty sure that line 12 of that example, "FibTask& a = *new( c.allocate_child() ) FibTask(n-2,&c.x);", should be removed.
To test this, I typed up the example; the below code (with the given line commented out) works for me:
41. clover ~/tbb-tutorial-test: g++ -ltbb fib.cc
42. clover ~/tbb-tutorial-test: ./a.out
55
Does this seem right to anyone else? CPS stuff still makes my brain hurt so I'm not quite confident enough to actually file a bug report at this moment. ;-)
Edit: In case this wasn't clear, I think it also works if you leave the line in. Without knowing the internals of the task class and such it's possible that it's a memory leak, but nothing worse. However, it does sort of miss the point of the section, which is that by using the recycling framework you can avoid allocations.
Evan
To test this, I typed up the example; the below code (with the given line commented out) works for me:
41. clover ~/tbb-tutorial-test: g++ -ltbb fib.cc
42. clover ~/tbb-tutorial-test: ./a.out
55
Does this seem right to anyone else? CPS stuff still makes my brain hurt so I'm not quite confident enough to actually file a bug report at this moment. ;-)
Edit: In case this wasn't clear, I think it also works if you leave the line in. Without knowing the internals of the task class and such it's possible that it's a memory leak, but nothing worse. However, it does sort of miss the point of the section, which is that by using the recycling framework you can avoid allocations.
Evan
#include
#include "tbb/task.h"
#include "tbb/task_scheduler_init.h"
using namespace tbb;
using namespace std;
long SerialFib(long n) {
if(n<2) return n;
else return SerialFib(n-1)+SerialFib(n-2);
}
struct FibContinuation : public task {
long* const sum;
long x,y;
FibContinuation(long* sum_) : sum(sum_) {}
task* execute() {
*sum= x+y;
return NULL;
}
};
class FibTask: public task {
public:
long n;
long* sum;
public:
FibTask(long n_, long* sum_) : n(n_), sum(sum_) {}
task* execute() {
if(n<2) {
*sum = SerialFib(n);
return NULL;
}
else {
FibContinuation &c = *new(allocate_continuation()) FibContinuation(sum);
// FibTask& a = *new(c.allocate_child()) FibTask(n-2, &c.x);
FibTask& b = *new(c.allocate_child()) FibTask(n-1, &c.y);
recycle_as_child_of(c);
n-=2;
sum=&c.x;
c.set_ref_count(2);
c.spawn(b);
return this;
}
}
};
long ParallelFib(long n) {
long sum;
FibTask&a = *new(task::allocate_root()) FibTask(n,∑);
task::spawn_root_and_wait(a);
return sum;
}
int main()
{
task_scheduler_init i;
cout << ParallelFib(10) << endl;
}
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You're right; this is a documentation bug.
The whole point of recycling is to avoid the need to allocate both tasks. Probaby during a reformatting of the Tutorial a strikethrough was lost. In any case, we'll be sure to fix this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the bug report. I've fixed it in our mainline developement tree. Regrettably, the fix will miss the 2.0 update release.
As Mike indicated, we lostmany of thestrikethough marks text during a major style reformatting. Every time I think we've recovered from that reformatting, someone fines another.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks... good to know I am actually mostly understanding that section. ;-)

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