Unrecognized function or variable in parfor

23 views (last 30 days)

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

Answers (1)

Raymond Norris
Raymond Norris on 28 Mar 2022
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
Raymond Norris
Raymond Norris on 9 Apr 2022
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!