【问题标题】:Running CVX in parallel in Matlab在 Matlab 中并行运行 CVX
【发布时间】:2016-09-13 14:45:32
【问题描述】:

我正在并行运行具有不同参数的 CVX。串行运行时,我没有收到任何警告,但并行运行(使用 parfor),我得到以下信息:

 In cvx/bcompress (line 2)
  In cvxprob/newcnstr (line 233)
  In cvxprob/newcnstr (line 72)
  In == (line 3)
  In cvx/abs (line 68)
  In cvx/norm (line 56)
  In remove_l (line 27)
  In parallel_function>make_general_channel/channel_general (line 914)
  In remoteParallelFunction (line 38)
Warning: NARGCHK will be removed in a future release. Use NARGINCHK or NARGOUTCHK instead.

我以前没有见过这个,我不知道如何解决它。任何帮助表示赞赏。

【问题讨论】:

    标签: matlab cvx


    【解决方案1】:

    警告无需担心......至少立即。请记住,这是一个警告,因此您的代码仍应运行。它只是告诉您函数nargchk 已被弃用,您应该使用较新的版本:narginchknargoutchk。您可以在 nargchk 的 MathWorks 官方文档中看到此警告:http://www.mathworks.com/help/matlab/ref/nargchk.html。我的猜测是 CVX 的最后一个版本是在 MATLAB 决定做出这个决定之前开发的。

    因此,您所要做的就是进入第 2 行的bcompress 文件并将nargchk 更改为narginchk。具体来说,当您下载cvx 时,打开包含代码的文件夹,然后转到/lib/@cvx/bcompress.m。将第 2 行的行 error(nargchk(1, 3, nargin)); 更改为 error(narginchk(1, 3));

    如果您不打算升级您的 MATLAB 版本并且想要坚持使用当前版本,那么您可以忽略该警告。有关详细信息,请参阅 narginchk 上的 MathWorks 帮助文件:http://www.mathworks.com/help/matlab/ref/narginchk.html

    【讨论】:

    • 非常感谢。我已将警告设置为关闭。但是这些仍然是印刷的。无论如何,我根本不想要这个警告。我只是想知道如何找到 remoteParallelFunction 并进行一些更改?
    • @Erin - 当您下载cvx 时,打开包含代码的文件夹,然后转到/lib/@cvx/bcompress.m。将第 2 行的行 error(nargchk(1, 3, nargin)); 更改为 error(narginchk(1, 3));。我会更新我的帖子。事实证明,remoteParallelFunction 不是罪魁祸首,但这就是电话的来源。
    【解决方案2】:

    我遇到了同样的问题。这些警告不会改变代码的功能,但如果您尝试使用命令窗口来获得有用的输出,则会很痛苦。由于警告来自大量 CVX 文件,我编写了一个脚本来修复它们。

    要使用 nargchk 修复所有 CVX 文件,请将以下代码复制到名为“update_nargchk.m”的文件中,然后在不带参数的 cvx 根文件夹中运行它,或者使用指向 cvx 根文件夹的字符串参数从其他地方运行它.

    function update_nargchk(directory)
    %UPDATE_NARGCHK Updates files using the depricated nargchk
    %   All files in the specified directory (or current directory if
    %   unspecified) are searched. If an instance of nargchk is found being
    %   used (with nargin) it is updated to use narginchk with the same values.
    
    if ~exist('directory','var')
        directory = '.';
    end
    
    recurse(directory);
    
    end
    
    function recurse( folder )
    
    d = dir(folder);
    for elem = 1:length(d)
        if ~strcmp(d(elem).name,'.') && ~strcmp(d(elem).name,'..')
            if d(elem).isdir
                recurse([folder '/' d(elem).name]);
            else
                if strcmp(d(elem).name(end-1:end),'.m') 
                    updateFile([folder '/' d(elem).name]);
                end
            end
        end
    end
    
    end
    
    function updateFile(filename)
    
    % read file contents into workspace
    fid = fopen(filename);
    C=textscan(fid,'%s','delimiter','\n','whitespace','');
    C = C{1,1};
    fclose(fid);
    
    % check for instances of nargchk
    instanceFound = false;
    for k=1:numel(C)
        textline = C{k,1};
        if ~isempty(regexp(textline,'^[^%]*nargchk','ONCE')) && ...
                ~isempty(regexp(textline,'^[^%]*nargin','ONCE'))
            instanceFound = true;
            nums = regexp(textline,'(\d+|-?Inf)','tokens');
            nums = [str2double(nums{1}) str2double(nums{2})];
            C(k) = {['narginchk(' num2str(nums(1)) ',' num2str(nums(2)) '); % Modified from: ' textline]};
        end
    end
    
    if instanceFound
        % print new file
        fid = fopen(filename,'w'); % Open the file
        for k=1:numel(C)
            fprintf(fid,'%s\r\n',C{k,1});
        end
        fclose(fid);
        disp([filename ' updated'])
    end
    
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-10
      • 1970-01-01
      • 2017-04-20
      • 2012-10-08
      • 2023-03-05
      • 2015-05-29
      相关资源
      最近更新 更多