0
Hi, I’m trying to learn a little Python parallelization to parallelize some loops for. I’m using the joblib. However, the first example I made, available on the library’s own website, does not seem to have worked very well. The parallelized code is absurdly slower than the serial. I’ve changed the number of processors used according to the available machine, but nothing! Ah, by default the library works with multiprocessing, due to python GIL issue, etc...
from math import sqrt
from joblib import Parallel, delayed
import time
#Serial
start=time.time()
def f():
results = []
for i in range(100000):
results.append(sqrt(i ** 2))
return results
c=f()
print(time.time()-start)
0.07995438575744629
#Paralelo
start=time.time()
def g():
def _g(x):
return sqrt(x)
return Parallel(n_jobs=4)(delayed(_g)(i ** 2) for i in range(100000))
d=g()
print(time.time()-start)
3.191032648086548
Someone could give way to understand what is happening?