Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Enqueued tasks never gets picked up.

sanjivkumargupta
Beginner
1,199 Views

I have the following pattern

parallel_for (blocked_range(0 , max),  [ ] (r) {

for (size_t i = r.begin(); i != r.end(); ++i) {

         ctx  = make_unique<tbb::task_group_context>();

         waitTask = (new (tbb::task::allocate_root(*ctx))

                         tbb::empty_task); 

        waitTask->set_ref_count(2);

        auto& workerTask = *new (waitTask->allocate_child()) WorkerTask(name);

        tbb::task::enqueue(workerTask);    

        waitTask->wait_for_all();  // wait for children to complete.

    }

}

I get a hang with all threads in receive_or_steal_task, but the "execute" of WorkerTask never being called.

Things work fine if I wait on all waitTasks   outside of the parallel_for in a different parallel_for.

OR

A sequential for loop in place of parallel_for in the above example also works fine .

 

0 Kudos
2 Replies
sanjivkumargupta
Beginner
1,199 Views

tbb::task::spawn () instead of tbb::task::enqueue() also works well. But  we need enqueue as we don't want to force require a wait() to guarantee the execution of the workerTask.

0 Kudos
Mariya_P_Intel
Moderator
1,011 Views

Dear @sanjivkumargupta,

Apologies for a lack of response. Please let us know if the question is still actual or not.

Thanks, Mariya


0 Kudos
Reply