この文書では、Ubuntu24.04上でLBM(格子ボルツマン法)流体解析ツールOpenLBを活用する方法を紹介します。
ここでの説明は、以下の「LBM流体解析ツールOpenLBの活用【01:導入方法と動作確認】」の続きとしています。ご参考にしてください。
OpenLB公式サイト
https://www.openlb.net/
OpenLBの解析時間の確認
現状では、OpenLBをデフォルトの状態で利用しており、CPUで計算しています。そこで、WSL2条のUbuntu24.04を起動して、OpneLBの環境の名前を以下の通り変更します。
$ cd ~/OpenLBwork/
release-1.8.1 release-1.8.1.tar.gz
$ mv release-1.8.1 release-1.8.1-CPU
$ ls
release-1.8.1-CPU release-1.8.1.tar.gz
例題「examples/laminar/cylinder3d」の解析時間を、以下の手順で調べてみます。
$ cd release-1.8.1-CPU/
$ ls
AUTHORS.txt LICENSE build default.mixed.mk doc flake.lock script
CITATION.cff Makefile config default.mk examples flake.nix src
CONTRIBUTORS.txt README.md config.mk default.single.mk external rules.mk
$ cd examples/laminar/cylinder3d
$ ls
Makefile cylinder3d.cpp cylinder3d.fcstd cylinder3d.h cylinder3d.stl
$ make
make -C ../../../external
(省略:若干warningがでるかエラーで中断しなければ良しとする)
g++ cylinder3d.o -o cylinder3d -lolbcore -L../../../external/lib -lpthread -lz -ltinyxml2 -L../../../build/lib
$ ls
Makefile cylinder3d.cpp cylinder3d.fcstd cylinder3d.o
cylinder3d cylinder3d.d cylinder3d.h cylinder3d.stl
$ ./cylinder3d
[ThreadPool] Sucessfully initialized, numThreads=1
(上記で計算が1スレッドで行われるようです。あとは省略)
[Timer] ----------------Summary:Timer----------------
[Timer] measured time (rt) : 312.380s
[Timer] measured time (cpu): 310.273s
[Timer] average MLUPs : 23.622
[Timer] average MLUPps: 23.622
[Timer] ---------------------------------------------
$ ls
Makefile cylinder3d.cpp cylinder3d.fcstd cylinder3d.o tmp
cylinder3d cylinder3d.d cylinder3d.h cylinder3d.stl
以上により、Intel Corei7-13620H(2.4GHz)の1スレッドで、解析時間が312秒(約5分)となりました。
解析結果は、tmpディレクトリにあり、可視化データはvtkDataディレクトリの中にあります。WindowsのParaViewから、Ubuntuとの共有フォルダにアクセスして、cylinder3d.pvdを開くと可視化できます。
解析条件のデータは、cylinder3d.datにまとめられています。
GPUを活用したOpenLBの実行
以下の手順は、以下の資料「OpenLB technical report:Installing CUDA for OpenLB」を参考にしています。
以下では、GPU専用のOpenLBを準備するために、改めてパッケージファイル「」を展開し、ディレクトリ「release-1.8.1-GPU」を以下のように作ります。
$ cd ~/OpenLBwork/
$ ls
release-1.8.1-CPU release-1.8.1.tar.gz
$ tar xvfz release-1.8.1.tar.gz
release-1.8.1/
release-1.8.1/.clang-format
(省略)
release-1.8.1/src/utilities/utilities3D.hh
release-1.8.1/src/utilities/vectorHelpers.h
k$ ls
release-1.8.1 release-1.8.1-CPU release-1.8.1.tar.gz
$ mv release-1.8.1 release-1.8.1-GPU
$ ls
release-1.8.1-CPU release-1.8.1-GPU release-1.8.1.tar.gz
それでは、作成したGPU専用のOpenLBの設定を進めます。このディレクトリ「release-1.8.1-GPU」中の、ビルド設定ファイル「config.mk」がコンパイル方法を設定しており、標準の設定では、コンパイラgccなどを用いたCPU実行用のビルドとなっています。このファイルは念のために、config.mk.orgとして名称変更しておきます。
次に、GPU用の設定ファイルは、ディレクトリ「config」のなかにあり、「gpu_only.mk」がGPUのみを用いる基本となる設定ファイルです。これをコピーして、GPU専用のビルド設定ファイル「config.mk」を作ります。
具体的は手順は、以下の通りです。
$ ls
AUTHORS.txt LICENSE config default.mk examples flake.nix src
CITATION.cff Makefile config.mk default.single.mk external rules.mk
CONTRIBUTORS.txt README.md default.mixed.mk doc flake.lock script
$ mv config.mk config.mk.org
$ cp config/gpu_only.mk ./config.mk
この段階で、OpenLBのライブラリなどをコンパイルするので、コマンド「make」を実行します。
$ make
make CXX='nvcc' CC='nvcc' -C external (GPU用のnvccが利用されています)
(省略)
ar rc build/lib/libolbcore.a src/communication/mpiManager.o src/communication/ompManager.o src/core/olbInit.o src/core/expr.o src/io/ostreamManager.o
それでは、先ほど検証した例題「examples/laminar/cylinder3d」で、試してみるので、このディレクトリに移動してmakeして、エラーなく終了して実行形式「clyinder3d」ができたら、これを実行してみます。
$ clyinder3d
(省略)
[Timer] ----------------Summary:Timer----------------
[Timer] measured time (rt) : 98.230s
[Timer] measured time (cpu): 95.991s
[Timer] average MLUPs : 75.114
[Timer] average MLUPps: 75.114
[Timer] ---------------------------------------------
この解析は、NVIDIA GeForce RTX4060 Laptop GPUで実行したのですが、解析時間が約99秒であり、先ほどのGPUの312秒と比べると、3倍以上の高速化となっています。
格子ボルツマン法は、GPUによる高速化が期待される解法であり、期待通りの効果になっています。