推薦軟硬體、網站

Google Adsense

aNobii網路書櫃

顯示具有 科學計算 標籤的文章。 顯示所有文章
顯示具有 科學計算 標籤的文章。 顯示所有文章

2009年9月26日 星期六

MATLAB R2009b for Mac: A Simple Performance Test

中文標題:MATLAB R2009b for Mac: 簡單測試文

前陣子的文章才提到一些關於MATLAB R2009b的消息,對MacOSX Snow Leopard來說,最好的消息就是R2009b for Mac終於是64-bit啦!安裝的時候有個"Select Architecture",可以選擇"Intel"(3630MB)或"Intel 64"(3802MB),或者是都選(4927MB)。

如果都選的話,安裝結束可以在 /Applications/MATLAB_R2009b -> 顯示套件內容 -> bin 裡分別看到maci和maci64這兩個資料夾。

裝完以後以預設64-bit執行,可以看到令人感動的初始畫面:


要以32-bit執行,在MATLAB_R2009b的 右鍵->簡介 中可以選擇「在32位元模式中開啟」:

甚至在工具程式->活動監視器(Activity Monitor)裡,MATLAB的「種類」也被標示成「Intel (64位元)」呢!這是我第一次看到non-Apple software被標示成64-bit XD。

至於大家最關心的速度,我先前已經用過R2009a跑了我影像處理簡介的期末Project,並記下數據了。這次我分別用R2009b(32-bit)和R2009b(64-bit)跑了一次,產生以下的結果(in seconds):


可以看出R2009b(32-bit)除了encode_img1進步12.69%以外,其他幾乎沒進步甚至還變慢Orz。
不過R2009b(64-bit)數據可就威了,幾乎都能減少10%甚至是20%的時間
而且加速原因是64-bit,而不是版本從a變b喔XD。

夠不夠厲害可能是自由心證啦,不過我是已經覺得很滿意了!

2009年9月2日 星期三

[Mac] MATLAB R2009a on Snow Leopard : An Installation Solution

If you previously installed MATLAB R2009a on OSX 10.5 Leopard, and then upgraded your OS to OSX 10.6 Snow Leopard, the MATLAB program would work fine.

But if you try to install MATLAB R2009a on Snow Leopard, you will get the following Java exception: (For those who just want to know the solution, go directly to the second image)
So I went check the log, saying:

(Sep 03, 2009 01:35:52)Starting activation process.
(Sep 03, 2009 01:35:52)Performing interactive activation.
(Sep 03, 2009 01:35:52)MATHWORKS ACTIVATION IS STARTING UP.
(Sep 03, 2009 01:35:54)com.mathworks.instutil.JNIException: java.lang.UnsatisfiedLinkError: Cant load library: /Applications/MATLAB_R2009a.app/bin/maci64/libinstutil.jnilib
java.lang.UnsatisfiedLinkError: Cant load library: /Applications/MATLAB_R2009a.app/bin/maci64/libinstutil.jnilib
com.mathworks.instutil.NativeUtility.(NativeUtility.java:30)
com.mathworks.instutil.MachineInfo.(MachineInfo.java:41)
com.mathworks.activationclient.model.ActivationModelImpl.loadNativeLib(ActivationModelImpl.java:228)
com.mathworks.activationclient.model.ActivationModelImpl.getMachineInfo(ActivationModelImpl.java:211)
com.mathworks.activationclient.view.ApplicationViewImpl.getMachineInfo(ApplicationViewImpl.java:260)
com.mathworks.activationclient.view.ApplicationViewImpl.showGUI(ApplicationViewImpl.java:116)
com.mathworks.activationclient.controller.ApplicationControllerImpl.start(ApplicationControllerImpl.java:118)
com.mathworks.activationclient.ActivationClientImpl.start(ActivationClientImpl.java:210)
com.mathworks.activationclient.ActivationApplication.goInteractive(ActivationApplication.java:186)
com.mathworks.activationclient.ActivationApplication.go(ActivationApplication.java:172)
com.mathworks.activationclient.ActivationApplication.main(ActivationApplication.java:135)

(Sep 03, 2009 01:35:54)java.lang.NullPointerException
com.mathworks.activationclient.view.ApplicationViewImpl.showGUI(ApplicationViewImpl.java:116)
com.mathworks.activationclient.controller.ApplicationControllerImpl.start(ApplicationControllerImpl.java:118)
com.mathworks.activationclient.ActivationClientImpl.start(ActivationClientImpl.java:210)
com.mathworks.activationclient.ActivationApplication.goInteractive(ActivationApplication.java:186)
com.mathworks.activationclient.ActivationApplication.go(ActivationApplication.java:172)
com.mathworks.activationclient.ActivationApplication.main(ActivationApplication.java:135)

(Sep 03, 2009 01:36:10)There was an unexpected exception:
null

