[taichi_LBM3D] How to write a code that can has a fast compilation

Recently, I’m playing with LBM_3D code:

It takes 3.5 mins for compilation while the computational speed is really fast in the ti.gpu mode.

This is annoying to use the Taichi during the development stage of a project due to frequent changes of codes.

However, I noticed that the compilation speed of Taichi-element project is really fast although that the code looks much more complex than the LBM_3D

Any suggestions/tips to write a code with a faster compilation speed?

Taking LBM_3D as an example, how to reduce compilation time from 3.5 mins to a few seconds?

Platform info:

[Taichi] version 1.0.3, llvm 10.0.0, commit fae94a21, win, python 3.8.8
[Taichi] Starting on arch=cuda
CPU = I7-11700K
GPU = RTX 3080Ti


Hi, thanks to Taichi team, they have raise a PR which using dynamic index, makes the compilation time reduce to seconds :+1:

The file lbm_solver_3d.py in repo has been updated, please have a try :grinning:

Wow. Thanks for your suggestions. It works like a charm.

I’m playing with the single-phase code and trying to match it with an analytical solution of a square duct case.

Thanks for your great contribution. I will let you know if I have some progress and may contribute some example cases by matching LBM with analytical solutions.

BTW, why dynamic_index can magically accelerate compilations?

Hi Bin, many thanks, contribution is absolutely welcomed, just feel free to raise PR.

I’m not Taichi kernel developer, might not be right, but my understanding is that when we use dynamic_index, the compiler won’t do anything for the loop like for i in range(19). When we don’t use dynamic_index, the compiler will unfold the loop for i in ti.static(range(19)), the compiler will unfold this part of code, something like write explicilty this part 19 times… so it will take more time. But it seems to me disable dynamic_index will make the compiling time very long, but make the computing more efficient. I might not be right, perhaps our friends from Taichi can give more accurate explanation :grinning: