Vine Linux 2.5CR(PC/AT互換機)への GMT3.3.5 と netcdf-3.4 のインストール --- GMT本体には intel C compiler icc を使って速いバイナリを作りましょう --- 02/07/09 筧 ■注意すべき点 1. 海岸線などのデータの置き場所についての注意 /usr/localで GMT_full.tar.gz GMT_high.tar.gz GMT_share.tar.gz を展開すると、/usr/local/GMT3.3.5/share ではなく /usr/local/share に海岸線などのデータが置かれます。これらのファイルはサイズが大きく、ハードディス クを圧迫するので、異なるバージョンを混在させる環境で共有させることを意図している のかな、と想像しています。 しかし GMT3.3.5 はデフォルトでは、海岸線などのデータが /usr/local/GMT3.3.5/share に置かれていることを想定しています。なので、何もしないと、海岸線を描かせようとし ても、「海岸線のデータがあれへんで」と文句を言われてしまいます。具体的には pscoast: Error: No configuration file /usr/local/GMT3.3.5/share/coastline.conf available! と言われます。この warning はちょっと舌足らずで、補ってやると、「default では海 岸線のデータは/usr/local/GMT3.3.5/share/ に置くんやけど、そこにはあれへんで。ほ んで、別の場所に置くときは /usr/local/GMT3.3.5/share/coastline.conf っちゅう設定 ファイルに置き場所を書くことになっとんやけど、そのファイルもあれへんで」と言って いるのです。 そこで、 /usr/local/GMT3.3.5/share/coastline.conf というファイル中に(これは空っぽのファイルすら用意してないので、全く自分で作って やる必要があります)、 /usr/local/share と海岸線などのデータの置き場所を書いてやって、GMT に置き場所を知らせてやります。 これで大丈夫です。 もちろん海岸線などのデータを /usr/local/GMT3.3.5/share に置くか、symbolic link を張る、という手もあります。なお、海岸線のデータの置き場所は compile 時には必要 ない情報なので、この処置は compile がすんだあとに行っても大丈夫です。 以上の情報は、install_gmt で対話的にインストールしている時に、install_gmt が教 えてくれました。 2. compiler の選択 GMT 本体の compile 時には gcc よりも Intel の icc を使った方が、お絵描きに よっては劇的に速くなります。もっとも、試したサンプルによっては倍近くの速度差が つくものの、CPUの進歩によりそもそも絶対時間が短いので、試したサンプルでは icc のありがたみがイマイチわかりません(笑)。 詳しくは、最後のベンチマークを参照してください。 --------------------------------------------------------------------------- ■インストール作業の実際 1. ftpサイトからファイルをとってくる GMTを使うにはnetcdfというlibraryが必要です。 netcdfは、Vine2.5CRの場合、Vine Plus CDにrpmファイルが収録されていますので、 それをインストールすることができます。それが使えない環境の場合は、 ftp.eos.hokudai.ac.jp/pub/gmt/netcdf より netcdf-3.4.tar.Z をとってきましょう。 GMTは ftp.eos.hokudai.ac.jp/pub/gmt より GMT3.3.5_doc.tar.gz GMT3.3.5_progs.tar.gz GMT3.3.5_scripts.tar.gz GMT3.3.5_suppl.tar.gz GMT3.3.5_web.tar.gz GMT_full.tar.gz GMT_high.tar.gz GMT_share.tar.gz triangle.tar.gz install_gmt をとってきます。 GMT3.3.5 では日本語のフォントを使うことができますが、日本語フォントと英字 フォントをフォント指定をいちいちせずに混在させることを可能にする patch GMT3.3.5-j.patch が http://plaza26.mbn.or.jp/~higamasa/gmt/ にありますので、頂いてきます。作者の檜垣さんに感謝いたします。 2. netcdf-3.4 のインストール rpmファイルをインストールする場合は、rootになって # rpm -ivh netcdf-3.4-9vl1.i386.rpm てな感じであっさりインストールできます。この、Vine2.5CRのVine Plusに収録されてい る netcdf-3.4-9vl1.i386.rpm の場合、netcdfのlibraryとヘッダファイルは、それぞれ /usr/lib /usr/include にインストールされます。 sourceからcompileしてインストールする手順の方を、以下に示しておきます。 netcdf-3.4.tar.Z を展開すると INSTALL という文書があります。それをよく読みま しょう。install の手順と、各種 OS に対応した適切な compile option を使うための、 環境変数設定の実例が載っています。Linux の場合の設定例もちゃんと書いてありますの で、その記述に従います。以下に、Fortran compiler として g77 を使う場合と fort77 を使う場合の両方を書いておきます。この例では、root の shell は csh や tcsh など の C shell 系である、としています。 Solaris など他の OS でも INSTALL 中にある設定例に従えばちゃんと install できる と思います。 以下の例で、hogehoge には netcdf-3.4.tar.Z が置いてあるディレクトリ名が入りま す。 ・Fortran compiler として g77 を使う場合 # /bin/csh (← shellがcsh系でなければcshに変更) # # cd /usr/local # # gzip -cd hogehoge/netcdf-3.4.tar.Z | tar xvf - # # setenv CC /usr/bin/gcc # setenv CPPFLAGS -Df2cFortran # setenv CFLAGS -g # setenv FC /usr/bin/g77 # setenv FFLAGS "-g -Wno-globals" # setenv CXX /usr/bin/g++ # # cd netcdf-3.4/src # ./configure # make # make test (←エラーは出ませんでした) # make install # # cd /usr/local # ln -sf netcdf-3.4 netcdf (← これは趣味の問題です) ・Fortran compiler として fort77 を使う場合 # /bin/csh (← shellがcsh系でなければcshに変更) # # cd /usr/local # # gzip -cd hogehoge/netcdf-3.4.tar.Z | tar xvf - # # setenv CC /usr/bin/gcc # setenv CPPFLAGS -Df2cFortran # setenv CFLAGS -g # setenv FC /usr/bin/fort77 # setenv FFLAGS "-g -Nx400 -w" # setenv CXX /usr/bin/c++ # # ./configure # make # make test (←エラーは出ませんでした) # make install # # cd /usr/local # ln -sf netcdf-3.4 netcdf (←これは趣味の問題です) なお、上記の設定でnetcdf-3.5.0も問題なくcompileできましたので念のため記してお きます。 Fortran compilerとしてintel ifcを使った場合、netcdf-3.4とnetcdf-3.5.0のいずれ でも make test でボコボコにエラーが出てしまいました(実害があるかどうかは未確認 です)。 3. GMT3.3.5 のインストール ftp サイトに、対話的にインストールを行うための install_gmt というシェルスクリ プトが用意されています。それを使うことにします。 以下の例では、速いbinaryを作るため(最後のベンチマークを参照)、C compilerに intelのiccを使っています。install_gmtに「C compilerは何を使いますか?」と聞かれる 時に、intelのiccを指定するだけで、特別なことは何もせずともあっさりとcompileでき ました。 iccがない場合は、代わりにgccを使えば、できるbinaryはiccを使った場合に比べて遅 くなりますが、compileは問題なくできると思います。 以下の例で、hogehoge には *.tar.gz が置いてあるディレクトリ名が入ります。 # cd /usr/local # # tar xvzf hogehoge/GMT3.3.5_doc.tar.gz # tar xvzf hogehoge/GMT3.3.5_progs.tar.gz # tar xvzf hogehoge/GMT3.3.5_scripts.tar.gz # tar xvzf hogehoge/GMT3.3.5_suppl.tar.gz # tar xvzf hogehoge/GMT3.3.5_web.tar.gz # tar xvzf hogehoge/GMT_full.tar.gz # tar xvzf hogehoge/GMT_high.tar.gz # tar xvzf hogehoge/GMT_share.tar.gz # tar xvzf hogehoge/triangle.tar.gz # # cd GMT3.3.5 # patch -p0 < hogehoge/GMT3.3.5-j.patch # # cd .. # # cp hogehoge/install_gmt . # chmod +x install_gmt # # ./install_gmt ・ ・ (install_gmt の質問に答えながら対話的にインストール) ・ ・ # # echo /usr/local/share > GMT3.3.5/share/coastline.conf (↑ 海岸線などのデータの置き場所を教えてやります) --------------------------------------------------------------------------- ■ install_gmt との対話の中身 [kakehi@sc210 local]# ./install_gmt +++ Will expand *.bz2 files made with bzip2 +++ ==> Enter make utility to use [make]: ==> Enter print command to use [lpr]: ==> Have you installed netcdf version 3.4 or later? (y/n) [y]: ==> Enter directory with netcdf lib and include [/usr/local/netcdf-3.4]: /usr/local/netcdf (↑ netcdf のディレクトリ名を書きます) ==> Want to ftp and get any of the GMT version archives? (y/n) [y]: n ==> Where should GMT data be stored [/usr/local/GMT3.3.5/share]? : ==> Where should GMT executables be stored [/usr/local/GMT3.3.5/bin]? : ==> Where should GMT linkable libraries be stored [/usr/local/GMT3.3.5/lib]? : ==> Where should GMT include files be stored [/usr/local/GMT3.3.5/include]? : Unix man pages are usually stored in /usr/man/manX, where X is the relevant man section. This is usually l for local. Below, you will be asked for X and the /usr/man part; the /manX will be appended automatically, so do not answer /usr/man/manl ==> Where should GMT man pages be stored [/usr/local/GMT3.3.5/man]? : ==> Enter Man page section for GMT man pages (1-9,l) [l]: ==> Where should GMT www pages be stored [/usr/local/GMT3.3.5/www]? : At run-time, GMT uses the $GMTHOME environmental parameter to find /usr/local/GMT3.3.5/share. The name must not contain the trailing /share. You may want to override the default if users will see a different mount point or a symbolic link instead of a local directory. ==> Enter default GMTHOME selection [/usr/local/GMT3.3.5]? : The answer to the following question will modify the GMT defaults. (You can always change your mind by editing share/gmt.conf) ==> Do you prefer SI or US default values for GMT (s/u) [s]: The answer to the following question will modify the GMT defaults. (You can always change your mind later by using gmtset) PostScript (PS) files contain commands to set paper size, pick a specific paper tray, or ask for manual feed. Encapsulated PS files (EPS) are not intended for printers (but will print ok) and can be included in other documents. Both formats will preview on most previwers (out-of-date Sun pageview is an exception). ==> Do you prefer PS or EPS as default PostScript output (p/e) [p]: Building the GMT libraries as shared instead of static will reduce executable sizes considerably. GMT supports shared libraries under Linux, SunOS, Solaris, IRIX, HPUX, and FreeBSD. Under other systems you may have to manually configure macros and determine what specific options to use with ld. ==> Try to make and use shared libraries? (y/n) [n]: y If you have more than one C compiler you need to specify which, otherwise the default cc should work fine. ==> Enter name of C compiler (include path if not in search path) [cc]: /opt/intel/compiler60/ia32/bin/icc (↑ C compiler は intel icc を使います) GMT passes information about previous GMT commands onto later GMT commands via a hidden file (.gmtcommands). To avoid that this file is updated by more than one program at the same time (e.g., when connecting two or more GMT programs with pipes) we use POSIX advisory file locking on the file. Apparently, some versions of the Network File System (NFS) have not implemented file locking properly. We know this is the case with Linux pre-2.4 kernels when mounting NFS disks from a Unix server. If this is your case you should turn file locking OFF. ==> Use POSIX Advisory File Locking in GMT (y/n) [y]: y ==> Want to test GMT by running the 20 examples? (y/n) [y]: n ==> Delete all tar files after install? (y/n) [n]: n Normally, all coastline files are installed in GMT3.3.5/share. However, you can also place some of them in separate directories. These dirs must exist or you must have write permission to make them. If alternate directories are specified then a coastline.conf file will be kept in /usr/local/GMT3.3.5/share to contain the names of these directories. NOTE: Do not append the final subdirectory /share as that is done automatically! Set write privileges on all files in GMT3.3.5 ...Done ==> Install any of the supplemental programs? (y/n/a(ll)) [a]: y dbase: Extracting data from NGDC DEM and other grids ==> Install the dbase programs? (y/n) [y]: cps: Encoding and decoding of Complete PostScript files for archiving ==> Install the cps programs? (y/n) [y]: imgsrc: Extracting grids from global altimeter files (Sandwell/Smith) ==> Install the imgsrc programs? (y/n) [y]: meca: Plotting special symbols in seismology and geodesy ==> Install the meca programs? (y/n) [y]: mex: Matlab interface for reading/writing GMT grdfiles (REQUIRES MATLAB) ==> Install the mex programs? (y/n) [y]: n (← MATLAB は入っていないので) mgg: Programs for making, managing, and plotting MGD77 & .gmt data ==> Install the mgg programs? (y/n) [y]: misc: Make posters on laserwriters and create bit-patterns ==> Install the misc programs? (y/n) [y]: segyprogs: Plot SEGY seismic data files ==> Install the segyprogs programs? (y/n) [y]: spotter: Plate tectonic backtracking and hotspotting ==> Install the spotter programs? (y/n) [y]: x2sys: New (Generic) Track intersection (crossover) tools ==> Install the x2sys programs? (y/n) [y]: x_system: Old (MGG-specific) Track intersection (crossover) tools ==> Install the x_system programs? (y/n) [y]: xgrid: An X11-based graphical editor for netCDF-based .grd files ==> Install the xgrid programs? (y/n) [y]: ==> Want to print any of the GMT Documentation? (y/n) [n]: ---> Begin GMT 3.3.5 installation <--- ---> Run configure to create makegmt.macros and gmt_notposix.h creating cache ./config.cache checking host system type... i686-pc-linux-gnu checking target system type... i686-pc-linux-gnu checking build system type... i686-pc-linux-gnu checking for gcc... /opt/intel/compiler60/ia32/bin/icc checking whether the C compiler (/opt/intel/compiler60/ia32/bin/icc ) works... yes checking whether the C compiler (/opt/intel/compiler60/ia32/bin/icc ) is a cross-compiler... no ・ ・ (中略) ・ ・ if [ ! /usr/local/GMT3.3.5/www = /usr/local/GMT3.3.5/www ]; then \ mkdir -p /usr/local/GMT3.3.5/www; \ \cp -r www/gmt /usr/local/GMT3.3.5/www; \ else \ echo "Install www directory the same as distribution www directory - nothing copied"; \ fi Install www directory the same as distribution www directory - nothing copied All users should add /usr/local/GMT3.3.5/www/gmt/gmt_services.html to their browser bookmarks rm -f *.o gmt_nan_init for i in blockmean blockmedian blockmode filter1d fitcircle grdfilter gmtconvert gmtdefaults gmtmath gmtselect gmtset grd2cpt grd2xyz grdcontour grdcut grdclip grdedit grdfft grdgradient grdhisteq grdimage grdinfo grdlandmask grdmask grdtrack grdreformat grdmath grdpaste grdproject grdsample grdtrend grdvector grdview grdvolume makecpt mapproject minmax nearneighbor project psbasemap psclip pscoast pshistogram psimage psmask psrose psscale pstext pscontour pswiggle psxy psxyz sample1d spectrum1d splitxyz surface trend1d trend2d triangulate xyz2grd; do \ rm -f $i; \ done GMT installation complete. Remember to set these: ----------------------------------------------------------------------- setenv GMTHOME /usr/local/GMT3.3.5 set path = (/usr/local/GMT3.3.5/bin $path) Add /usr/local/GMT3.3.5/man to MANPATH: Add /usr/local/GMT3.3.5/www/gmt/gmt_services.html as browser bookmark ----------------------------------------------------------------------- install_gmt: Session parameters written to file install.par # --------------------------------------------------------------------------- ■ GMT のコマンドと man ファイルへの path を切っておく 僕は tcsh を使っていますので、.cshrc に # setting for GMT3.3.5 setenv GMTHOME /usr/local/GMT3.3.5 set path = ($path ${GMTHOME}/bin) setenv MANPATH ${MANPATH}:${GMTHOME}/man:/usr/local/netcdf/man と書いています。 ■ ベンチマーク:CPU と compiler による実行速度の違い CPU | compiler | OS | job01 job02 job15 job19 ---------------------------------------------------------------------------- Pentium4 1.50GHz | intel icc | Vine 2.5CR | 0.88 4.81 3.28 2.76 Pentium4 1.50GHz | gcc | Vine 2.5CR | 1.03 8.25 5.56 2.88 PentiumII 400MHz | gcc | Vine 2.0CR | 2.81 18.41 9.27 6.59 Alpha 21164A 500MHz | Compaq ccc | Vine 2.1CR | 3.55 13.06 8.63 5.15 ※compiler は GMT本体(GMT3.3.5)を compile するのに使った C compiler。 ※job01、job02、job15、job19 はそれぞれ GMT3.3.5 の example の 01、02、15、19。 ※数字は実時間(秒)。 ※数字は以下のようにして計った。 % time job02.csh 4.810u 0.110s 0:04.93 99.7% 0+0k 0+0io 4738pf+0w ↑ ↑ ↑ ユーザー時間 | | システム時間 | 実時間 ※Intel の Linux 用 C and C++ compiler(icc)、Fortran compiler(ifc) 、 Math Kernel Library (MKL) は、非商用目的に限り、Intel のホームページから無償 ダウンロードできます。 ※PentiumII 400MHz + gcc と Alpha 21164A 500MHz + Compaq ccc でそんなに差がない のがちょっとショック。