带有arrayfun的matlab parfor(切片变量)

时间:2013-08-13 08:35:54

标签: matlab matlab-compiler parfor

正如标题所说,我希望有一个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循环 请不要问这些命令的意义 - 他们只是为了这个命令 我想,应该向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捕获? 没有编译器就会发生这种情况。

1 个答案:

答案 0 :(得分:1)

我不相信这个问题与编译有关。当我尝试在常规MATLAB中运行代码时,我得到的错误是test中的变量parfor无法归类。

这里没有错误 - 并非每一段代码都可以在parfor循环内运行,并且MATLAB不可能在运行时之前完全确定哪些部分可以和不可以。它试图做得很好,当它发生时,代码分析器会在运行之前告诉你 - 但是当它不能时,它会发出你发现的运行时错误。

也许你可以想到一种方法,MATLAB可以静态地确定这个变量不能被分类 - 在这种情况下,这可以作为代码分析器的增强请求报告给MathWorks。

相关问题