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 Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by