Problem with cell array indexing when using parfor
Mostra commenti meno recenti
Dear all,
I'm try to do certain calculation that automatically generates a certain (large) matrix for each iteration and calculates the Eigenvalue for it. To speed up the lengthy calculation, I am using parfor. Unfortunately, the code gives me "The variable IM in a parfor cannot be classified" error. It seems like looking at M-lint tells me that IM, B1, B2, and B3 are bad variables. These are all cell arrays that were created so that different cell can be assigned independently by each iteration, preventing interaction between other iterations.
I do not understand the problem here. Could someone help me? Thank you.
The code is shown below. IM, IIM, B1, B2, and B3 are already defined elsewhere as empty cell arrays. variables l and n depends on the input of the user but is defined prior to the code.
parfor cycle = 1:n
IM{cycle, 1} = IIM
B1{cycle, 1} = setdiff(1:(2*l+1)^3, ((2*l+1)^3+1)/2).'
if Impurity == 1
o(cycle) = randi([0, 1], 1);
if o(cycle) == 0
B2{cycle, 1} = 0;
else
p(cycle) = randi(length(B1{cycle, 1}),1);
IM{cycle, 1}(:, B1{cycle, 1}(p(cycle), 1)) = 0;
IM{cycle, 1}(B1{cycle, 1}(p(cycle), 1), :) = IM{B1{p(cycle),1}, :}*1;
IM{cycle, 1}(B1{cycle, 1}(p(cycle), 1), B1{cycle, 1}(p(cycle), 1)) = -str2double(answer3(2,1));
B2{cycle, 1} = B1{cycle, 1}(p(cycle), 1);
end
end
B3{cycle, 1} = zeros(m,1);
q(cycle) = 1;
while length(B1{cycle, 1}) > o(cycle) + str2double(answer2(1,1)) - 1
r(cycle) = randi(length(B1{cycle, 1}),1);
if B1{r(cycle), 1} ~= B2{cycle, 1}
B3{cycle, 1}(q(cycle),1) = B1{cycle, 1}(r(cycle), 1);
B1{r(cycle), 1} = [];
IM{:, B3{q(cycle), 1}} = 0;
IM{B3{q(cycle), 1}, :} = 0;
q(cycle) = q(cycle) + 1;
end
end
B1{cycle, 1}(B1{cycle, 1}==B2{cycle, 1}) = [];
for q = 1:length(B1{cycle, 1})
IM{B1{cycle, 1}(q(cycle), 1), B1{cycle, 1}(q(cycle), 1)} = 0;
IM{B1{cycle, 1}(q(cycle), 1), B1{cycle, 1}(q(cycle), 1)} = -(str2double(answer3(1,1)) + str2double(answer3(2,1)) + sum(IM{cycle, 1}(:, B1{q(cycle),1}))) + str2double(answer3(6,1))*sum(IM{cycle, 1}(:, B1{q(cycle),1}));
end
IM{cycle, 1}(((2*l+1)^3+1)/2, ((2*l+1)^3+1)/2) = 0;
IM{cycle, 1}(((2*l+1)^3+1)/2, ((2*l+1)^3+1)/2) = -(str2double(answer3(1,1)) + str2double(answer3(2,1)) + sum(IM{cycle, 1}(:, ((2*l+1)^3+1)/2)) + str2double(answer3(6,1))*sum(IM{cycle, 1}(:, ((2*l+1)^3+1)/2)))
I = eye((2*l+1)^3);
C = zeros((2*l+1)^3, 1);
C(((2*l+1)^3+1)/2) = 1;
[P{cycle,1},D{cycle,1}] = eig(IM{cycle,1})
V{cycle,1} = (P{cycle,1}*expm((D{cycle,1})*t)*(P{cycle,1})^-1)*C
S1(cycle) = sum(V{cycle,1}(B1{q(cycle),1},1)) + V{cycle,1}(((2*l+1)^3+1)/2,1);
end
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Parallel Computing Fundamentals in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!