Skip to content

Commit

Permalink
Don't number of threads go below 4.
Browse files Browse the repository at this point in the history
  • Loading branch information
matham committed Jun 13, 2024
1 parent 48dabb2 commit 145ab63
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cellfinder/core/detect/filters/setup_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,12 @@ def n_torch_comp_threads(self) -> int:
This is less than `n_processes` because we account for thread
contention. Specifically it's limited by `MAX_TORCH_COMP_THREADS`.
"""
# Reserve batch_size cores for batch parallelization on CPU, 1 per
# plane. for GPU it doesn't matter either way because it doesn't use
# threads. Also reserve for data feeding thread and cell detection
n = max(1, self.n_processes - self.batch_size - 2)
# Reserve batch_size cores for batch multiprocess parallelization on
# CPU, 1 per plane. for GPU it doesn't matter either way because it
# doesn't use threads. Also reserve for data feeding thread and
# cell detection. Don't let it go below 4.
n = max(4, self.n_processes - self.batch_size - 2)
n = min(n, self.n_processes)
return min(n, MAX_TORCH_COMP_THREADS)

@property
Expand Down

0 comments on commit 145ab63

Please sign in to comment.