Taichi: [cpu] how to set number of threads?

Created on 21 Sep 2020  路  4Comments  路  Source: taichi-dev/taichi

Describe the bug
By default, Taichi seems to occupy all available cores, even for very small computations. This ends up being slower for small operations on machines with many cores. It also is problematic when it comes to running many Taichi processes in parallel on one machine. Is there any way to control the number of threads Taichi uses?

I see a quick mention of this here (https://taichi.readthedocs.io/en/stable/global_settings.html?highlight=threads#develop) but it appears to only relate to the test suite.

potential bug

All 4 comments

Fixed in #1867 (https://taichi.readthedocs.io/en/latest/debugging.html#serial-execution).
You may set ti.init(cpu_max_num_threads=n) to specify the max number of cores to be used.
Also note that we can actually prepending ti.parallelize(n) before parallel for-loops may only tweak a specific loop. This API is not so stable according to @yuanming-hu, however.

Thanks so much @archibate !

Glad to help!
Btw, how about the C backend? It now supports AdStack very well, please let me know if you have any trouble. Looking forward to hear from your success import into Julia.

That's awesome! I'm currently using PyCall.jl, and I'm close enough to a paper deadline at this point that I'm a little too risk-averse to switch just yet, but I'll def look into switching everything over after that!

Was this page helpful?
0 / 5 - 0 ratings