Skip navigation

Category Archives: Matlab

Dual processorなG5を使っているにも関わらず、ボクが使っているモノの中で一番CPU powerを必要とするMatlabがDual processorに対応していない為、いささか宝の持ち腐れ気味。

なんとなく、Mac版のMatlabはJavaで動いているせいじゃないか、って思っていたけど、ひょっとしたら本当にそうなのかもしれない…

実は、GUI版のMatlabを使うのが一般的だけれども、Terminal.appからcommand lineでMatlabを起動させることが出来る。

% cd /Applications/MATLAB_SV701/bin
% export DISPLAY=: 0.0
% ./matlab -nojvm

こんな感じで。(ちなみに、%はcommand prompt)データをplotするのとかもX11を使って出来るけど、Javaを使っているArray editorとかは使えない。

で、とりあえず1から1000まで表示させて、それをさらに1000回繰り返す単純なプログラムを書いて実行速度を比較してみた。グラフまで作って比較しようと思ってたけど、あまりにも結果が明らかだったので、消してしまって手元にないけれども、Terminal.appから起動した方のMatlabの方が断トツに早かった。

処理中のCPU usageを見てみて分かったことは、このような単純なプログラムの場合、Terminal.appで起動したJava無しのMatlabは二つのCPUをフルに使っているということ。それに対して、普通のGUI版のMatlabはいつも通り、平均して一つ分(もちろん2つのCPUを使っているけれども、両方のCPU usageが同時に100%になることはなく、足して100%をちょっと越えるくらい)しか使っていない。

この結果に喜んで、.bash_profileをいじって、PATHの追加とexport DISPLAY=: 0.0とかいちいち起動の度にタイプしなくてもいい様にしてみたものの、肝心のoptimizationが関連してくるプログラムではTerminal.app版のMatlabでも、GUI版と似たような結果になってしまった。

残念。

やっぱり、Mathworksがアナウンスしているように、MatlabはJavaとかそういう表層的な部分ではなく、もうちょっと深いところでDual processorに対応してない気がする…

噂では、Intel Mac用にUniversal Binaryな(?)新しいMatlabが開発中らしいので、出来るコトならば、Intel Macだけじゃなくて、G5とかでも恩恵にあずかれるといいんだけど…Mac Proはむっちゃ速いらしいけど、さすがにそんなのを買う余裕は無いし。

自分用のメモ:
.bash_profileに
PATH=$PATH:/Applications/MATLAB_SV701/bin
export DISPLAY=:0.0
alias matlab=’matlab -nojvm -nosplash’
と書いておくとTerminal.appからの起動が楽。

Dynare is a a pre-processor and a collection of Matlab routines (also Scilab, Gauss, C++ versions are available) which solve non-linear DSGE models with forward looking variables.

Installing Dynare on Windows is pretty easy and descriptions are available in the manufal. However, it was not clear (at least to me) how to install on Mac OS X environment.

So here is my note on installation procesures.

  1. Download Dynare for Matlab [Linux] from here.
  2. Decompress the downloded file and put the folder (dynare_v3) somewhere you want, for example under /Applications/. It contains subfolders, doc, examples, and matlab.
  3. On Matlab, set the path to include the dynare/matlab folder.
  4. Since the original dynare_m is compiled for the Intel chip, without any changes, Dynare does not work. You will get some error like:
    ??? Error using ==> dynare
    /bin/bash: line 1: /Applications/dynare_v3/matlab/dynare_m: cannot execute binary file

    If you don’t want any hassles, you can use the ready-made dynare_m by Christophe Cahn, available from here. However, according to my rough experiments, my version of dynare_m seems faster than the ready-made parser. Actually, this is my first time to compile things. So I don’t have a clear idea why it is so. But maybe gcc optimizes the program for my G5 processor…

  5. If you are curious and willing to compile by yourself, download Parser source code from here and decompress it.
  6. Now we will compile dynare_m. To do this, you need XCode to be installed on your Mac, which enables you to use “make” command on the Terminal.app.
  7. With your favarite text editor, create the “makefile”. Here is what I used:
    all: dynare_m
    
    precompiler.o: precompiler.cc precompiler.hh d_ll.c d_tab.c
    	g++ -c precompiler.cc
    
    dynare_m: dynare_m.o d_tab.o d_ll.o precompiler.o
    	gcc -g -o dynare_m dynare_m.o d_tab.o d_ll.o precompiler.o -lstdc++
    
    dynare_m.o: dynare.c d.h d_tab.h
    	gcc -g -c dynare.c -o dynare_m.o -DMATLAB -Wall #-DDEBUG
    
    d_ll.o: d_ll.c d_tab.h
    	gcc -g -c d_ll.c
    
    d_tab.o: d_tab.c
    	gcc -g -c -DYYDEBUG=1 d_tab.c
    
    d_tab.c d_tab.h: d.y d.h
    	bison -d --verbose -od_tab.c d.y
    
    d_ll.c: dyn.l d_tab.h
    	flex -i -od_ll.c dyn.l
    

    I just modified the original makefile such that it works on PPC. Save it as makefile (without file extension) in parser.src.

  8. Open Terminal.app and move to the parser.src directory. On the command line, type
    make all

    then you will get your version of dynare_m in the same directory.

  9. Copy it to the matlab folder under the dynare directory.

After successfull installation, now you are ready for using Dynare. To use Dynare, you type on the command line in Matlab,

dynare('your_dynare_file.mod').

自分用のMatlabメモ。

頻繁に使う訳じゃないから、すぐ忘れるけど、使えると便利なコマンド:
findstr
strfind
strmatch

Follow

Get every new post delivered to your Inbox.