GAMESS をビルドする (OpenBLAS 編)

ふと思い立って GAMESS をビルドして遊んだので記録を残そうと思います。基本的には GAMESS Installation Instructions for Linux に従いつつ、ビルドがコケたところを修正してまとめました。

参考 → mkl 編

環境

OS : Ubuntu 18.04 64bit
gcc : version 7.3.0
GAMESS : Feb 14, 2018 R1 Public Release
BLAS : OpenBlas v0.3.3

必要なソフトウェアをインストール

まず、ビルドのために fortran コンパイラと csh が必要なのでインストールします。

sudo apt-get install gfortran csh

c コンパイラも必要だったと思うので、gcc がインストールされていない場合はしましょう。gcc -v と打ってバージョン情報が出力されなければする必要があります。

sudo apt-get install build-essential

OpenBLAS のビルド

今回は OpenBLAS をビルドして使いました。v0.3.3 を使っていますが、新しいリリースがあればそっちを使うといいでしょう。試していませんが、apt-get でもインストールできるらしいです。面倒ならこっちでもいいとおもいます。

GAMESS にリンクして使う場合に限っていえば、スレッディング機能は無効にしたほうが無難だと思います。スレッディングを有効にしてビルドした場合でも環境変数で無効にできるので好きな方を選びましょう。

git clone https://github.com/xianyi/OpenBLAS.git
cd OpenBLAS
git checkout v0.3.3
make USE_THREAD=0
sudo make install PREFIX=/opt/OpenBLAS_NO_THREAD

GAMESS のビルド

GAMESS のソースファイル gamess-current.tar.gz は自分で入手しましょう。gamess-current.tar.gz~/Downloads にあり、ビルドは ~/gamess で行うものとしますが、違ったら適当に読み替えてください。

下の `whoami` はあなたのユーザーネームに置き換えてください。

cd ~/
tar xvf ~/Downloads/gamess-current.tar.gz
chown -R `whoami` gamess
chmod g-s gamess

OpenBLAS は公式にはサポートされていないので、configure の前に以下のどちらかのパッチを当てます。ここ を参考にして新しめの GAMESS に適用できるようにしました。

patch < ~/gamess_2018R1_openblas.diff
rm gamess_2018R1_openblas.diff

ここから対話的(!)な configure が始まります。

cd gamess
./config

This script asks a few questions, depending on your computer system, to set up compiler names, libraries, message passing libraries, and so forth.

You can quit at any time by pressing control-C, and then .

Please open a second window by logging into your target machine, in case this script asks you to 'type' a command to learn something about your system software situation. All such extra questions will use the word 'type' to indicate it is a command for the other window.

After the new window is open, please hit to go on.

<Enter> キーを押します。

GAMESS can compile on the following 32 bit or 64 bit machines:
axp64 - Alpha chip, native compiler, running Tru64 or Linux
cray-xt - Cray's massively parallel system, running CNL
cray-xc - Cray's XC40, with KNL nodes
hpux32 - HP PA-RISC chips (old models only), running HP-UX
hpux64 - HP Intel or PA-RISC chips, running HP-UX
ibm32 - IBM (old models only), running AIX
ibm64 - IBM, Power3 chip or newer, running AIX or Linux
ibm64-sp - IBM SP parallel system, running AIX
ibm-bg - IBM Blue Gene (Q model), these are 64 bit systems
linux32 - Linux (any 32 bit distribution), for x86 (old systems only)
linux64 - Linux (any 64 bit distribution), for x86_64 or ia64 chips,
using gfortran, ifort, or perhaps PGI compilers.
mac32 - Apple Mac, any chip, running OS X 10.4 or older
mac64 - Apple Mac, any chip, running OS X 10.5 or newer
sgi32 - Silicon Graphics Inc., MIPS chip only, running Irix
sgi64 - Silicon Graphics Inc., MIPS chip only, running Irix
sun32 - Sun ultraSPARC chips (old models only), running Solaris
sun64 - Sun ultraSPARC or Opteron chips, running Solaris
win32 - Windows 32-bit (Windows XP, Vista, 7, Compute Cluster, HPC Edition)
win64 - Windows 64-bit (Windows XP, Vista, 7, Compute Cluster, HPC Edition)
winazure - Windows Azure Cloud Platform running Windows 64-bit
type 'uname -a' to partially clarify your computer's flavor.
please enter your target machine name:

linux64 を入力して <Enter> を押します。

