Phantom-GRAPE graph drawing HOWTO (2017/11/09)


nautilus

そういえばnautilusはいぜんはリモートホストのファイルシステムなどをいろいろとマウントできたりしたものだが,最近そのへんどうなっておるのか.

と思ってちょっと調べたのですが,そもそも最近の版はアドレスバーそのものが存在せず,リモホを見に行く指令をそもそも出しようがないのである.どうなってんの?というところからいろいろ調べました.知ってればどうってことない話で,まず

ctrl-L でアドレス窓が生えます.そこに sftp://誰@どこ/

みたいな事を書けばそれでアクセスできるようになりました.なんじゃそりゃ.クソ簡単じゃねーの.

リモートホストのファイルのプレビューは出ないのでしょうか?まぁいいや.(設定で出せるようになります)

emacs fonts

いつしかemacsのフォントが文字によって幅の違うものが出るようになっていて,まぁこれはこれで意味もあることなのだろうが,やっぱし非常に使いにくいと思ったので,我慢せずに設定した.

migmix font という文字をいれて,これをemacsの既定のフォントに設定しただけですが,i や l が幅が狭かったりすると見にくくて本当にイラっとするので設定してよかったと思う.端末のフォントもこれにした.昔のX端末の味わいが復活して非常に気分が良い.仕事する気になる.

2017/02/19

word2vector関連案件などをやっていました.

みごと納品しました.つかれました.ぎっくぎr腰になりました.ギックリ.

ネイピア数再訪

どっかで, あたりの確率が 1/n のクジが n 回連続で外れる確率が,どれもだいたい同じで不思議だ!みたいな記事をみかけた.

そこで,外れる確率を実際に計算してプロットしてみました.どうもだいたい同じ値になるどころか,特定の値に収束しているっぽいですね.なんで?

じつはこの収束先の値は理論的にわかっていて,それはおよそ 0.37 です.そうですね 1/e です.

そうとわかれば高校のときの算数を思い出せば無事に計算できると思います. e の定義は

$$ \lim_{n\rightarrow \infty} \big(1+\frac{1}{n}\big)^n $$

が使いやすいんですかね.

お茶の時間とみかんと実験について

お茶にミルクを入れるのとミルクにお茶をいれるのは同じか違うかという話があって,これが違うわけですが,揉んだみかんは揉んでないみかんと味が違うか,という話が最近あったんですが,どう思います?

これが,やっぱり違うんですね!本当にこの仕事はおもしろいですね!!

nvidia

nvidia-driver をインストールする.軽い気持ちで始めたらクソはまって大変だった.

基本的には apt-get install nvidia-detect してこのコマンドを実行しその結果を見て apt-get install nvidia-driver などすればいいのだが,途中でエラーになってもあまりそのへんがうまくつくられてなくて普通にインストールされたことになってしまうので,原因がわからないのである.

Xなどが一切動かず,どうもカーネルモジュールがロードされていない(そのへんは lsmod すればすぐにわかる)ので,様子をみるために手でやってみると

  modprobe nvidia
  modprobe: FATAL: Module nvidia-current not found in directory /lib/modules/4.12.0-1-amd64
  modprobe: ERROR: ../libkmod/libkmod-module.c:979 command_do() Error running install command for nvidia
  modprobe: ERROR: could not insert 'nvidia': Operation not permitted

このざまななので,どうもものがはいってないぽいのですがどうなっているのでしょうか?

しらべたところ

  root@kibitaki:/usr/src/nvidia-current-375.82#dpkg-reconfigure --force nvidia-kernel-dkms   

  ------------------------------
  Deleting module version: 375.82
  completely from the DKMS tree.
  ------------------------------
  Done.
  Loading new nvidia-current-375.82 DKMS files...
  Building for 4.12.0-1-amd64
  Module build for kernel 4.12.0-1-amd64 was skipped since the
  kernel headers for this kernel does not seem to be installed.

