Skip to content

Commit

Permalink
Merge pull request #26 from jfbourgon/cpu-count
Browse files Browse the repository at this point in the history
improve cpu count
  • Loading branch information
mpelchat04 authored Oct 24, 2024
2 parents 88e6202 + e86cd1c commit ac51770
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions geo_inference/geo_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import gc
import re
import sys
import platform
import time
import torch
import pystac
Expand Down Expand Up @@ -182,8 +183,13 @@ async def async_run_inference(self,
"""

# configuring dask
num_workers = len(os.sched_getaffinity(0)) - 1 if workers == 0 else workers
# configuring dask with proper number of workers, alternatively we could also use os.getenv('SLURM_CPUS_PER_TASK')
if workers != 0:
num_workers = workers
elif 'linux' in platform.uname().system.lower():
num_workers = len(os.sched_getaffinity(0)) - 1
else:
num_workers = os.cpu_count() - 1
print(f"running dask with {num_workers} workers")
config.set(scheduler='threads', num_workers=num_workers)
config.set(pool=ThreadPool(num_workers))
Expand Down

0 comments on commit ac51770

Please sign in to comment.