Erin
Erin

Reputation: 187

Running CVX in parallel in Matlab

I am running CVX with different parameters in parallel. When running in serial, I do not get any warning, but running in parallel (with parfor), I get the following:

 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.

I haven't seen this before and I do not know how to solve it. Any help is appreciated.

Upvotes: 0

Views: 1175

Answers (2)

user2305198
user2305198

Reputation: 1

I was having the same issue. The warnings don't change the functionality of the code but are a pain if you're trying to use the command window for useful output. Since the warning was coming from a huge number of CVX files I wrote a script to fix them all.

To fix all CVX files using nargchk copy the following code into a file named 'update_nargchk.m' and either run it in the cvx root folder with no arguments or run it from elsewhere with a string argument pointing to your cvx root folder.

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

Upvotes: 0

rayryeng
rayryeng

Reputation: 104545

The warning is nothing to worry about... at least immediately. Remember, it's a warning so your code should still run. It is simply telling you that the function nargchk is deprecated and that you should use the newer versions: narginchk and nargoutchk instead. You can see this warning at the MathWorks official documentation for nargchk here: http://www.mathworks.com/help/matlab/ref/nargchk.html. My guess is that the last version of CVX developed was before MATLAB decided to make this decision.

As such, all you have to do is go into the bcompress file at line 2 and change nargchk with narginchk. Specifically, when you download cvx, open up the folder that contains the code, then go /lib/@cvx/bcompress.m. Change the line at line 2 error(nargchk(1, 3, nargin)); to error(narginchk(1, 3));.

If you don't intend on upgrading your version of MATLAB and you want to stick with the current version you have, then you can simply ignore the warning. See the MathWorks help file on narginchk for more details: http://www.mathworks.com/help/matlab/ref/narginchk.html

Upvotes: 1

Related Questions