Code covered by the BSD License  

Highlights from
Parallel Producer-Consumer for MATLABPOOL

Parallel Producer-Consumer for MATLABPOOL

by

 

Provides a simple interface to the MATLABPOOL with functionality similar to PCT PARALLEL_FUNCTION.

example_pforfun(Nrow, Ncol, Nop)
% [outputData, intervals] = example_pforfun(Nrow, Ncol, Nop)
%   example pforfun usage
%
% Example, use all default arguments:
% example_pforfun;
%
% Example, all input and output arguments:
% [outputData, intervals] = example_pforfun(1, 15, 300);

function [outputData, intervals] = example_pforfun(Nrow, Ncol, Nop)
  
  % default arguments
  if nargin < 1
    Nrow = 1;
  end
  if nargin < 2
    Ncol = 15;
  end
  if nargin < 3
    Nop = 300;
  end
  
  % make pforfun arguments
  commonData.Nrow = Nrow;
  commonData.Ncol = Ncol;
  
  inputData = 1:Nop;
  
  configInfo.minBatchSize = 2;
  configInfo.enableWaitBar = true;
  configInfo.nameWaitBar = 'Example pforfun';
  
  tStart = tic;
  [outputData, intervals] = pforfun(@iTest, commonData, inputData, configInfo);
  toc(tStart)
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% rslt = ptest(data)
function rslt = iTest(commonData, inputData)
  
  % get number of iterations
  Nexc = numel(inputData);
  
  % extract some common data
  Nrow = commonData.Nrow;
  Ncol = commonData.Ncol;
  
  % make empty result struct
  rslt.dat = zeros(Nrow, Ncol);
  rslt(1:Nexc) = rslt;
  
  % main loop
  for n = 1:Nexc
    rslt(n).dat = randn(Nrow, Ncol);
    while any(rslt(n).dat(:) < 0)
      rslt(n).dat = randn(Nrow, Ncol);
    end
    rslt(n).dat(1, 1) = inputData(n);
  end
  
end

Contact us