parfor much slower than for loop when using struct variables

1 vue (au cours des 30 derniers jours)
Thomas Marullo
Thomas Marullo le 26 Mar 2013
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 commentaire
Edric Ellis
Edric Ellis le 26 Mar 2013
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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by