Code covered by the BSD License  

Highlights from
BSD/Linux Host Information and matlabpoolPlus

BSD/Linux Host Information and matlabpoolPlus

by

 

21 Dec 2012 (Updated )

Get information about the host on which the Matlab instance is running. Also provides matlabpoolPlus

matlabpoolPlus(alpha,profname)
function nw = matlabpoolPlus(alpha,profname)
  % MATLABPOOLPLUS is a wrapper around matlabpool that uses the available
  %   local (!) number of processors of the current host to calculate the 
  %   number of workers (depending on the parameter alpha).
  %
  % Alpha can be used in 3 ways (let np be the number of processors):
  %   if alpha < 0 (integer), matlabpool local (np-alpha)
  %      i.e., the number of workers equals the number processors minus
  %      alpha
  %   if alpha > 0 && alpha < 1 (fraction), matlabpool local ceil(alpha*np)
  %      i.e., only use a fraction (alpha) of the available processors
  %   if alpha > 1 (integer), matlabpool local min(alpha,np)
  %      i.e., use up to alpha processors
  %
  % Returns the number of created workers.
  %
  % @author B. Schauerte
  % @date 2013
  
  % Copyright 2013 B. Schauerte. All rights reserved.
  % 
  % Redistribution and use in source and binary forms, with or without 
  % modification, are permitted provided that the following conditions are 
  % met:
  % 
  %    1. Redistributions of source code must retain the above copyright 
  %       notice, this list of conditions and the following disclaimer.
  % 
  %    2. Redistributions in binary form must reproduce the above copyright 
  %       notice, this list of conditions and the following disclaimer in 
  %       the documentation and/or other materials provided with the 
  %       distribution.
  % 
  % THIS SOFTWARE IS PROVIDED BY B. SCHAUERTE ''AS IS'' AND ANY EXPRESS OR 
  % IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
  % WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
  % DISCLAIMED. IN NO EVENT SHALL B. SCHAUERTE OR CONTRIBUTORS BE LIABLE 
  % FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  % CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
  % SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
  % BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
  % WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  % OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  % ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  %  
  % The views and conclusions contained in the software and documentation
  % are those of the authors and should not be interpreted as representing 
  % official policies, either expressed or implied, of B. Schauerte.
 
  if nargin < 1, alpha = 0.999; end % default: use all available processors
  if nargin < 2, profname = 'local'; end
  
  np = getnumprocessors(); % override the default max number of workers
  
  prof = parcluster(profname);
  prof.NumWorkers = np;
  
  nw = 0;
  if alpha < 0
    assert(isinteger(alpha)); % otherwise, wrong usage
    nw = np-alpha; 
    matlabpool(prof,'open',nw);
  elseif alpha > 0 && alpha < 1
    nw = ceil(np*alpha);
    matlabpool(prof,'open',nw);
  elseif alpha > 1
    assert(isinteger(alpha)); % otherwise, wrong usage
    nw = min(np,alpha);
    matlabpool(prof,'open',nw);
  elseif alpha == 1
    % ... do nothing, avoid opening a single matlabpool
  elseif alpha == 0
    % ... I have no idea what that would mean
  end
    

Contact us