sdf icon indicating copy to clipboard operation
sdf copied to clipboard

Multithreading isn't doing multithreading.

Open Tyler-Barnes opened this issue 9 months ago • 1 comments

I am working on a complex fractal mesh and noticed that my threadripper is being woefully under-utilized.

Looking at the process manager I can see that the 48 workers reported in the console is not accurate, and it's running single threaded pretty much.

I see in the source there are details that outline a threadpool, but I'm worried that the Global Interpreter Lock is not being bypassed for true multithreading. And that the current object structure is not picklable.

I played around with trying to get it to work, and got something running. However, I understand that the resulting sdf object structure is pretty far removed from the native implementation.

Feel free to take this implementation for adaptation, or to try and get the current structure working with multithreading. I just wasn't able to get multiple threads actually running with the current source.

Here is the execution time for the default mandelbulb with 200**3 samples:

min -1.29456, -1.29456, -1.34752
max 1.29457, 1.29457, 1.34752
step 0.0131198, 0.0131198, 0.0131198
8822592 samples in 343 batches with 48 workers
  100% (343 of 343) [##############################] 0:03:59 0:00:00    
0 skipped, 226 empty, 117 nonempty
355942 triangles in 240.053 seconds

and then the execution time for the multithreaded implementation:

min -1.29456, -1.29456, -1.34752
max 1.29457, 1.29457, 1.34752
step 0.0131198, 0.0131198, 0.0131198
8822592 samples in 343 batches with 48 workers
  100% (343 of 343) [##############################] 0:00:07 0:00:00    
0 skipped, 226 empty, 117 nonempty
355942 triangles in 8.14684 seconds

Great project; I've been having a ball working with it. Thanks!

(can't upload .py extension for some reason; using .txt instead) Default_Mandelbulb.txt Multithreaded_Mandelbulb.txt

Tyler-Barnes avatar May 12 '25 00:05 Tyler-Barnes

I have implemented the fix in a branch. Multithreading Branch

I can't get openvdb to build the python module correctly on windows, so I did not convert the mesh.py file since I can't test it.

I can make a pull request if the object structure change is not too offensive to the original.

Basically just had to change the local f() function definitions into a class so it's picklable.

Tyler-Barnes avatar May 23 '25 02:05 Tyler-Barnes