Where is the GAMESS software on your system?
A typical response might be /u1/mike/gamess,
most probably the correct answer is /opt/gamess

GAMESS directory? [/opt/gamess]

<Enter> キーを押します。

Please provide the name of the build locaation.
This may be the same location as the GAMESS directory.

GAMESS build directory? [/opt/gamess]

<Enter> キーを押します。

Please provide a version number for the GAMESS executable.
This will be used as the middle part of the binary's name,
for example: gamess.00.x

Version? [00]

<Enter> キーを押します。

Linux offers many choices for FORTRAN compilers, including the GNU
compiler suite's free compiler 'gfortran', usually included in
any Linux distribution. If gfortran is not installed, it can be
installed from your distribution media.

To check on installed GNU compilers, for RedHat/SUSE style Linux,
type 'rpm -aq | grep gcc' for both languages,
and for Debian/Ubuntu style Linux, it takes two commands
type 'dpkg -l | grep gcc'
type 'dpkg -l | grep gfortran'

There are also commercial compilers, namely Intel's 'ifort', and
Portland Group's 'pgfortran', and Pathscale's 'pathf90'.
The last two are not common, and aren't as well tested.

type 'which gfortran' to look for GNU's gfortran (a good choice),
type 'which ifort' to look for Intel's compiler (a good choice),
type 'which pgfortran' to look for Portland Group's compiler,
type 'which pathf90' to look for Pathscale's compiler.
Please enter your choice of FORTRAN:

gfortran と入力し、<Enter> キーを押します。

gfortran is very robust, so this is a wise choice.

Please type 'gfortran -dumpversion' or else 'gfortran -v' to
detect the version number of your gfortran.
This reply should be a string with at least two decimal points,
such as 4.1.2 or 4.6.1, or maybe even hyphens like 4.4.2-12.
The reply may be labeled as a 'gcc' version,
but it is really your gfortran version.

Please enter only the first decimal place, such as 4.6 or 4.8:

gfortran のバージョンを入力するところです。現在 (Sep. 2018) apt で降ってくる gfortran のバージョンは 7.3 だと思うのですが、残念ながら素直に 7.3 と入力するとエラーになります。その場合は、7.2 と入力して <Enter> しましょう。たぶん大丈夫です。GAMESS がアップデートされたらこの問題もなくなると思います。

hit to continue to the math library setup.

<Enter> キーを押します。

Linux distributions do not include a standard math library.

There are several reasonable add-on library choices,
MKL from Intel for 32 or 64 bit Linux (very fast)
ACML from AMD for 32 or 64 bit Linux (free)
ATLAS from www.rpmfind.net for 32 or 64 bit Linux (free)
PGI BLAS from Portland Group for 32 or 64 bit Linux
and one very unreasonable option, namely 'none', which will use
some slow FORTRAN routines supplied with GAMESS. Choosing 'none'
will run MP2 jobs 2x slower, or CCSD(T) jobs 5x slower.

Some typical places (but not the only ones) to find math libraries are
Type 'ls /opt/intel/mkl' to look for MKL
Type 'ls /opt/intel/Compiler/mkl' to look for MKL
Type 'ls /opt/intel/composerxe/mkl' to look for MKL
Type 'echo '$MKLROOT'"' to look for MKL"
Type 'ls -d /opt/acml' to look for ACML
Type 'ls -d /usr/local/acml
' to look for ACML
Type 'ls /usr/lib64/atlas' to look for Atlas
Type 'ls /opt/pgi/linux86-64//lib/ to look for libblas.a from PGI
Type 'ls /opt/pgi/osx86-64//lib/ to look for libblas.a from PGI

Enter your choice of 'mkl' or 'atlas' or 'acml' or 'pgiblas' or 'openblas' or 'none':

openblas と入力して <Enter> を押します。

Enter full path to OpenBLAS libraries (without 'lib' subdirectory):

/opt/OpenBLAS_NO_THREAD と入力し <Enter> を押します。

please hit to compile the GAMESS source code activator

<Enter> を押します。

please hit to set up your network for Linux clusters.

<Enter> を押します。

If you have a slow network, like Gigabit Ethernet (GE), or
if you have so few nodes you won't run extensively in parallel, or
if you have no MPI library installed, or
if you want a fail-safe compile/link and easy execution,
choose 'sockets'
to use good old reliable standard TCP/IP networking.

If you have an expensive but fast network like Infiniband (IB), and
if you have an MPI library correctly installed,
choose 'mpi'.

