Parfor and cell array

2 次查看(过去 30 天)
Michael
Michael 2014-10-21
回答: Michael 2014-10-21
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.

采纳的回答

José-Luis
José-Luis 2014-10-21
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()

更多回答(1 个)

Michael
Michael 2014-10-21
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.

类别

Help CenterFile Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by