Skip to content
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

fix(raster): rework raster threads to work on osx #1180

Merged
merged 1 commit into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
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