communication library ('sockets' or 'mpi')?

sockets と入力し <Enter> を押します。

64 bit Linux builds can attach a special LIBCCHEM code for fast
MP2 and CCSD(T) runs. The LIBCCHEM code can utilize nVIDIA GPUs,
through the CUDA libraries, if GPUs are available.
Usage of LIBCCHEM requires installation of HDF5 I/O software as well.
GAMESS+LIBCCHEM binaries are unable to run most of GAMESS computations,
and are a bit harder to create due to the additional CUDA/HDF5 software.
Therefore, the first time you run 'config', the best answer is 'no'!
If you decide to try LIBCCHEM later, just run this 'config' again.

Do you want to try LIBCCHEM? (yes/no):

no と入力して <Enter> を押します。これで configure の終了です。

GAMESS 独自の分散コンピューティング用ライブラリ (?) ddi をビルドします。

cd ddi
./compddi >& compddi.log
mv ddikick.x ..
cd ..

うまく行っていれば、compddi.log の最後の方に "DDI compilation ended successfully." という文があると思います。

いよいよ GAMESS をビルド (&リンク) します。少し時間がかかると思います。

./compall >& compall.log
./lked >& lked.log

最後に rungms スクリプトを編集します。63行目あたりに以下のような箇所があるので、

set TARGET=sockets
set SCR=/scr/$USER
set USERSCR=/u1/$USER/scr
set GMSPATH=/u1/mike/gamess

次のように編集します。

set TARGET=sockets
set SCR=/tmp
set USERSCR=/tmp
set GMSPATH=$HOME/gamess

SCR および、USERSCR は計算のための一時ファイルを置く場所らしいです。編集する行の上のコメントに簡単な説明があります。好きに決めて問題ないと思います。(/tmp はちょっと乱暴かもしれない…)

GMSPATH はビルドした gamess.00.x があるパスなので、ひとまずテストのために $HOME/gamess にします。

GAMESS のテスト

ビルドした GAMESS をテストします。

./runall 00

00 は GAMESS のバイナリを指定するための引数で gamess.00.x を使うという意味です。省略したら 00 になると思います。テストが終わったら、exam01.log から exam47.log までの47のファイルが出力されます。確認するためには

tests/standard/checktst

を実行して All 47 test results are correct! と表示されれば OK です!異常終了しているファイルがあれば内容をよく確認しましょう。

GAMESS のインストール

インストール先は /opt/gamess とします。GAMESS は Filesystem Hierarchy Standard に従っているソフトウェアではないようなので /usr/local 以下は適当なインストール先ではなさそうです。

まず、rungms ファイルを編集して GMSPATH を再度変更します。

set GMSPATH=/opt/gamess

ディレクトリごと移動して所有者を変更して終わりです。

cd ~/
sudo mv gamess /opt
cd /opt
chown -R root:root gamess

おまけ

.bashrc あたりで alias とか作ったら使いやすいと思います。

alias rungms=/opt/gamess/rungms

さらにキャッシュをクリアしてから実行してくれるようなスクリプト~/.local/bin/ に置いて使っています。

alias gamess=~/.local/bin/gamess.sh

GAMESS をビルドする (mkl 編)

ふと思い立って GAMESS をビルドして遊んだので記録を残そうと思います。基本的には GAMESS Installation Instructions for Linux に従いつつ、ビルドがコケたところを修正してまとめました。

参考 → OpenBLAS 編

環境

OS : Ubuntu 18.04 64bit
gcc : version 7.3.0
GAMESS : Feb 14, 2018 R1 Public Release
BLAS : mkl (intel-mkl-2018.3-051)

必要なソフトウェアをインストール

まず、ビルドのために fortran コンパイラと csh が必要なのでインストールします。

sudo apt-get install gfortran csh

c コンパイラも必要だったと思うので、gcc がインストールされていない場合はしましょう。gcc -v と打ってバージョン情報が出力されなければする必要があります。

sudo apt-get install build-essential

intel-mkl のインストール

intel-mkl パッケージをインストールします。intel による解説 に従って intel-mkl パッケージをインストールします。バージョンがいくつかありますが、よくわからないので一番新しい (2018/9月現在) ものを選びました。

wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB
apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB

sudo apt-get update

sudo apt-get intel-mkl-2018.3-051

/opt/intel 以下にインストールされるようです。

GAMESS のビルド