こういうことがわかりました.動いているカーネル4.12 だけど入ってるソースが4.13だった. そこでimageも4.13にして再起動し, 既に手元にある nvidia-kernel-dkms パッケージを reconfigure します

  pkg-reconfigure --force nvidia-kernel-dkms

  -------- Uninstall Beginning --------
  Module:  nvidia-current
  Version: 375.82
  Kernel:  4.13.0-1-amd64 (x86_64)
  -------------------------------------

  Status: Before uninstall, this module version was ACTIVE on this kernel.

  nvidia-current.ko:
  - Uninstallation
  - Deleting from: /lib/modules/4.13.0-1-amd64/updates/dkms/
  中略
  depmod...

  DKMS: install completed.

お.できたっぽいですね.以下確認

  nvidia-smi                       
  Sun Oct 15 22:15:28 2017       
  +-----------------------------------------------------------------------------+
  | NVIDIA-SMI 375.82                 Driver Version: 375.82                    |
  |-------------------------------+----------------------+----------------------+
  | GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
  | Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
  |===============================+======================+======================|
  |   0  GeForce GTX 108...  Off  | 0000:03:00.0      On |                  N/A |
  | 29%   30C    P8    10W / 250W |     64MiB / 11163MiB |      0%      Default |
  +-------------------------------+----------------------+----------------------+
  
  +-----------------------------------------------------------------------------+
  | Processes:                                                       GPU Memory |
  |  GPU       PID  Type  Process name                               Usage      |
  |=============================================================================|
  |    0       759    G   /usr/lib/xorg/Xorg                              40MiB |
  |    0       792    G   /usr/bin/gnome-shell                            21MiB |
  +-----------------------------------------------------------------------------+
  root@kibitaki:~yuji#

既にXも動いてるぽいのでホストを置いてある部屋に行ってみたらすべてが無事に動いていた.

なお,このためだけにフルHD解像度の新しいディスプレイを買いました.HDMI接続ってやつです.

2017/10/21

先月に投稿した論文が不採録となり,まぁこれも良いチャンスだと思って久々に dist-upgrade するかということになり間違ってpinしたままapt-get dist-upgrade したらいろいろ消えてloginできなくなり,しかもwifiのリンクも消滅するなどして一旦詰んだ. おちついて再起動したところ single user mode ならコンソールからログインできるので,そこからおかしいところを直していくことになった.

ネットワーク接続はusbにイーサネットをつなぐアダプタを持っていたので(ここでもむっちの教えが生きた!)有線で接続して dhclient したらつながるようになった.

コンソールから作業するとしてもコンソールの字がちっこすぎて,小文字のlと1などの区別がほぼつかないのでなかなか作業が苦しい. そこで,むっちにおしえてもらって

   dpkg-reconfigure console-setup
 

すると文字がでかくなった.これなら戦える.結局, apt --fix-ナントカ install で最初にエラーになってるパッケージの原因を発見してこれを手で直したらすべてがインストールされ元に戻り wifi も復活した.

これでとりあえず仕事はできるようになったが,ファイルマネージャがおかしくて画像などのサムネイルが表示されない状態がしばらく続いていた.これもいいかげん便利が悪いので今日あたり直すか,と根性いれて調査した.サムネイルのキャッシュ

/home/yuji/.cache/thumbnails/

以下を一旦消せ,などの情報があるがいずれも関係なく,更に調査したところ

   /usr/share/thumbnailers
  

という場所に各種サムネイル生成のための設定が存在し, そこに gdk-pixbuf-thumbnailer どうたらいうものが無いことがわかった.おそらく先日のどさくさで消えたのだろう. gdk-pixbuf-thumbnailer というコマンドがそもそも存在しない.これを持っているパケジを探したら

  libgdk-pixbuf2.0-bin
   

にゆきあたったのでインストールしたら復活した. ちなみに動画のサムネイラはtotemに含まれているらしく,これもインストールしなおしたら治った.しかし, svg は素のアイコンのままである.あ.いま治った. librsvg2-common を dpkg-reconfigre したら thumbnailer ができ,キャッシュを消したら直った.

chromiumが巨大な問題

表示がばかでかくてまったく難儀していたのだが,パッケージ "chromium" に含まれる

/usr/share/applications/chromium.desktop

のなかの次のエントリをこのようなオプションをつけて起動することにしたら(下は高解像ディスプレイにおける2倍拡大の場合)

