- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
H i,
I'm unable to run the below code in Linux system. while running it's giving Segmentation fault in tbb::internal::allocate_root_proxy::allocate ()
the code is
ong SerialFib( long n );
class FibTask: public task {
public:
long n;
long* sum;
FibTask( long n_, long* sum_ )
//n(n_), sum(sum_)
{}
task* execute() { // Overrides virtual function
//task::execute
if( n *sum = SerialFib(n);
} else {
long x, y;
FibTask& a = *new( allocate_child() ) FibTask(n-1,&x);
FibTask& b = *new( allocate_child() ) FibTask(n-2,&y);
// Set ref_count to "two children plus one for the wait".
set_ref_count(3);
// Start b running.
spawn( b );
// Start a running and wait for all children (a and b).
spawn_and_wait_for_all( a );
// Do the sum
*sum = x+y;
}
return NULL;
}
};
long SerialFib( long n ) {
if( n<2 )
return n;
else
return SerialFib(n-1)+SerialFib(n-2);
}
int main()
{
long sum;
int n = 100;
FibTask& a = *new(task::allocate_root()) FibTask(n,∑);
task::spawn_root_and_wait(a);
printf("The result = %ld\n",sum);
return sum;
}
I'm unable to run the below code in Linux system. while running it's giving Segmentation fault in tbb::internal::allocate_root_proxy::allocate ()
the code is
ong SerialFib( long n );
class FibTask: public task {
public:
long n;
long* sum;
FibTask( long n_, long* sum_ )
//n(n_), sum(sum_)
{}
task* execute() { // Overrides virtual function
//task::execute
if( n
} else {
long x, y;
FibTask& a = *new( allocate_child() ) FibTask(n-1,&x);
FibTask& b = *new( allocate_child() ) FibTask(n-2,&y);
// Set ref_count to "two children plus one for the wait".
set_ref_count(3);
// Start b running.
spawn( b );
// Start a running and wait for all children (a and b).
spawn_and_wait_for_all( a );
// Do the sum
*sum = x+y;
}
return NULL;
}
};
long SerialFib( long n ) {
if( n<2 )
return n;
else
return SerialFib(n-1)+SerialFib(n-2);
}
int main()
{
long sum;
int n = 100;
FibTask& a = *new(task::allocate_root()) FibTask(n,∑);
task::spawn_root_and_wait(a);
printf("The result = %ld\n",sum);
return sum;
}
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please read the Tutorial carefully (in particular, the section 3.1) and check my recent reply in another thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Alexey Kukanov (Intel)
Please read the Tutorial carefully (in particular, the section 3.1) and check my recent reply in another thread.
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