GAMESS のソースファイル gamess-current.tar.gz は自分で入手しましょう。gamess-current.tar.gz~/Downloads にあり、ビルドは ~/gamess で行うものとしますが、違ったら適当に読み替えてください。

下の `whoami` はあなたのユーザーネームに置き換えてください。

cd ~/
tar xvf ~/Downloads/gamess-current.tar.gz
chown -R `whoami` gamess
chmod g-s gamess

cd gamess
./config

ここから対話的(!)な configure が始まります。

This script asks a few questions, depending on your computer system, to set up compiler names, libraries, message passing libraries, and so forth.

You can quit at any time by pressing control-C, and then .

Please open a second window by logging into your target machine, in case this script asks you to 'type' a command to learn something about your system software situation. All such extra questions will use the word 'type' to indicate it is a command for the other window.

After the new window is open, please hit to go on.

<Enter> キーを押します。

GAMESS can compile on the following 32 bit or 64 bit machines:
axp64 - Alpha chip, native compiler, running Tru64 or Linux
cray-xt - Cray's massively parallel system, running CNL
cray-xc - Cray's XC40, with KNL nodes
hpux32 - HP PA-RISC chips (old models only), running HP-UX
hpux64 - HP Intel or PA-RISC chips, running HP-UX
ibm32 - IBM (old models only), running AIX
ibm64 - IBM, Power3 chip or newer, running AIX or Linux
ibm64-sp - IBM SP parallel system, running AIX
ibm-bg - IBM Blue Gene (Q model), these are 64 bit systems
linux32 - Linux (any 32 bit distribution), for x86 (old systems only)
linux64 - Linux (any 64 bit distribution), for x86_64 or ia64 chips,
using gfortran, ifort, or perhaps PGI compilers.
mac32 - Apple Mac, any chip, running OS X 10.4 or older
mac64 - Apple Mac, any chip, running OS X 10.5 or newer
sgi32 - Silicon Graphics Inc., MIPS chip only, running Irix
sgi64 - Silicon Graphics Inc., MIPS chip only, running Irix
sun32 - Sun ultraSPARC chips (old models only), running Solaris
sun64 - Sun ultraSPARC or Opteron chips, running Solaris
win32 - Windows 32-bit (Windows XP, Vista, 7, Compute Cluster, HPC Edition)
win64 - Windows 64-bit (Windows XP, Vista, 7, Compute Cluster, HPC Edition)
winazure - Windows Azure Cloud Platform running Windows 64-bit
type 'uname -a' to partially clarify your computer's flavor.
please enter your target machine name:

linux64 を入力して <Enter> を押します。

Where is the GAMESS software on your system?
A typical response might be /u1/mike/gamess,
most probably the correct answer is /opt/gamess

GAMESS directory? [/opt/gamess]

<Enter> キーを押します。

Please provide the name of the build locaation.
This may be the same location as the GAMESS directory.

GAMESS build directory? [/opt/gamess]

<Enter> キーを押します。

Please provide a version number for the GAMESS executable.
This will be used as the middle part of the binary's name,
for example: gamess.00.x

Version? [00]

<Enter> キーを押します。

Linux offers many choices for FORTRAN compilers, including the GNU
compiler suite's free compiler 'gfortran', usually included in
any Linux distribution. If gfortran is not installed, it can be
installed from your distribution media.

To check on installed GNU compilers, for RedHat/SUSE style Linux,
type 'rpm -aq | grep gcc' for both languages,
and for Debian/Ubuntu style Linux, it takes two commands
type 'dpkg -l | grep gcc'
type 'dpkg -l | grep gfortran'

There are also commercial compilers, namely Intel's 'ifort', and
Portland Group's 'pgfortran', and Pathscale's 'pathf90'.
The last two are not common, and aren't as well tested.

type 'which gfortran' to look for GNU's gfortran (a good choice),
type 'which ifort' to look for Intel's compiler (a good choice),
type 'which pgfortran' to look for Portland Group's compiler,
type 'which pathf90' to look for Pathscale's compiler.
Please enter your choice of FORTRAN:

gfortran と入力し、<Enter> キーを押します。

gfortran is very robust, so this is a wise choice.

Please type 'gfortran -dumpversion' or else 'gfortran -v' to
detect the version number of your gfortran.
This reply should be a string with at least two decimal points,
such as 4.1.2 or 4.6.1, or maybe even hyphens like 4.4.2-12.
The reply may be labeled as a 'gcc' version,
but it is really your gfortran version.

