TBB parallel_while demo

Source: Internet
Author: User

// This is meCodeA framework implemented using the parallel_while loop.
Class body {
TBB: parallel_while <body> & my_while;
Public:
Body (TBB: parallel_while <body> & W): my_while (w ){}

//------------------------------------------------------------------------
// Following signatures required by parallel_while
//------------------------------------------------------------------------
Typedef long argument_type;
Void operator () (long c) const {
Function (c); // The function in this region is the part that needs to be implemented by yourself,
}
};

Class stream {
Id_queue_type & my_queue;
Public:
Stream (id_queue_type & _ Queue): my_queue (_ Queue ){}
Bool pop_if_present (Long & item ){
Return my_queue.pop_if_present (item );
}
};

Void parallelpreordertraversal (id_queue_type & _ Queue ){
TBB: parallel_while <body> W;
Stream S (_ Queue );
W. Run (_ queue, body (w ));
}

Void startalgrorithm ()
{
TBB: task_scheduler_init Init; // multi-thread Initialization
Parallelpreordertraversal (unbidpersonqueue );
}

Body stream parallelpreordertraversal. The three parts are the key to the while implementation. Body and stream are just a virtual function in the framework of parallel_while, it can be understood that parallel_while only provides us with a framework for converting loops into multi-threaded execution. However, we have to implement the specific implementation and reload it; this place is his subtlety, haha :)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.