2-2 使用多核心??速??

~Aڭ̤]iHɥΦhֹqBzAӥ[t{XCF즹\AAqƦh֤ߡAӥBAtΤ]w˥Bzuc]Parallel Processing ToolboxA² PCT^CY̭ݳơA[tp⪺kpUG
  1. bϥΥBzOeAUFumatlabpool local nvOA䤤 n N֤߼ƥءAҦp 4]|֤߹q^ 8]K֤߹q^C
  2. ϥ parfor OӨNӪ for jAO榡pUG
    parfor loopvar = initval:endval, statements, end
  3. ̫UFumatlabpool closevBz\C
ڭ̴NiHӹդ@²檺dҡG

Example 1: 02-{XPO餧̨Τ/parfor01.mver distcomp % PCT matlabpool local 4 n = 100; rowMedian1=zeros(1000, 1); rowMedian2=zeros(1000, 1); % === Ĥ@ؤkGcommon for-loop tic for i = 1:1000 rowMedian1(i) = max(eig(rand(n))); end time1 = toc; % === ĤGؤkGparallep for-loop tic parfor i = 1:1000 rowMedian2(i) = max(eig(rand(n))); end time2 = toc; fprintf('time1 = %g, time2 = %g, speedup factor = %g\n', time1, time2, time1/time2); matlabpool close------------------------------------------------------------------------------------------------------- MATLAB Version: 8.1.0.604 (R2013a) MATLAB License Number: DEMO Operating System: Microsoft Windows 7 Version 6.1 (Build 7601: Service Pack 1) Java Version: Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode ------------------------------------------------------------------------------------------------------- Parallel Computing Toolbox Version 6.2 (R2013a) Starting matlabpool using the 'local' profile ... connected to 4 workers. time1 = 4.94823, time2 = 1.62187, speedup factor = 3.05094 Sending a stop signal to all the workers ... stopped.

boӽdҤAڭ̲ͤF 1000 100x100 üƯx}AMpC@ӯx}Sxȡ]@ 100ӡ^̤jȡAYϥΥBzMΪ parfor jApt׬O@ for j骺 3 kC]ڪqO|֤ߡC^

pGAb MATLAB ɡA@٭n٭nקפAɭY MATLAB ΤFҦh CPUAi|ɭPqӺCUӡAALkiѽsC] parfor ѥt@ӰѼơAiHwҥΨ쪺u@̭ӼơAO榡pUG

parfor (loopvar = initval:endval, M), statements, end
䤤 M YOҥΨ쪺֤߭ӼơCҦpbUҤAMڪqO|֤ߡAڥuϥΨ֨Ӷi parfor BG

Example 2: 02-{XPO餧̨Τ/parfor02.mfprintf('MATLAB version = %s\n', version); matlabpool local 4 n = 100; rowMedian1=zeros(1000, 1); rowMedian2=zeros(1000, 1); % === Ĥ@ؤkGcommon for-loop tic for i = 1:1000 rowMedian1(i) = max(eig(rand(n))); end time1 = toc; % === ĤGؤkGparallel for-loop using 2 workers tic parfor (i = 1:1000, 2) % uΨӮ֤ rowMedian2(i) = max(eig(rand(n))); end time2 = toc; fprintf('time1 = %g, time2 = %g, speedup factor = %g\n', time1, time2, time1/time2); matlabpool closeMATLAB version = 8.1.0.604 (R2013a) Starting matlabpool using the 'local' profile ... connected to 4 workers. time1 = 4.91713, time2 = 2.58577, speedup factor = 1.90162 Sending a stop signal to all the workers ... stopped.

ѩuΨ֡AҥH[tƱ⭿C

bϥ parfor jɡAXInSO`NG

PCT O@ӥ\jjucAثe]iH䴩hxqBAåiHϥ GPU]Graphic Processing UnitAϧγBz^ӶijqBAԲӥ\аѦҤU@p`СC


MATLAB{]pGig