Calculate and Assembly Stiffness Matrix in Parfor Loop

3 次查看(过去 30 天)
Hello,
I am working on extensive lattice networks, so I need to deal with very big stiffness matrices and enormous numbers of degrees of freedom. For this reason I am trying to parallelize the calculation of the stiffness matrix and the sectional response in order to speed the process up. Anyways, I couldn't make it work. My code looks like this
for i=1:number_steps
iterations = 0; % Initialize Iterations counter
K = zeros(dof,dof); % Initialize Stiffness Matrix
for ii=1:number_elements
id_i = Connectivity_Matrix(ii,1); % Retreive 1st node id
id_j = Connectivity_Matrix(ii,2); % Retreive 2nd node id
displacement = retreive_displacement(id_i,id_j,disp);
K_e = k_matrix(id_i,id_j,parameters,displacement);
K(gdl_n*id_1-(gdl_n-1):gdl_n*id_1,gdl_n*id_1-(gdl_n-1):gdl_n*id_1) = K(gdl_n*id_1-(gdl_n-1):gdl_n*id_1,gdl_n*id_1-(gdl_n-1):gdl_n*id_1) + K_e(1:gdl_n,1:gdl_n); % Direct Stiffness Assembly
end
end
The code runs smoothly up to the calculation of the element stiffness matrix (K_e). The error comes up when trying to assembly the global stiffness matrix by adding the single elements contribution in the proper position. The problem arises because the K matrix is indexed through a variable that changes inside the loop, which is of course inevitable because the id of the nodes of the bar needs to be updated for every element. I thought I could just store all the element stiffness matrices in a cell and then add them up outside the parfoor loop, but this is clearly not very efficient, since I will need an extra for loop. Any ideas?
Thanks.
  1 个评论
Alessandro
Alessandro 2015-2-12
Idea #2: what if I calculate all the values used to indicize the K matrix outside the parfor loop?

请先登录,再进行评论。

回答(1 个)

Alessandro
Alessandro 2015-2-16
Up

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by