Then I checked the MATLAB_R2009a.app (right click => Show Package Content), and found that
there was no such directory "bin/maci64", but only "bin/maci".
So I copied and renamed it to "maci", ran the installation again. This time I got another exception:


(Sep 03, 2009 12:26:51)com.mathworks.instutil.JNIException: java.lang.UnsatisfiedLinkError: /Applications/MATLAB_R2009a.app/bin/maci64/libinstutil.jnilib: no suitable image found. Did find: /Applications/MATLAB_R2009a.app/bin/maci/libinstutil.jnilib: mach-o, but wrong architecture /Applications/MATLAB_R2009a.app/bin/maci64/libinstutil.jnilib: mach-o, but wrong architecture
java.lang.UnsatisfiedLinkError: /Applications/MATLAB_R2009a.app/bin/maci64/libinstutil.jnilib: no suitable image found. Did find: /Applications/MATLAB_R2009a.app/bin/maci/libinstutil.jnilib: mach-o, but wrong architecture /Applications/MATLAB_R2009a.app/bin/maci64/libinstutil.jnilib: mach-o, but wrong architecture
...

This "wrong architecture" message reminded me to turn to Java settings for the final trial.
(After all, the activation program was written in Java :p)
And it worked!!

Here's the solution:
1. Use Finder to go to /Applications/Utilities/Java Preferences.
2. In the Java Application section, set 32-bit as the first priority over the 64-bit by dragging it upward.
3. Run the MATLAB R2009a installation again.

As I remember, Java in Leopard had the Java SE 5 (32-bit) as the first priority, but Snow Leopard does not! (all Java SE 6, and 64-bit first)

Hopefully you will finally see this activation window. I believe everyone knows what to do next :DD
Upon success, you can see that MATLAB R2009a runs in 32-bit mode.


I also saw some good news about the coming R2009b release from MATLAB Central blog.
The R2009b will be a 64-bit version, and will move one step closer to being entirely independent of X11. However the latter is going to take another couple of releases to accomplish...

I really look forward to the day when 64-bit + native MATLAB application become possible :)

2008年10月11日 星期六

Octave on MacOSX

說到科學計算,一般人總是想到MathWorks公司的MATLAB。但這學期修數值方法,老師反而推薦另一套軟體:GNU/Octave
其實這樣的態度是好的,老師也說,學生時期,應該要鼓勵我們用沒有版權爭議的Octave,而不是奇怪版本的MATLAB。況且MATLAB包含的領域太多了大部分也用不到,身為自由軟體的支持者,雖然MATLAB也能做到,但如果只是修課、寫作業的話,當然要試試看Octave這套軟體。


如果是Windows使用者那就直接跳過這篇吧XD。Windows上面的設定很簡單,只要抓回來安裝好就好了,而且還有內建編輯器SciTE,用edit指令就可直接呼叫。
Mac底下就沒有那麼容易了,自己也曾經碰到一些困難。以下說明Octave for MacOSX的一些主要設定步驟:

1. 下載編譯好的可執行檔
2. 解決編輯器的問題
3. 設定.octaverc
4. 解決繪圖的問題(gnuplot與AquaTerm)



1. 下載編譯好的可執行檔
這很簡單,官網Download的地方選MacOSX可以連到SourceForge下的下載頁面。選擇最新的版本並確定自己的機型就可以囉。Intel的選octave-x.x.x-i386.dmg,PowerPC的選octave-x.x.x-ppc.dmg。


接下來就是簡單的drag-and-drop,把disk image檔裡的Octave.app拖曳到Applications裡就可以啦。
不過檔案先別急著刪,Extras資料夾裡的gnuplot等等還會用到!
用一般方式開啟Octave,就可以得到如下的終端機畫面:


注意畫面上方的標題,與開terminal時不一樣,Octave使用的shell是sh而不是一般情形的bash,所以有些unix指令在octave裡是行不通的。


2. 解決編輯器的問題
Octave for Mac的一大問題就是沒有內建編輯器。雖然說其實有沒有不影響,開個慣用的editor來寫,再用Octave來跑就行了。不過當打edit指令沒有辦法出現自己習慣的編輯器畫面,爽度就是有差XD。
Octave預設的編輯器是emacs,不信可以打入EDITOR來查看環境變數,會出現"ans = emacs"。
如果要換成vim,可以打
> edit editor "vim %s" 來切換,雙引號和%s都要照打,>是命令提示字元不用打。

但我和同學用edit或是edit xxx來編輯檔案都會當掉,不知什麼原因,我們用的是Intel Mac + OSX 10.5.5,預設編輯器換成vim也是不行,看來只要是terminal下的編輯器都有問題。
感謝iPluto補充:也可以用edit editor "xterm -e vim %s"就不會當,但是這樣會多開X11環境多此一舉。

