MATLAB 中 parfor 中无法识别的函数或变量

发布于 2025-01-17 07:45:18 字数 1435 浏览 1 评论 0原文

我是 MATLAB 软件的初学者,我在线使用 MATLAB。问题在于在并行循环中初始化名为“estModel”的变量。我想使用并行处理,因为计算需要很长时间才能完成,但是当我在 parpool 中使用 'threads' 而不是 'local' 时,就会出现此问题。在“本地”模式下,不存在此问题,代码执行正确,结果正确。但在“线程”的情况下,变量“estModel”未在 parfor 循环中初始化,并给出此错误:无法识别的函数或变量“estModel”。在“本地”模式下,工作人员数量为 2 ,但在“线程”模式下,工作人员数量为 8 。所以我使用“线程”而不是“本地”。我完全不了解 parpool 结构。这部分有问题吗( parpool :本地或线程或...并根据工作人员数量选择“线程”)?最后,三个变量“kh”、“model”和“DATA”在并行循环之前完全初始化,变量“model”使用 arima 函数。 谁能帮我解决这个问题?

code :

clear all;
close all;
clc;
DATA=xlsread('test');  % The data for modeling and forecasting is read from an excel file called test, which is a column vector.
size_of_DATA=length(DATA);
p=20;  % nonseasonal autoregressive polynomial degree range in arima model.
q=10;  % nonseasonal moving average polynomial degree range in arima model.
D=2;   % degree of nonseasonal integration range in arima model.
h=0;   % counter
for k=1:D
    for j=1:q
        for i=1:p
            if i+j+k-2<=size_of_DATA
                h=h+1;
                model(h)=arima(i-1,k-1,j-1);
            end
        end
    end
end
poolobj=parpool('threads'); 
parfor i=1:h
    estModel(i)=estimate(model(i),DATA);
end
delete(poolobj);

名为“test”的 Excel 文件是一个任意时间序列,它是一个包含 500 个数据的列向量(当然,其长度可以变化)。您可以使用此链接中的文件进行测试: ln5.sync.com/dl/9e3913140/ctiyajcx-mgmnis6z-8mgyaigq-p2a9hpxu

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?

code :

clear all;
close all;
clc;
DATA=xlsread('test');  % The data for modeling and forecasting is read from an excel file called test, which is a column vector.
size_of_DATA=length(DATA);
p=20;  % nonseasonal autoregressive polynomial degree range in arima model.
q=10;  % nonseasonal moving average polynomial degree range in arima model.
D=2;   % degree of nonseasonal integration range in arima model.
h=0;   % counter
for k=1:D
    for j=1:q
        for i=1:p
            if i+j+k-2<=size_of_DATA
                h=h+1;
                model(h)=arima(i-1,k-1,j-1);
            end
        end
    end
end
poolobj=parpool('threads'); 
parfor i=1:h
    estModel(i)=estimate(model(i),DATA);
end
delete(poolobj);

The excel file called 'test' is an arbitrary time series that is a column vector with 500 datas (of course, its length can vary). you can use file in this link for test : ln5.sync.com/dl/9e3913140/ctiyajcx-mgmnis6z-8mgyaigq-p2a9hpxu

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文