Musabbir Arrafi
Musabbir Arrafi

Reputation: 1885

Processing time increases with the number of Threads

I'm working with the pymeshlab library. I noticed a weird behavior with multithreading while using one of their filters generate_surface_reconstruction_screened_poisson which can be found here: https://pymeshlab.readthedocs.io/en/latest/filter_list.html#generate_surface_reconstruction_screened_poisson

What it basically does is, create a watertight surface from oriented point sets. For example, if there are holes or missing surfaces in your mesh, it will reconstruct the surface of that area using the adjacent point sets as a reference.

The left is the input and the right is the output:

enter image description here

For this filter, there is an argument threads that can be passed which essentially represents

threads : int = 16 (default)

Number Threads: Maximum number of threads that the reconstruction algorithm can use.

Now I have tried with different numbers of threads but it seems like the best performance in terms of execution time I'm getting while setting the number of threads to two. Increasing or decreasing the number of threads just increases the time elapsed in the execution of the filter. Here's my implementation:

import pymeshlab
import time

for thread_number in [1, 2, 4, 8, 16]:
    ms = pymeshlab.MeshSet()
    ms.load_new_mesh('FullHead.obj')

    start_time = time.perf_counter()
    ms.apply_filter('generate_surface_reconstruction_screened_poisson', visiblelayer=True, preclean=True, threads=thread_number)
    elapsed_time = time.perf_counter() - start_time
    print(f"time taken for running with {thread_number} threads: {elapsed_time} seconds\n")
    
    ms.save_current_mesh(f'recons_output/{thread_number}_reconstructed_mesh.obj')

Output:

time taken for running with 1 threads: 7.891609824000625 seconds

time taken for running with 2 threads: 7.006016070998157 seconds

time taken for running with 4 threads: 10.419608506999793 seconds

time taken for running with 8 threads: 17.781056181996973 seconds

time taken for running with 16 threads: 31.617957017999288 seconds

This behavior seems quite strange to me. The number of cores and available threads in my CPU is 4. Here's my CPU specs: https://www.intel.com/content/www/us/en/products/sku/97456/intel-core-i57300hq-processor-6m-cache-up-to-3-50-ghz/specifications.html

Shouldn't increasing the number of threads make the execution faster for at least the number of threads set to four? Also, let me know if there is any other way to achieve faster execution for surface reconstruction with the screened-poisson algorithm.

P.S. If you want to try in your system, here's the FullHead.obj file uploaded in Google Drive: https://drive.google.com/file/d/1XjRq1HFyXvogDTSQtiKD2raIgvof5Tkj/view?usp=drive_link

You can find similar results on google-colab too: https://colab.research.google.com/drive/1D-44yptui8tVCGU286y6Pi09yi0r4-Ce?usp=sharing

Upvotes: 1

Views: 151

Answers (0)

Related Questions