Parfor and cell array

1 visualizzazione (ultimi 30 giorni)
Michael
Michael il 21 Ott 2014
Risposto: Michael il 21 Ott 2014
Suppose I have the following code
p = cell(1,3);
w = zeros(5,3);
p{1} = X; 2 by 2 matrix
p{2} = Y; 2 by 2 matrix
p{3} = Z; 2 by 2 matrix
parfor k=1:3
for i=1:5
w(i,k) = somefunction(variable1, variable2,p{k})
end
end
If I remove the parfor, the code runs fine, but if I use the parfor I get the error: Output argument "XXXX" from some other function that is used in "somefunction" was not assigned during call.
Sorry for being very schematic but the actual code is very long has and uses numerous functions.

Risposta accettata

José-Luis
José-Luis il 21 Ott 2014
It works for me:
p = cell(1,3);
w = zeros(5,3);
p{1} = rand(2);
p{2} = rand(2);
p{3} = rand(2);
myFun = @(x,y,z) x + y + sum(z(:));
variable1 = 1;
variable2 = 2;
parfor k=1:3
for i=1:5
w(i,k) = myFun(variable1, variable2,p{k})
end
end
I'm afraid you'll have to provide more details about variable1, variable2 and somefunction()

Più risposte (1)

Michael
Michael il 21 Ott 2014
Figured it out, a portion of the workers were working with variables p{k} that had a defective input. The matrices were not Hermitian and the code only works if they are. Running each iteration separately helped.

Categorie

Scopri di più su Parallel for-Loops (parfor) in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by