First time using Intel thread Building Blocks Summary _ Parallel Computing

Source: Internet
Author: User
The main use of the basic parallel_for usage, according to the version of the brother to modify their own character recognition function, brother created a new class as a container, which carries a pointer to the character recognition class, the specific reason according to senior said because in the parallelization of the time will be a new instance of multiple classes, So send a pointer and create a new instance of the class outside the parallel class with the following code: #include <QtCore/QCoreApplication> #include "patternMatch.h" #include <tbb\ concurrent_vector.h> #include <tbb\tbb.h> #include <tbb\scalable_allocator.h> #include <array>/ /using namespace CV; using namespace TBB;
Class Paralellrecognize {Public:patternmatch *recognizecore;    Cv::mat *allframe;   Paralellrecognize (patternmatch* newrecognize, cv::mat* newlist) {recognizecore = newrecognize;  Allframe = NewList; }
void operator () (const blocked_range<long>& R) Const {cv::mat* a = Allframe;
for (Long i = R.begin (); I!= r.end (); ++i) {//cout << "frame index" << "" << I << Endl;   Recognizecore->recognizeoneimage (i); }
}
~paralellrecognize () {}};
The shadow shows the key, the code in the main function: int main (int argc, char *argv[]) {qcoreapplication A (argc, argv);
Cv::mat *mat = NULL; Patternmatch *newrecognize = new Patternmatch (4, 1986); Instantiated once, 4 and 1984 means the current video has 4 rows, 1986 frames, the test is convenient and uses the specific number of int totalfilenum = Newrecognize->getfilenum (); Non-parallel version tick_count t0 = Tick_count::now ();  Tick_count is the type of running time of the TBB function, it is very easy to use oh Newrecognize->startmatch (); Tick_count T1 = Tick_count::now ();
Parallel version Tick_count t2 = Tick_count::now ();  parallel_for (blocked_range<long> (0, Totalfilenum), Paralellrecognize (Newrecognize, Mat));   tick_count t3 = Tick_count::now ();  printf ("Serial work took%g seconds\n", (t1-t0). seconds ());  printf ("Parallel work took%g seconds\n", (t3-t2). seconds ());  Double serialtime = (t1-t0). seconds ();  Double paralleltime = (t3-t2). seconds (); printf ("ratio for two timt:%f\n", serialtime/paralleltime);  Print results to TXT file newrecognize->printtext ();  printf ("Write file completed.\n"); return A.exec (); }
Next is release the program, need to Tbb.dll, I am using Win32 mode of release, so should use the 32-bit version, my Computer directory for C:\Program Files (x86) \intel\composer XE 2015\REDIST\IA32\TBB\VC12, if 64 digits, should be in C:\Program Files (x86) \intel\composer XE 2015\redist\intel64\ Select the appropriate tbb.dll file in the TBB. Otherwise, you will not be able to run the EXE program, the application does not start 0xc000007b issues such as normal.

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.