Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.

Segmentation fault with parallel for

adrael
Beginner
200 Views
Hi,

I am using template parallel_for and I have a seg fault at execution. (It's not the first time that I try using parallel_for). here is my serial code :


template
void MyNode

::get_obj( std::vector

&objects,

 const Q in_rect ) const 
{
 
 for( unsigned int i = 0; i < this->elem_list.size( ); i++ )
 {
 
 Node

*sample = this->elem_list.at( i );

 
 if( sample->get_foo().bar( in_rect ) == true )
 {
 sample_fcnB( objects, in_rect );
 }
 }
}


And here is my code :


template 
  class get_obj_for {
   const vect< Node

* > &my_elem_list;

   const B &my_in_rect ; 
   vector

&my_objects ;


public:
    void operator()( const blocked_range& r ) const {
  
     for( unsigned int i = r.begin(); i < r.end(); i++ )
     {
 
      Node

*sample = my_elem_list.at( i );

 
       if( sample->get_foo().bar( my_in_rect ) == true )
      {
      sample_fcnB( my_objects, my_in_rect );
      }
      }
    }
 
  // Constructor
    get_obj_for(
 &
nbsp;     const vect< Node

* > &liste_elem,

      const B &rect,
      vector

&objects) :

      my_m_elel_list(liste_elem), 
      my_in_rect(rect),
      my_objects(objects) 
    {}
  };




It compiles. But It crashes at runtime with segmentation fault. It does not enter the operator() method ( a printf just before the loop doesn't appear).
And gdb show that segfault occurs in tbb::parallel_for....get_obj_for()

I don't know what to do now.

0 Kudos
2 Replies
ARCH_R_Intel
Employee
200 Views

Does your code crash even with a single thread?

What I usually do is run with a single thread (e.g. "tbb::use task_scheduler_init init(1);" and see if the code crashses. If so, then I debug the code like I would debug serial. code (e.g. single step it, or look at the traceback).

adrael
Beginner
200 Views
Problem solved. I had forgotten to initialize tbb...
Reply