Please enter only the first decimal place, such as 4.6 or 4.8:

gfortran のバージョンを入力するところです。現在 (Sep. 2018) apt で降ってくる gfortran のバージョンは 7.3 だと思うのですが、残念ながら素直に 7.3 と入力するとエラーになります。その場合は、7.2 と入力して <Enter> しましょう。たぶん大丈夫です。GAMESS がアップデートされたらこの問題もなくなると思います。

hit to continue to the math library setup.

<Enter> キーを押します。

Linux distributions do not include a standard math library.

There are several reasonable add-on library choices,
MKL from Intel for 32 or 64 bit Linux (very fast)
ACML from AMD for 32 or 64 bit Linux (free)
ATLAS from www.rpmfind.net for 32 or 64 bit Linux (free)
PGI BLAS from Portland Group for 32 or 64 bit Linux
and one very unreasonable option, namely 'none', which will use
some slow FORTRAN routines supplied with GAMESS. Choosing 'none'
will run MP2 jobs 2x slower, or CCSD(T) jobs 5x slower.

Some typical places (but not the only ones) to find math libraries are
Type 'ls /opt/intel/mkl' to look for MKL
Type 'ls /opt/intel/Compiler/mkl' to look for MKL
Type 'ls /opt/intel/composerxe/mkl' to look for MKL
Type 'echo '$MKLROOT'"' to look for MKL"
Type 'ls -d /opt/acml' to look for ACML
Type 'ls -d /usr/local/acml
' to look for ACML
Type 'ls /usr/lib64/atlas' to look for Atlas
Type 'ls /opt/pgi/linux86-64//lib/ to look for libblas.a from PGI
Type 'ls /opt/pgi/osx86-64//lib/ to look for libblas.a from PGI

Enter your choice of 'mkl' or 'atlas' or 'acml' or 'pgiblas' or 'none':

mkl と入力して <Enter> を押します。

The exact MKL libraries needed depend on its version number.
First, where is your MKL software installed? For example
/opt/intel/mkl -or-
/opt/intel/Compiler/mkl -or-
/opt/intel/composerxe/mkl -or-
/your/sites/nonstandard/path/mkl

Found: Nothing.

Don't enter anything past the mkl subdirectory pathname.
MKL pathname?

/opt/intel/mkl と入力し <Enter> を押します。

Second, it is possible to have multiple version of MKL
installed, but often there is only one version installed.
Your system seems to have the following version(s):

benchmarks bin examples include interfaces lib tools

a) If the above output contains one or more version number,
enter the specific version you prefer, giving all decimals.
b) If the above output contains paths like 'bin' and 'lib',
enter the word 'proceed' next.
MKL version (or 'proceed')?

proceed と入力し <Enter> を押します。

please hit to compile the GAMESS source code activator

<Enter> を押します。

please hit to set up your network for Linux clusters.

<Enter> を押します。

If you have a slow network, like Gigabit Ethernet (GE), or
if you have so few nodes you won't run extensively in parallel, or
if you have no MPI library installed, or
if you want a fail-safe compile/link and easy execution,
choose 'sockets'
to use good old reliable standard TCP/IP networking.

If you have an expensive but fast network like Infiniband (IB), and
if you have an MPI library correctly installed,
choose 'mpi'.

communication library ('sockets' or 'mpi')?

sockets と入力し <Enter> を押します。

64 bit Linux builds can attach a special LIBCCHEM code for fast
MP2 and CCSD(T) runs. The LIBCCHEM code can utilize nVIDIA GPUs,
through the CUDA libraries, if GPUs are available.
Usage of LIBCCHEM requires installation of HDF5 I/O software as well.
GAMESS+LIBCCHEM binaries are unable to run most of GAMESS computations,
and are a bit harder to create due to the additional CUDA/HDF5 software.
Therefore, the first time you run 'config', the best answer is 'no'!
If you decide to try LIBCCHEM later, just run this 'config' again.

Do you want to try LIBCCHEM? (yes/no):

no と入力して <Enter> を押します。これで configure の終了です。

GAMESS 独自の分散コンピューティング用ライブラリ (?) ddi をビルドします。

cd ddi
./compddi >& compddi.log
mv ddikick.x ..
cd ..

うまく行っていれば、compddi.log の最後の方に "DDI compilation ended successfully." という文があると思います。

