Created
May 10, 2021 21:03
-
-
Save DougAF/9fec79848f3bccb77f05c281b29eb838 to your computer and use it in GitHub Desktop.
batch_multiprocess.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def batch_multiprocess(inputs): | |
""" | |
Compute multiprocess with one batch per process. | |
""" | |
len_inputs = len(inputs) | |
n_batches = multiprocessing.cpu_count() | |
batch_size = len_inputs // n_batches | |
batches = [] | |
for i in range(n_batches): | |
start = batch_size * i | |
end = (i + 1) * batch_size if i != n_batches - 1 else len_inputs | |
batch = inputs[start:end] | |
batches.append(batch) | |
return Parallel(n_jobs=-1)( | |
delayed(single_thread.__wrapped__)(batch) for batch in batches | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment