Re: [問題] 關於MATLAB 2008b 用四核心跑程式的問題已回收
※ 引述《joeytseng (:))》之銘言:
: ※ 引述《oscar328111 (土育山堯)》之銘言:
: : 我有一個程式用 Q6600四核心的電腦
: : 在RUN的時候 CPU使用率~~ 只有25~26% 好像沒有滿載
: : 請問要如何設定能讓它四個核心都跑到滿載
: 要有平行處理的部份
: : 已經試過在 File > Preferences > Multithreading > Automatic 打勾了
: : 一樣沒有作用
: 隨便寫一個簡單的範例:
: matlabpool open local 4 % 取得資源
: parfor (ii= 1:100000) % parallel-for-loop
: ii;
: end
: matlabpool close
精華區裡面有講到多執行緒的效能變化
並不只是對parfor有作用
以前學第稍微測試過多直行緒對於的cpu使用率
發現並不是全部指令都會用到多直行緒去跑的
至於後來看到了parfor
當年我也是感到挺有興趣
電腦換了E8400後
help看一看,然後拿裡面的範例來跑跑
首先一開始就是在平行運算項目裡面getting started裡的內容
裡面舉了兩個例子
一個是一般迴圈的寫法
clear A;
for i=1:1024
A(i) = sin(i*2*pi/1024);
end
plot(A);
一個是使用parfor的跑法
matlabpool open;
clear A;
parfor i=1:1024
A(i) = sin(i*2*pi/1024);
end
plot(A);
matlabpool close;
看到這兩個,我就做點小修改,加上計時和拿掉plot
來看看使用parfor到底可以讓效能提升多少,把程式碼改成這樣
clear A;
tic
for i=1:1024
A(i) = sin(i*2*pi/1024);
end
toc
matlabpool open;
clear A;
tic
parfor i=1:1024
A(i) = sin(i*2*pi/1024);
end
toc
matlabpool close;
而跑出來結果如下
Elapsed time is 0.001109 seconds.
Starting matlabpool using the parallel configuration 'local'.
Waiting for parallel job to start...
Connected to a matlabpool session with 4 labs.
Elapsed time is 0.316509 seconds.
Sending a stop signal to all the labs...
Waiting for parallel job to finish...
Performing parallel job cleanup...
Done.
而且是跑了好幾次的結果都0.001x秒和0.3x秒
才剛試用parfor就看到這樣的結果
之後我就再也沒有任何想要去碰平行運算相關內容的念頭了
不是說我不喜歡平行運算
只是一開始在起頭時就給我一個看起來好像沒有任何改善的結果(還變差了)
這實在很難讓我再有動力去研究平行運算的其他內容......-___-
--
Deserves death! I daresay he does. Many that live deserve death. And some die
that deserve life. Can you give that to them? Then be not too eager to deal out
death in the name of justice, fearing for your own safty. Even the wise cannot
see all ends.
Gandalf to Frodo
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.120.25.235
推
05/01 02:58, , 1F
05/01 02:58, 1F
討論串 (同標題文章)
MATLAB 近期熱門文章
PTT數位生活區 即時熱門文章