いよいよ GAMESS をビルド (&リンク) しますが、私の環境では少し修正しないとリンクで失敗しました。パッチ にしています。

patch < ~/gamess_2018R1_mkl.diff
rm gamess_2018R1_mkl.diff

ビルドには少し時間がかかると思います。

./compall >& compall.log
./lked >& lked.log

最後に rungms スクリプトを編集します。63行目あたりに以下のような箇所があるので、

set TARGET=sockets
set SCR=/scr/$USER
set USERSCR=/u1/$USER/scr
set GMSPATH=/u1/mike/gamess

次のように編集します。

set TARGET=sockets
set SCR=/tmp
set USERSCR=/tmp
set GMSPATH=$HOME/gamess

SCR および、USERSCR は計算のための一時ファイルを置く場所らしいです。編集する行の上のコメントに簡単な説明があります。好きに決めて問題ないと思います。(/tmp はちょっと乱暴かもしれない…)

GMSPATH はビルドした gamess.00.x があるパスなので、ひとまずテストのために $HOME/gamess にします。

GAMESS のテスト

ビルドした GAMESS をテストします。

./runall 00

00 は GAMESS のバイナリを指定するための引数で gamess.00.x を使うという意味です。省略したら 00 になると思います。テストが終わったら、exam01.log から exam47.log までの47のファイルが出力されます。確認するためには

tests/standard/checktst

を実行して All 47 test results are correct! と表示されれば OK です!異常終了しているファイルがあれば内容をよく確認しましょう。

GAMESS のインストール

インストール先は /opt/gamess とします。GAMESS は Filesystem Hierarchy Standard に従っているソフトウェアではないようなので /usr/local 以下は適当なインストール先ではなさそうです。

まず、rungms ファイルを編集して GMSPATH を再度変更します。

set GMSPATH=/opt/gamess

ディレクトリごと移動して所有者を変更して終わりです。

cd ~/
sudo mv gamess /opt
cd /opt
chown -R root:root gamess

おまけ

.bashrc あたりで alias とか作ったら使いやすいと思います。

alias rungms=/opt/gamess/rungms

さらにキャッシュをクリアしてから実行してくれるようなスクリプト~/.local/bin/ に置いて使っています。

alias gamess=~/.local/bin/gamess.sh

[ 解決済 ] Windows で Julia 1.0 を使う時の注意

※2018/9/6 追記

IJulia v1.11.0 および ZMQ.jl v1.0.0 のリリースによって以下の問題は解決したようです。これで安心して windows でも Julia v1.0 へ移行できますね!


Julia 言語のバージョン 1.0 がついにリリースされましたね🎉 待ち望んでいたのでとてもうれしいです。今現在は、まだ対応していないパッケージなどもあるのでしばらく混乱はあるかもしれませんが、漸次追いつくものと思います。バージョン 1.x.x の間は大きな機能変更はないものと思われるので、安心して Julia スクリプトを書くことができますね。

さて、早速 Julia 1.0 を試してみたのですがひとつ大きな問題にあたりました。IJulia パッケージを導入して jupyter notebook を起動したのですが、これがフリーズしてまともに動かないのです。(2018/8/29 現在) 調べたところ IJulia パッケージは既に対応を終えているのですが、どうやらこの問題は Windows でのみ起こるらしいです。

github.com

どうも、かなり厄介な問題らしくデバッグは難航している模様です。

回避策

元も子もないんですが、Windows ユーザーはしばらく v0.6.4 を使いましょう。該当の issue tracker にはいろいろこうしたらなおった!みたいな報告がありますが全部眉唾です。問題が再現したりしなかったりするのが最も厄介な点なので、報告する気持ちはわかりますが読み飛ばして開発者の調査を待ちましょう。ちなみに v0.7 でも同じ問題が発生するのでこれもダメです。

julia-vim に送った PR が取り込まれました

ちょっと前の話になりますが、 julia のドキュメントを vim 内に表示するための機能を追加する PR を julia-vim プラグインに送りました。

github.com

machakann.hatenablog.com

これが、ついに merge されてうれしいって話です。

使い方

まずは

julia-vim をインストールしましょう。お好きなプラグインマネージャを使うといいと思います。

カーソル下の関数・マクロを調べる

julia のソースコードを開きます。知りたい関数・マクロ名の上にカーソルを置いて、K キー (shift + k) を押します。そうするとウィンドウが分割され、ドキュメントが表示されます。通常のウィンドウなので、 :quit コマンドや :only コマンドなどで閉じることができます。

