Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
19 Views

Problem in running the example in the tutorial

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;
}


0 Kudos
2 Replies
Highlighted
19 Views

Please read the Tutorial carefully (in particular, the section 3.1) and check my recent reply in another thread.

0 Kudos
Highlighted
Beginner
19 Views

Please read the Tutorial carefully (in particular, the section 3.1) and check my recent reply in another thread.

Thanks Alexey Kukanov for your timely help
0 Kudos