MATLAB 并行for运算

来源:互联网 发布:常州seo排名公司 编辑:程序博客网 时间:2024/06/10 03:58

Memo for MATLAB Parfor.

Execute Loop Iterations in Parallel - Parfor

Main Steps

Step1. Initialization

numCores: number of cores used in loop iterations

%Close the pools, if anytry    fprintf('Closing any pools...\n');    parpool close; catch    %ignore any errors endfprintf('Starting a pool of workers with %d cores\n', numCores);parpool('local',numCores);

Step2. Execution

%matlab can't save/load inside parfor%accumulate them and then saveparfor i = 1:N    f(i);end

Step3. Closing

%close the poolfprintf('Closing the pool\n');parpool close;

References:

  1. Execute loop iterations in parallel - Parfor
  2. MATLAB并行:parfor
原创粉丝点击