Effacer les filtres
Effacer les filtres

Unrecognized function or variable in parfor

14 vues (au cours des 30 derniers jours)
An Engineer
An Engineer le 27 Mar 2022

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

Réponses (1)

Raymond Norris
Raymond Norris le 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
  7 commentaires
Walter Roberson
Walter Roberson le 29 Mar 2022
Edit NumWorkers (number of workers to start on your local machine)
The default setting is the number of physical cores, but you can change that. You can, for example, double that so that hyperthreaded cores are used as well (assuming that you have hyperthreading enabled.)
You could, if you wanted, ask for 50 workers (but more than 64 can be a problem on Windows.) You would be leaving it up to the operating system to schedule all those workers on the number of cores (and hyperthreads) actually available.
But remember:
  • On the great majority of CPUs, hyperthreading does not provide additional compute capacity. hyperthreading is more a fast-switch technology, so that as soon as a worker volunteers to give up control of a core (to wait for disk or an interrupt or for a user to respond or voluntary pause()), then the new worker gets activated quite quickly. Hyperthreading does not add any additional Arithmetic Logic Units or instruction decoders or so on.
  • On some quite new CPUs, hyperthreading is able to dispatch instructions to the Integer Arithmetic Logic Unit while the main thread is busy doing floating point tasks. Using this effectively requires some very fine tuning.
  • If you have more workers than you have effective available cores. then the operating system might try to schedule them "fairly" -- which might mean that it rolls a worker out and replaces it with another worker. This takes time lowers the overall efficiency compared to running one task to completion and then starting another
Raymond Norris
Raymond Norris le 9 Avr 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.

Connectez-vous pour commenter.


En savoir plus sur Parallel Computing Fundamentals dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by