PCT: Parfor vs For with one core
이전 댓글 표시
We are writing an application in which some parts are meant to be in parallel. Nevertheless, we want to tune the app so that it uses the optimal number of cores (even if the number of cores = 1)
My question is: what happens with the speed of execution for these two blocs
parfor i = 1:X
executeY
end
for i = 1:X
executeY
end
when only one core is being used, keeping everything else constant? Is the parfor slower because it checks if a matlabpool is open? Is the speed of execution the same for both?
채택된 답변
추가 답변 (2개)
Jan
2013년 1월 28일
0 개 추천
I do not have experiences with the parallel toolbox. Can you open a pool with 2 threads on a single core node? A process with alternating file access and computations, e.g. reading a movie file, could profit from multiple threads on a single core. Another example is a compression software, e.g. 7zip runs faster with two threads even on a single core processor.
Jason Ross
2013년 1월 28일
0 개 추천
This special-casing may not be strictly necessary, as "parfor" reverts to serial behavior if there is no matlabpool available, as follows:
"If the parfor-loop cannot run on workers in a MATLAB pool, MATLAB executes the loop on the client in a serial manner. In this situation, the parfor semantics are preserved in that the loop iterations can execute in any order."
In regards to the thread question, each MATLAB worker process is it's own process -- you can see the number of MATLAB instances increase as a matlabpool is started. And to be extra pedantic, core count is independent of the number of worker MATLABs started -- the placement of the worker is left to the operating system entirely, and the "one core per worker" is merely a "best guess default". There are situations where you would want different ratios, depending on a number of factors.
댓글 수: 2
gire
2013년 1월 28일
Jason Ross
2013년 1월 28일
Using Sean's code I was able to see the difference. I couldn't come up with a way to do it better, unfortunately.
카테고리
도움말 센터 및 File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!