Exec=/usr/bin/chromium --force-device-scale-factor=2.0 %U

直ったのでよかった.

Phantom-GRAPE and graph layout

2-branching Bethe lattice of depth 16 drawn by the software combination of this article. The root node in magenta, leaf in red, in full spectrum according to the depth. The size gets smaller from the root node as well.

Phantom-GRAPE is what? In short, it is a software that accelerates numerical computation by using standard CPU features which is unknown to common compilers. Standard CPU means you need no special hardware like GRAPE board nor GPU to use this method.

For details see this paper. Phantom-GRAPE: numerical software library to accelerate collisionless N-body simulation with SIMD instruction set on x86 architecture According this paper, it is

numerical software library for collisionless N-body simulations named "Phantom-GRAPE" which highly accelerates force calculations among particles by use of a new SIMD instruction set extension to the x86 architecture, AVX, an enhanced version of SSE.

In this article I will introduce you to use it on standard Linux host (which means Debian installed AMD64 arch PC) step by step to use it for large scale graph layout.

Before you begin you have to check following points.

get GRAPE software package from kfcr.jp

unpack the archive and run scripts/install by typing

csh ./scripts/install

This will do some preparation for you. Note you are typing this command from the root directory of the extracted package (otherwise it will not work). It will ask you several questions. Choose your options by answering them. The number of cores can be seen by looking at /proc/cpuinfo

To use it from my ngraph, build Nbody.so by compiling libvtc-ruby.c and link libvtc.a which is found in grape software package "sample/vtc/" directory. It takes several further steps ahead.

As Ruby links things dynamically, you should build '.so', which is basically a position independent code instead of ".a". It is generated by giving -fPIC option to the compiler. Add it to the CFLAGS of Makefiles of pg5/common.mk and sample/vtc/Makefile (Makefile of libvtc-ruby generated by extconf.rb already has this option).

Change JMEMSIZE constant of phantom_g5.c and phantom_g5mc.c in pg5/ directory to meet your usage. It designates the upper limit of the particle number. I've changed it from 2^16 to 2^23 (which is about 8M).

Edit sample/vtc/force_g7.c to use OpenMP by changing #if condition of line 267. The file has several different versions of get_force_grape functions, and non-OpenMP version is used unless you configure it explicitly. Change the condition phrase (which is simply "0'; FALSE in the world of C programming language) to 1.

make again (here "make" is a command on unix host, not general verb) in pg5/ and sample/vtc/ to generate position independent native code objects. Adjust makefiles to avoid error and build pg5/libpg55.a linked libvtc.a .

Build libvtc-ruby. It will produce Nbody.so. Put it in some place of Ruby $LOAD_PATH

Require Ngraph and build some network(or "graph" if you are a mathematician) on Ruby. You will have to optimize tree_vector_param of Nbody class object. It can be set on-the-fly as follows, let g be some Ngraph instance, then

g.nbody.tree_vector_param= 1000

will set the parameter to 1000. This parameter gives the balance between divide-conquer step and SIMD pipeline step of Barnes-Hut hierarchical algorithm execution. Increasing it will give more weight to SIMD pipeline process and less divide-conquer. Adjust it so that "force" method runs most quickly. Calculation of 1M particles will finish within 5 seconds on recent CPU if you adjust it well.

example plot from run with different parameters on Intel Corei7-6800K with 3.4GHz (3.8G upper limit) tested with 1M particles. Horizontal axis shows the tree_vector_param (this corresponds to ncrit in the vtc source) and vertical for elapsed time.

The above plot shows how it went on my laptop (Intel Core i7-6560U CPU @ 3.2GHz with 16G RAM). Horizontal axis for particle size(upto 8M) and vertical for time in seconds to go through a single loop. It shows 1M sized network drawing will be finished within 10 minutes (we can go more than 300 loops within this interval) on plain common laptop. I have to say it is a awesome performance. The core temperature reaches 80degrees during the computation. Beware not to cover and block the cooling.

Acknowledgment: Thank you very much Kawai-san for your help to this library, parameter tuning and OpenMP support; after all, everything.


記事リストへ