parallel computing speed question when the body of the parfor loop takes about 2 seconds

조회 수: 1 (최근 30일)
I have a question about parallel:
parfor ii=1:N dosomething%% end
in the parfor loop, the time of dosomething is 2 seconds in each loop, and N is about 100. In that condition, is it efficient to use parfor here???
I feel confused about that as I test the time and find the more core I use, the more time I spend!!!!!! Could someone help to answer this question?!!!!

채택된 답변

Ken Atwell
Ken Atwell 2015년 5월 13일
It really depends on what "dosomething" is doing. If it is pure computation, it should be a big win. If there is file or network I/O going on, your mileage will vary depending on the application and hardware.
Also keep an eye on memory usage on your computer -- if you're using all of your physical RAM, your computer may be spending much of its time swapping, more than offsetting and gain you'd get from multiprocessor operation.
  댓글 수: 2
Guanfeng Gao
Guanfeng Gao 2015년 5월 13일
Thanks for your help. I could not quite understand what the network I/O refers to. Actually, in the "do somthing", there only exist some simply computation and another loop to call a c function by mex file. Is it what you are saying?
Walter Roberson
Walter Roberson 2015년 5월 13일
Pure computation on a local system is fine. If you were using the Distributed Computing Engine to send to several hosts then there would be network traffic. If you were load()'ing files then there would be file I/O.

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

추가 답변 (1개)

Guanfeng Gao
Guanfeng Gao 2015년 5월 13일
Thanks!!! I do not have several hosts or file I/O in my parallel loop!!! However, I am still not satisfied with the speed. E.G. there are 100 iterations (parfor ii=1:100), and for each iteration it takes 2 seconds; when I use 32 cores it takes 129 seconds, which means that the parallel only speedup to "2*100/129~2" than the regular one when I use 32 cores!!!! That really confused me!!!!!!
  댓글 수: 1
Walter Roberson
Walter Roberson 2015년 5월 13일
Are the matrices large? If so then you might be encountering a lot of overhead in transmitting the values back. Try experimenting with drange() instead of parfor()

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


Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by