数理的手法を使いやすくするためのソフトウェア開発

科学技術計算とデータサイエンスについて

すごいプログラミング言語Formura で、たのしく科学シミュレーション?

科学シミュレーションのプログラミングは、 しばしば、退屈でめんどうなことがあります。

まず、退屈なのは、 ひとそろいの偏微分方程式で記述できるようなシミュレーションであっても、 長大で冗長なソースプログラムを書かねばならないことです。 そして、めんどうなのは、 微分方程式の意味とハードウェアアーキテクチャから どのように高速化すれば良いのかが明らかなときでも、 その機械的なチューニング作業をコンパイラではなく 人間がせねばならないことです。

新しいプログラミング言語

しかし、こうした冗長性と機械的作業を解消するための 研究も行われています ^1 ^2 ^3 ^4 ^6 ^7 。 こうした研究は理化学研究所でも進められおり ^5 、 その論文 ^7 は、 スーパーコンピューティングの国際会議"SC16"において、 ゴードンベル賞のファイナリストに選ばれました ^9

論文 ^6 ^7 は、新しいプログラミング言語 Formura について書かれています。 この言語は、 Fortran が初等的数式を実行形式のコードへと変換するように、 偏微分方程式をCのコードへと変換します。 そして、偏微分方程式で、例えば、菌類の地下ネットワークをシミュレートしようとすれば、 FortranやCでは長大なソースプログラムを書かねばなりませんが、 Formuraならたった20ステップ!ですみます。 また、そのチューニング作業を人間が行わずとも、 コンパイラによる自動チューニングだけで、 理研スパコンから1.2ペタプロップスの性能を引き出せるのです。

楽しいプログラミングだけですごいのか?

さて、こうした研究は科学シミュレーション分野を変えていくのでしょうか? たしかに、プログラミングから冗長性と機械的作業が減れば、 それだけプログラミングは楽しくなります。 しかし、楽しさに現実を変える力はあるのでしょうか? ちなみに、Formura論文の筆頭著者の村主さんは、 「すごいHaskell、たのしく学ぼう」 ^8 の訳者のひとりでもあり、 私はこの本を途中まで読んでみて、 関数型プログラミングには、シミュレーションプログラミングにつきものの冗長性と機械的作業を 解消し、プログラミングを楽しくできる可能性があると知りました。 ただ、Haskellのような関数型プログラミング言語やその楽しいプログラミングスタイルを、 自分の仕事である数理的手法のソフトウェア開発に使える可能性は小さいと判断し、 このすごい本を途中で読むのをやめてしまいました。

関数型プログラミングと領域特化言語はすごい

しかし、私の判断は間違っていたのかもしれません。 プログラミング言語Formura は、Haskellで実装された独立型の領域特化言語 ^10 ^12 であり、 関数型プログラミングの楽しさが科学シミュレーション開発のやり方を変えうることを示している と思います。 また、Formuraの研究の前に、Haskellで実装された埋込み型の領域特化言語 Paraiso ^4 も、 関数型プログラミングが、シミュレーションをプログラミングしやすくするだけでなく、 その計算速度をも向上させられることを 示しています。

やはり、関数型プログラミング、それによるメタ言語的抽象 ^11 と領域特化言語は素晴らしいです。


参考

^1:Klaus Iglberger, Georg Hager, Jan Treibig, and Ulrich Rüde, "Expression Templates Revisited: A Performance Analysis of Current Methodologies", SIAM J. Sci. Comput., 34(2), C42–C69.

^2:Pierre Esterie, Joel Falcou, Mathias Gaunard, Jean-Thierry Lapresté, Lionel Lacassagne, "The Numerical Template toolbox: A Modern C++ Design for Scientific Computing", Journal of Parallel and Distributed Computing, Elsevier, 2014, 74 (12), pp. 3240-3253.

^3:Christophe Prud'Homme, Vincent Chabannes, Vincent Doyeux, Mourad Ismail, Abdoulaye Samake, Gonçalo Pena, Cécile Daversin, Christophe Trophime, "Advances in Feel++: a domain specific embedded language in C++ for partial differential equations",Eccomas'12 - European Congress on Computational Methods in Applied Sciences and Engineering, Sep 2012, Vienna, Austria

^4: T. Muranushi, “Paraiso: an automated tuning framework for explicit solvers of partial differential equations,” Computational Science & Discovery, vol. 5, no. 1, p. 015003, 2012.

^5:理化学研究所プレスリリース「式が書ければ「京」が使える-高度なプログラムを自動生成できる新言語「Formura」を開発-」

^6:Takayuki Muranushi, Seiya Nishizawa, Hirofumi Tomita, Keigo Nitadori, Masaki Iwasawa, Yutaka Maruyama, Hisashi Yashiro, Yoshifumi Nakamura, Hideyuki Hotta, Junichiro Makino, Natsuki Hosono, Hikaru Inoue, "Automatic generation of efficient codes from mathematical descriptions of stencil computation", FHPC 2016: Proceedings of the 5th International Workshop on Functional High-Performance Computing

^7:Takayuki Muranushi, Seiya Nishizawa, Hirofumi Tomita, Keigo Nitadori, Masaki Iwasawa, Yutaka Maruyama, Hisashi Yashiro, Yoshifumi Nakamura, Hideyuki Hotta, Junichiro Makino, Natsuki Hosono, Hikaru Inoue, "Simulations of below-ground dynamics of fungi: 1.184 pflops attained by automated generation and autotuning of temporal blocking codes", SC '16 Proceedings of the International Conference for High Performance Computing, Networking, Storage and Analysis Article No. 3

^8:「すごいHaskell、たのしく学ぼう」Miran Lipovaca (著), 田中 英行 (翻訳), 村主崇行 (翻訳)

^9:Finalists Compete for Prestigious ACM Gordon Bell Prize in High Performance Computing

^10:M.Fowler and R.Parsons, "Domain-Specific Languages", Addison-Wesley, 2011.

^11:Structure and Interpretation of Computer Programs 2nd edition

^12:"Functional Programming for Domain-Specific Languages", Central European Functional Programming School Volume 8606 of the series Lecture Notes in Computer Science pp 1-28.