Parfor and cell array

1 Ansicht (letzte 30 Tage)
Michael
Michael am 21 Okt. 2014
Beantwortet: Michael am 21 Okt. 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.

Akzeptierte Antwort

José-Luis
José-Luis am 21 Okt. 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()

Weitere Antworten (1)

Michael
Michael am 21 Okt. 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.

Kategorien

Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by