Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces support for custom thread pool. By allowing users to define and manage their own thread pools, we can provide greater flexibility and control over the multithreaded execution. This is particularly useful for users that need to integrate with existing thread management frameworks.
APIs (Applicable for Every Indices):
There are two implementation requirements for a custom thread pool to work on SVS:
size()
: This method should return the number of threads in the thread pool.parallel_for(std::function<void(size_t)> f, size_t n)
: This method should execute the tasks. Here,f(i)
represents a task on thei^th
partition, andn
represents the number of partitions that need to be executed.Example:
Changes:
set_num_threads()
at C++ level to eliminate the need of a resizable thread pool. For the python binding, we bindindex.num_threads = num_threads
toindex.set_threadpool(svs::threads::DefaultThreadPool(num_threads))
. This implementation will destroy the original thread pool and create the new one with the desirednum_threads
. The overhead will increase; however, this call should be made very rarely.set_num_threads()
withset_threadpool(svs::threads::DefaultThreadPool(num_threads)
due to the removal ofset_num_threads()
.Owing this thread pool reference wrapper is essentially the same as taking a reference of the thread pool.
ReferenceDataset
.CppAsyncThreadPool
andQueueThreadPool
for both example and testingThreadPoolReferenceWrapper
as a utility reference wrapper.run
withparallel_for
.parallel_for
is more meaningful and precise.FunctionRef
withstd::function<void(size_t)>
. As we exposeparallel_for
to users,std::function<void(size_t)>
is more general. I did not observe a significant increase in binary size, and the change does not impact performance.