Error using Parallel Computing Toolbox with INTLAB

7 ビュー (過去 30 日間)
Marc Arsenault
Marc Arsenault 2016 年 10 月 20 日
編集済み: Marc Arsenault 2016 年 10 月 21 日
Hi,
I am unable to convert code that uses interval arithmetic (based on the INTLAB toolbox) to be executed in parallel using the Parallel Computing toolbox. Here is a snippet of (otherwise useless) code which will lead to the error:
x=infsup(1,2);
pool=parpool(2);
parfor i=1:1
2*x
end
Here is the error message that is received:
Starting parallel pool (parpool) using the 'local' profile ... connected to 2 workers.
Error using * (line 35)
Struct contents reference from a non-struct array object.
Error in spmd_test (line 8)
parfor i=1:1
Please note that the same code would work without issue if a standard "for" loop was used instead of "parfor". Any advice would be appreciated on why this doesn't work as expected.
Thank you,
Marc

回答 (3 件)

Marc Arsenault
Marc Arsenault 2016 年 10 月 21 日
編集済み: Marc Arsenault 2016 年 10 月 21 日
Many thanks to Michio and Edric for promptly responding to my query. I eventually found the issue to be due to the use of a global variable (INTLAB_CONST) within the Intlab toolbox and referred to by mostly all commands provided by the toolbox. Since the Parallel Computing toolbox doesn't have a good relationship with global variables, this led to the error (the error message itself was to the effect that the INTLAB_CONST variable, which is a structure, did not exist in the m-file being executed). A functional workaround is the following (for example):
% Main function excerpt (illustration only):
global INTLAB_CONST
parloop i=1:100
% Call to subroutine:
x=other_function(INTLAB_CONST,other_variables);
end
Within the subroutine being called by the parfor loop, the global variable is again declared and the value passed explicitly to the function is assigned to it, e.g.:
function x=other_function(INTLAB_CONST_TEMP,other_variables)
global INTLAB_CONST
INTLAB_CONST=INTLAB_CONST_TEMP
% Remainder of code...
end
I believe this allows (forces?) the Parallel Computing toolbox to categorize INTLAB_CONST as a variable and avoid the aforementioned difficulties.
Thanks again!
Marc

michio
michio 2016 年 10 月 20 日
編集済み: michio 2016 年 10 月 20 日
There are some restrictions on variables you can use within parfor. Example: Use Objects and Handles in parfor-Loops
I am guessing that the following code would work without a problem.
x=1;
pool=parpool(2);
parfor i=1:1
2*x
end
If so, getting to know what x=infsup(1,2) is should help. What kind of datatype does infsup returns? Could you try
x = infsup(1,2);
whos x
to see the datatype of x? Or could you simply get output without displaying the result?
x=infsup(1,2);
pool=parpool(2);
parfor i=1:1
result(i) = 2*x;
end

Edric Ellis
Edric Ellis 2016 年 10 月 21 日
I suspect this is related to the transfer of an object of type infsup. You could check this as follows:
x = infsup(1,2);
save tmp x
clear
load tmp
x * 2;
If that fails in the same way, then the problem lies with the class infsup. If that succeeds, then I'm not sure where the problem lies...

カテゴリ

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