Using parallel.pool.constant with parfeval

8 ビュー (過去 30 日間)
Gerrit Schlömer
Gerrit Schlömer 2016 年 8 月 10 日
回答済み: Edric Ellis 2016 年 8 月 12 日
I've got large constant topological matrixes, I want to work with in parallel. I'm trying to find out how parfeval work's with a parallel.pool.constant. It's mentioned that it works on http://de.mathworks.com/help/distcomp/parallel.pool.constant.html
Here is my Test_Script.m:
Test = 1;
Testp = parallel.pool.Constant(Test)
for ab = 1:2
F(ab) = parfeval(@Test2,1);
end
parfor ab = 1:2
x(ab,:) = Testp.Value;
end
The function Test2.m ist only
function [out]=Test2()
out = Testp.Value
end
So the parfor-loop works, but the parfeval-loop says, that "Undefined variable "Testp" or class "Testp.Value"." Can you tell me, how it works?

採用された回答

Edric Ellis
Edric Ellis 2016 年 8 月 12 日
You need to explicitly pass the instance of parallel.pool.Constant into your parfeval call - it doesn't work like a global variable - it works more like an ordinary variable, but with some behind-the-scenes intelligence to minimise data transfers. So, here's what you'd need to change:
% In your script:
...
F(ab) = parfeval(@Test2, 1, Testp);
...
% In Test2.m:
function [out] = Test2(inConst)
out = inConst.Value;
end

その他の回答 (0 件)

カテゴリ

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