※ 2018/9/16 追記 : preview ウィンドウを使うようになった ので :pclose コマンドも使えます。

demo K

もし、~~~ command is not executable みたいな警告が出る場合は julia の実行ファイルが見つからない場合なので、 g:julia#doc#juliapath に実行ファイルへのパスを設定してください。

let g:julia#doc#juliapath = 'path/to/julia/executablefile'

基本的には、PATH が通っていれば必要ありません。また、Windows では PATH を通していなくとも %LOCALAPPDATA%\Julia-*\bin\julia.exe が存在すればそれを使います。

任意の関数・マクロを調べる

任意の関数・マクロを調べる機能も存在します。こちらには標準でのマッピングは存在しませんが、例えば、 ? キーにマッピングすると、REPL のヘルプモードのように使えます。 vimrc に次のように書きましょう、自動コマンドグループ名はお好みで。

augroup vimrc-julia
  autocmd FileType julia nmap <buffer> ? <Plug>(JuliaDocPrompt)
augroup END

あるいは ~/.vim/after/ftplugin/julia_mapping.vim (Windows なら %USERPROFILE%\vimfiles\after\ftplugin\julia_mapping.vim) あたりにマッピング設定だけ書いてもいいですね。

nmap <buffer> ? <Plug>(JuliaDocPrompt)

デモです。入力の途中で <Tab> キーを押すと補完候補を出してくれます。

demo <Plug>(JuliaDocPrompt)

Vim のターミナルウィンドウの文字色を設定する

はじめに

Vim 8.1 がリリースされましたね。目玉機能の一つとしてターミナルウィンドウが挙げられています。 Vim 8.0 から存在していましたが、ついに実験的機能ではなくなった、ということでしょうか。

f:id:machakann:20180519224618j:plain

実はこのターミナルウィンドウの文字色は、設定によって変更できます。しかし、これは :highlight コマンドとは異なる方法で管理され、しかも、適切に扱うにはある程度 Vim script の知識が必要になります。なので、ここに簡単にまとめておこうと思います。

ただし、注意する点として以下の機能を使うためには gvim を使用しているか、 'termguicolors' オプションが使用可能でオンになっている必要があります。

ユーザーによる設定

各文字色の指定には g:terminal_ansi_colors 変数を使います。これは十六要素のリストで、各要素は色指定のための文字列です。基本的には #RRGGBB 形式の七文字で指定します。

let g:terminal_ansi_colors = [
  \ "#0c0c0c", "#c50f1f", "#13a10e", "#c19c00",
  \ "#0037da", "#881798", "#3a96dd", "#cccccc",
  \ "#767676", "#e74856", "#16c60c", "#eadf84",
  \ "#3b78ff", "#b4009e", "#61d6d6", "#e8e8e8"
  \ ]

各要素は次のように各文字色に対応しています。

インデックス
0 black
1 dark red
2 dark green
3 brown
4 dark blue
5 dark magenta
6 dark cyan
7 light grey
8 dark grey
9 red
10 green
11 yellow
12 blue
13 magenta
14 cyan
15 white

つまり、このような対応になります。

let g:terminal_ansi_colors = [
  \ "black",     "dark red",     "dark green", "brown",
  \ "dark blue", "dark magenta", "dark cyan",  "light grey",
  \ "dark grey", "red",          "green",      "yellow",
  \ "blue",      "magenta",      "cyan",       "white"
  \ ]

理想的には、ユーザーは何も設定の必要がなく、各カラースキームが適切な色を設定するのが一番良いと思います。しかし、実際にはまだ新しい機能なので、まだすべてのカラースキームファイルが対応しているわけではありません。ひとまず使っているカラースキームで問題がある場合に g:terminal_ansi_colors を設定しましょう。

g:terminal_ansi_colors は vimrc で設定してもカラースキームが上書きしたり、削除したりします。なので、デフォルト設定として次のように設定すると安心です。

if has('terminal')
  function! s:set_default_ansi_colors() abort
    if exists('g:terminal_ansi_colors')
      return
    endif

    let g:terminal_ansi_colors = [
      \ "#0c0c0c", "#c50f1f", "#13a10e", "#c19c00",
      \ "#0037da", "#881798", "#3a96dd", "#cccccc",
      \ "#767676", "#e74856", "#16c60c", "#eadf84",
      \ "#3b78ff", "#b4009e", "#61d6d6", "#e8e8e8"
      \ ]
  endfunction
  call s:set_default_ansi_colors()

  augroup vimrc
    autocmd!
    autocmd ColorScheme * call s:set_default_ansi_colors()
  augroup END
