Skip to content

Instantly share code, notes, and snippets.

@pgalilea
Created April 12, 2021 21:14
Show Gist options
  • Save pgalilea/d507336ed69f0d5a9dfd77ac1d3ee7ab to your computer and use it in GitHub Desktop.
Save pgalilea/d507336ed69f0d5a9dfd77ac1d3ee7ab to your computer and use it in GitHub Desktop.
Embarrassingly parallel for loops
from math import sqrt
import multiprocessing
from joblib import Parallel, delayed
nj= max( 2, multiprocessing.cpu_count() )
Parallel(n_jobs=nj)( delayed(sqrt)(i ** 2) for i in range(10) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment