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

add parallelization #43

Open
bnord opened this issue Apr 27, 2023 · 1 comment
Open

add parallelization #43

bnord opened this issue Apr 27, 2023 · 1 comment
Labels
enhancement New feature or request wishlist

Comments

@bnord
Copy link
Contributor

bnord commented Apr 27, 2023

No description provided.

@bnord bnord added the enhancement New feature or request label Apr 27, 2023
@bnord bnord added the wishlist label Jun 18, 2023
@bnord
Copy link
Contributor Author

bnord commented Jun 24, 2023

Notes and Ideas on how to implement parallelization

Likely key components

  1. map() function
  2. import multiprocessing as mppython
workers = mp.cpu_count() - 1
with mp.Pool(workers) as p:
  1. example:
import multiprocessing as mp
import random
import time

def some_calculations(x: float) -> float:
    time.sleep(.5)
    # some calculations are done
    return x**2

if __name__ == "__main__":
    x_list = [random.random() for _ in range(20)]
    with mp.Pool(4) as p:
        x_recalculated = p.map(some_calculations, x_list)
  1. joblib
  2. asyncio
  3. example:
import multiprocessing
from joblib import Parallel, delayed
from tqdm import tqdm

num_cores = multiprocessing.cpu_count()
inputs = tqdm(myList)

if __name__ == "__main__":
    processed_list = Parallel(n_jobs=num_cores)(delayed(myfunction)(i,parameters) for i in inputs)

Sources

  1. https://towardsdatascience.com/parallelization-in-python-the-easy-way-aa03ed04c209
  2. https://stackoverflow.com/questions/9786102/how-do-i-parallelize-a-simple-python-loop
  3. https://medium.com/@mjschillawski/quick-and-easy-parallelization-in-python-32cb9027e490

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wishlist
Projects
None yet
Development

No branches or pull requests

1 participant