Unrecognized function or variable in parfor

15 ビュー (過去 30 日間)
An Engineer
An Engineer 2022 年 3 月 27 日
コメント済み: Raymond Norris 2022 年 4 月 9 日

I am a beginner in MATLAB software and I use MATLAB online .The problem is in initializing a variable called 'estModel' in a parallel loop . I want to use parallel processing because the calculations take a long time to complete but this problem occurs when I use 'threads' in parpool instead of 'local' . In 'local' mode this problem does not exist and the code is executed correctly and the results are correct . But in the case of 'threads', the variable 'estModel' is not initialize in the parfor loop , and give this error : Unrecognized function or variable 'estModel' . In 'local' mode the number of workers are 2 but in 'threads' mode the number of workers are 8 . So I use 'threads' instead of 'local' . I do not know about parpool structure completely . Is there a problem in this part ( parpool : local or threads or ... and chooses 'threads' based on the number of workers ) ? Finally the three variables 'kh', 'model' and 'DATA' are completely initializing before parallel loop and the variable 'model' uses the arima function .
Can anyone help me to solve this problem?
part of code :
parfor i=1:kh

回答 (1 件)

Raymond Norris
Raymond Norris 2022 年 3 月 28 日
I don't see how you're getting the error. Can you provide a bit more context? For example, when I run something similar (I think?), I get a different error
kh = 2;
for i = 1:kh
model(i) = arima(2,0,1); %#ok<SAGROW>
DGP = arima('AR',{0.5,-0.3},'MA',0.2,'Constant',0,'Variance',0.1);
T = 500;
DATA = simulate(DGP,T);
poolObj = parpool("threads");
parfor i = 1:kh
estModel(i) = estimate(model(i),DATA);
Is this not what you're seeing?
Error using optimoptions
Use of function matlabpath is not supported on a thread-based worker.
Error in arima/estimate (line 253)
default = optimoptions('fmincon');
Related documentation
  7 件のコメント
Raymond Norris
Raymond Norris 2022 年 4 月 9 日
Hi @An Engineer. Support for local clusters running on MATLAB Online was recently unintentionally added and has since been removed. You might consider running remote clusters with Cloud Center. To do so, you'll need an AWS account as well as a MATLAB Parallel Server license. Contact your Account Rep or Technical Support for more information.


Community Treasure Hunt

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

Start Hunting!

Translated by