Skip to content

Add optional sequential mode for efficiency #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

John-194
Copy link
Contributor

Can I add an option to set sequential mode?
Sequential can be more efficient because it does not have the scheduler's overhead, but it depends on the dataset. Here are the results from my testing:

PARLAY_NUM_THREADS: Not set
  ordered point cloud:
     New threaded:   1.23 ms; CPU: ~650%;
     New sequential: 1.23 ms; CPU:  100%; efficiency: 6.5x
     Original:       1.23 ms; CPU: ~650%; 
  shuffled point cloud:
     New threaded:   1.46 ms; CPU: ~650%
     New sequential: 2.31 ms; CPU:  100%; efficiency: 4.1x
     Original:       1.45 ms; CPU: ~650%
     
PARLAY_NUM_THREADS: 1
  ordered point cloud:
     New threaded:   2.64 ms; CPU:  100%
     New sequential: 1.23 ms; CPU:  100%; efficiency: 2.1x
     Original:       2.64 ms; CPU:  100%
  shuffled point cloud:
     New threaded:   3.70 ms; CPU:  100%
     New sequential: 2.33 ms; CPU:  100%; efficiency: 1.6x
     Original:       3.69 ms; CPU:  100%

Using sequential mode is faster than setting PARLAY_NUM_THREADS to 1.
To make this work, I used a simple if check in the main loop, but the performance cost is within a margin of error - unnoticeable.

Usage:

import dbscan

# set sequential, disable threading
dbscan.set_sequential()
print("sequential:", dbscan.get_sequential())
dbscan.DBSCAN(points, eps=1.5, min_samples=15)

# enable threading again
dbscan.set_sequential(False) 
print("sequential:", dbscan.get_sequential())
dbscan.DBSCAN(points, eps=1.5, min_samples=15)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant