parfor much slower than for loop when using struct variables
조회 수: 1 (최근 30일)
이전 댓글 표시
I developed some finite element modeling code which is very CPU intensive with solving many equations and I am trying to improve it by using `parfor`. Here is the pseudo code of what I am doing
Two struct variables
Model = (structure variable with about 20 floating point variables and a few matrices of 10x10)
Elements{} = (cell array of structs where there are some nested structs inside, but all holding floating point data variables. There is one reference to a function, ie: Elements.getState = @getStateN
Code
parfor elmID = 1:numElements
[Elements{elmID} Results(elmID)] = Elements{elmID}.getState(Elements{elmID}, Model);
end
When I run this code, it is 40 times SLOWER than when I use a for loop.
I assumed here that the Elements{} cell array is being sliced into numElements so the whole Elements cell array wasn't being copied back and forth. Also, the Model structure seemed negligible because I took it out in one case to see.
Is there something here that I am doing wrong or is it just that there is large overhead with copying structs back and forth?
댓글 수: 1
Edric Ellis
2013년 3월 26일
What size matlabpool are you using? I assume it's a 'local' matlabpool. Also, on the right-hand-side inside your PARFOR loop, don't you mean
[Elements{elmID} Results(elmID)] = getState(Elements{elmID}, Model);
The code as written passes the element into the "getState" method twice.
Finally, do you know roughly how big a MAT file on disk you get when you save Elements, Results, and Model together? That's the amount of data that needs to be transmitted to process the loop.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!