endif

自動コマンドグループ名 (:help :augroup) は各自適切に設定してください。以下のリンクが参考になります。

vimrcアンチパターン · vim-jp/reading-vimrc Wiki · GitHub

おさらい autocmd/augroup - Qiita

【一人 vimrc Advent Calendar 2017】vimrc で安全に autocmd を設定する【3日目】 - Secret Garden(Instrumental)

カラースキームファイルによる設定

カラースキームを作ったら、その背景色にあう文字色を設定しましょう。

カラースキームの背景が黒に近い場合、デフォルトの色も見やすいと思います。これで十分なら、設定をクリアするだけで簡単です。

unlet! g:terminal_ansi_colors

もっとカラースキームにあった色を設定したい場合は、 g:terminal_ansi_colors を使って色を設定します。ただし、その色設定はカラースキームを後で変更した場合に邪魔かもしれない、という点に注意しましょう。ほかのカラースキームへ変更する時に設定をクリアするようにしてください。

if has('terminal') && exists('##ColorSchemePre')
  let g:terminal_ansi_colors = [
    \ "#0c0c0c", "#c50f1f", "#0f8d64", "#814d25",
    \ "#2353b1", "#881798", "#359fcf", "#cccccc",
    \ "#767676", "#e74856", "#88b422", "#cfa42b",
    \ "#6290ea", "#c800b2", "#44bfe0", "#e8e8e8"
    \ ]

  augroup mycolorscheme
    autocmd!
    autocmd ColorSchemePre * unlet! g:terminal_ansi_colors
    autocmd ColorSchemePre * autocmd! mycolorscheme
  augroup END
endif

自動コマンドグループ名 (:help :augroup) は各自適切に設定してください。

個人的には背景が暗い場合はデフォルトでも十分、背景が明るい場合はデフォルトだと厳しいなと感じます。

関連パッチ

patch 8.0.1685: can't set ANSI colors of a terminal window

patch 8.0.1777: cannot cleanup before loading another colorscheme

Vim の Julialang シンタックスハイライトについて

Vim の julialang 用シンタックスハイライト はなかなか控えめで渋くて好きです。 (Vim script 用のなんかは書いていると、ちょっと色が多すぎるな…と思ったりします。) ただ、括弧がハイライトされると視覚的に便利かなー、と思うので改造しようかと思っていたら、実はすでに構文グループが存在していた、ということを最近知りました。

github.com

なので括弧に色を付けたい場合は、~/.vim/after/syntax/julia.vim あたりに追記すればいいということですね。

highlight link juliaParDelim Delimiter

ハイライトグループ Delimiter は普通 Special にリンクされてると思います。 :help group-name

さらにコンマも色を付けたい場合は

highlight link juliaComma Delimiter

なんですけど、画面に色がつきすぎる感じもする。

julia-vim に Pull request を送りました

Julia も Vim で書いてるんですけど、結構な頻度でドキュメントを見たくなります。 Vim script を書く時の :help コマンドに慣れすぎているのでこのくらいの気軽さで Julia のドキュメントをひければいいのに、と思っていました。ので、書きました。

github.com

K キーでカーソル下のキーワードのドキュメントを開きます。また、 <Plug>(julia-doc-prompt)? あたりにマップしておけばREPLのそれのように使えます。

まだ、 merge されるかわかりませんが、されてほしいです。:terminal コマンドあるじゃん、と言われれば確かにそうなんですけど、:terminal 叩いてREPL立ち上げてって結構面倒じゃないですかね?改善案とかあれば件の issue にお願いします。

※ 2018/8/6 追記 Merge されました!めでたい


ここから、余談。本当は keywordprg オプションの設定だけで済ませたかったんだけど、 Julia の場合 @macrofuncname! が有効なキーワードなので iskeyword オプションも変更しなければならなかった。これだけならまだ提案してたかもしれないけど、 !bool と書くとこんどは真偽値の反転なので !iskeyword に含めるのはちょっと... ということで K キーにマッピングする形になってしまった。その点指摘されてるけど、いかんともしがたい。いい方法ないかな...

※ 2018/4/4 追記 紆余曲折の末、何とか 'keywordprg' オプションを使う形に持っていけました。