Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
2401 Discussions

Problem in running the example in the tutorial

sudhar_m2000
Beginner
76 Views
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
Alexey_K_Intel3
Employee
76 Views
Please read the Tutorial carefully (in particular, the section 3.1) and check my recent reply in another thread.

sudhar_m2000
Beginner
76 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
Reply