正如标题所说,我想要一个 parfor 循环,里面使用 arrayfun。
我为该问题创建了一个最小的工作示例:
在名为的文件中包含以下几行thisparfortest.m
function test=thisparfortest(countmax)
parfor count=1:countmax
test(count).nummer=count;
test(count).bisdrei=arrayfun(@(testnum)eq(test(count).nummer,testnum),1:3);
end
该命令mcc('-e','-v','thisparfortest')
导致
Compiler version: 4.18.1 (R2013a)
Error: File: **************\thisparfortest.m Line: 3 Column: 5
The variable test in a parfor cannot be classified.
See Parallel for Loops in MATLAB, "Overview".
Processing C:\Program Files\MATLAB\R2013a\toolbox\matlab\mcc.enc
Processing include files...
2 item(s) added.
Processing directories installed with MCR...
The file mccExcludedFiles.log contains a list of functions excluded from the CTF archive.
0 item(s) added.
Generating MATLAB path for the compiled application...
Created 43 path items.
Parsing file "****************\thisparfortest.m"
(Referenced from: "Compiler Command Line").
Parsing file "C:\Program Files\MATLAB\R2013a\toolbox\compiler\deploy\deployprint.m"
(Referenced from: "Compiler Command Line").
Parsing file "C:\Program Files\MATLAB\R2013a\toolbox\compiler\deploy\printdlg.m"
(Referenced from: "Compiler Command Line").
Unable to determine function name or input/output argument count for function
in MATLAB file "thisparfortest".
Please use MLINT to determine if this file contains errors.
Error using mcc
Error executing mcc, return status = 1 (0x1).
但正如建议的那样mlint thisparfortest
(也checkcode
)返回没有问题 - 就像在编辑器中一样。
该循环可以完成并编译为 for 循环。
请不要询问这些命令的含义——它们只是为 mwe 准备的。
我认为,这应该报告给 mathworks - 还是我做错了什么?
一些补充:运行时
function retval=thisparfortest(countmax)
helpfun=@(x)arrayfun(@(testnum)eq(x,testnum),1:3);
parfor count=1:countmax
retval(count).nummer=count^2;
retval(count).bisdrei=helpfun(retval(count).nummer);
end
只有for
循环才能工作,但是当使用显示的版本时parfor
会导致
Error using thisparfortest>(parfor supply) (line 3)
Undefined function or variable "retval".
Error in thisparfortest (line 3)
parfor count=1:countmax
Caused by:
Undefined function or variable "retval"
这不应该被 mlint/checkcode 捕获吗?这发生在没有编译器的情况下。