Skip to content

Commit

Permalink
fix(raster): rework raster threads to work on osx (#1180)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhughes-usgs committed Aug 10, 2021
1 parent b511594 commit b893017
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 100 deletions.
191 changes: 108 additions & 83 deletions examples/Notebooks/flopy3_raster_intersection.ipynb

Large diffs are not rendered by default.

51 changes: 34 additions & 17 deletions flopy/utils/rasters.py
Expand Up @@ -440,23 +440,40 @@ def resample_to_grid(
if multithread:
q = queue.Queue()
container = threading.BoundedSemaphore(thread_pool)
threads = []
for node in range(ncpl):
t = threading.Thread(
target=self.__threaded_resampling,
args=(modelgrid, node, band, method, container, q),
)
threads.append(t)

for thread in threads:
thread.daemon = True
thread.start()
for thread in threads:
thread.join()

for _ in range(len(threads)):
node, val = q.get()
data[node] = val

# determine the number of thread pairs required to
# fill the grid
nthreadpairs = int(ncpl / thread_pool)
if ncpl % thread_pool != 0:
nthreadpairs += 1

# iterate over the tread pairs
for idx in range(nthreadpairs):
i0 = idx * thread_pool
nthreads = thread_pool
if i0 + thread_pool > ncpl:
nthreads = ncpl - i0
i1 = i0 + nthreads
threads = []
for node in range(i0, i1):
t = threading.Thread(
target=self.__threaded_resampling,
args=(modelgrid, node, band, method, container, q),
)
threads.append(t)

# start the threads
for thread in threads:
thread.daemon = True
thread.start()

# wait until all threads are terminated
for thread in threads:
thread.join()

for idx in range(nthreads):
node, val = q.get()
data[node] = val

else:
for node in range(ncpl):
Expand Down

0 comments on commit b893017

Please sign in to comment.