解決之道就是改用其他GUI的編輯器,不推薦TextMate,雖然號稱最貴的text editor,但中文支援有問題,而且想支援MATLAB語法還要裝外掛。
所以我推薦用Smultron,是自由軟體,支援數十種程式語言,也有一些不錯的特色。可惜對於MATLAB語言的支援還是不如MATLAB的編輯器來得好,keyword辨別、註解、縮排等還有進步空間,不過以一個支援這麼多語言的編輯器來說算很不錯了!


首先要注意,Smultron會把.m的副檔名,辨認成Mac開發者常用的Objective-C,所以除非讀者本身就是Cocoa API的視窗程式開發高手,否則可以考慮修改副檔名辨認。


在偏好設定->進階->語法定義,勾選「使用擴展名猜測」,並且在下面的程式語言列表中,把Matlab後面加上m,把Objective-C的m去掉,這樣以後用Smultron開.m時,就能辨識成Matlab語法了。

最後還有一步,既然我們希望在Octave底下打edit就能開Smultron,就必須讓它能從terminal開啟。所幸Smultron和TextMate都有這項設計。


從Smultron選單的說明->安裝命令行工具,或是TextMate選單的Help->Terminal Usage(TextMate第一次啟動似乎就會問你要不要裝),即可輕易安裝。過程會要求輸入管理者的密碼,因為要動到/usr/bin下的東西。剩餘步驟請見下一段。


3. 設定.octaverc
編輯器安裝設定完了,因為現在/usr/bin下已經有smultron, mate這些東西,只要到terminal下打
> smultron 或
> mate
就能開啟該GUI文字編輯器。(注意開terminal時,如果目前正在跑octave,要按cmd+N開一個新視窗才是bash shell的terminal喔)
再回到Octave畫面,打edit editor "smultron %s"就能將預設編輯器改成Smultron。
不過必須每次開Octave都要下edit editor "smultron %s"才能變更編輯器,很麻煩該怎麼辦呢?

可以設定.octaverc。點代表隱藏檔,rc是run commands的縮寫,在程式開始的時候就run一些commands,意義相當於偏好設定檔。其他unix-like系統常見的有.vimrc,.bashrc,.cshrc。
現在再回到bash terminal(不是octave喔),我們要在home底下建立.octaverc。
> cd ~ 切換到home,~代表家目錄的意思
> touch .octaverc 為了避免沒這個檔案,先摸(建立)一下。一定要加"點"喔!
> open .octaverc 用Mac的文字編輯開啟.octaverc。
會用vim的人也可以直接在第二步:
> vim .octaverc



先把預設編輯器改成自己喜歡的:
edit editor "smultron %s"
然後看還有沒有其他的東西要設定。例如預設的起始路徑是~/,但是我喜歡把程式都放在~/Octave目錄下,所以可以多加這行:
cd ~/Octave
讀者如果有自己習慣要先跑的指令也可以加在這裡。


4. 解決繪圖的問題(安裝gnuplot與AquaTerm)
現在再回到Octave下,舉一個簡單的繪圖範例:
> x = 1:100;
> y = sqrt(x);
> plot(x,y);
這樣會畫出 y=sqrt(x)從x=1~100的圖,可是畫面卻出現error:
error: you must have gnuplot installed to display graphics; if you have gnuplot installed in a non-standard location, see the 'gnuplot_binary' function 原來是還需要gnuplot這個元件才能畫圖。這時候回到1.抓下來的octave-x.x.x-xxxx.dmg檔,把Extras裡的gnuplot-x.x.x-xxxx.dmg裝起來,同樣也是drag-and-drop就可以了。(其實一開始就該裝了啦XD,只是故意寫在後面來說明。)

注意:使用gnuplot需要先安裝X11系統,OSX10.5 Leopard本身就附上X11了,但OSX10.4 Tiger的人需要到安裝光碟Disc 2找X11來裝,但下面有免X11的解決方法。

這時候再畫一次應該就能出現這樣的結果:


有點鋸齒狀,效果不是很好。因此在Mac上推薦使用AquaTerm這個套件。網路上說:

AquaTerm allows you to plot things in OS X without using an X client, such as X11. This has two advantages:
  • It requires less memory and hard drive space, if you don't have X installed or running already.
  • The graphs look better, and can be saved as Quartz PDFs.
不需要X11,省空間跟記憶體,畫出來的圖漂亮又能存成PDF和EPS,所以別懷疑快去下載吧。安裝方法也是簡單的drag-and-drop至/Applications裡。
不過裝完AquaTerm仍然會用X11來畫圖,還差最後一步。到bash terminal下:
> cd ~
> touch .profile
> open .profile 編輯.profile這個檔案,還是要加"點"。檔案裡打入這行:
export GNUTERM='aqua'

存檔離開,重新開啟Octave,再用剛剛的畫圖範例:
> x = 1:100;
> y = sqrt(x);
> plot(x,y);
現在用Octave畫圖就會開啟AquaTerm來顯示了,很細緻呢!




《本篇文章歡迎補充與指教》
主要參考資料:Octave Docs,Octave Wiki上的OctaveForMac
Powered By Blogger

Google Analytics