How do I translate C++ threading into Matlab Parallel Toolbox?

조회 수: 3 (최근 30일)
Lex
Lex 2016년 3월 29일
댓글: Gautam Mohan 2016년 4월 1일
If I have this code in C++, what is the Matlab equivalent in the Parallel toolbox?
HANDLE snThread;
unsigned threadID;
PassIn par;
par.what = 1;
snThread = (HANDLE)_beginthreadex( NULL, 0, displaySN, &par, 0, &threadID);
i = SetThreadPriority(snThread, THREAD_PRIORITY_TIME_CRITICAL);
if (i!=1) {
cout <<"Can not set thread priority. Quit!"<<endl;
CloseHandle(snThread);
} else {
WaitForSingleObject(snThread, INFINITE);
CloseHandle(snThread);
}
cout<<endl;
where displaySN is a function that is described as "The working horse, running a prioritized thread." I can include the displaySN code if people want, however, it will include code that specifically a product of a company and hence may not be intelligible.
So the purpose of the code is to take a bunch of images we previously created, hold them in queue, and run them very quickly one right after the other, essentially showing a movie. Threading helps us achieve the quick turnover in images.
I am a bit confused what the difference is between threading and the parallel computing toolbox or how either relate to each other
  댓글 수: 1
Gautam Mohan
Gautam Mohan 2016년 4월 1일
Hi Lex,
Threading is not really related to the Parallel Computing Toolbox. The PCT is meant to serve as an abstraction within MATLAB to write parallelized code. It provides an interface to multicore systems in the form of a Parallel Pool, and allows for certain keywords such as 'parfor' that allows easy structuring of parallelized code.
It does not offer the kind of low-level parallelism that threading deals with. There isn't an analogous construct in MATLAB for a thread. All parallelization is handled internally by MATLAB, and all the user needs to worry about is the code they are writing. You can read more about the PCT here. It is geared more towards data parallelism.
I would recommend trying to implement your application in MATLAB without worrying about parallelization, and trying to optimize it after writing it if it does not suit your performance requirements.
You can also call C++ functions through MATLAB via the MEX interface . This might be a potential solution for you if a MATLAB implementation is unable to match the performance goals of your current application.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by