I am trying to use parallel computation package joblib in python. I can execute the following example and get the result
Parallel(n_jobs=8)(delayed(sqrt)(i) for i in range(10))
However, the following code does not work out.
from joblib import Parallel, delayed
def f(x):
return 1
def y(x):
result=Parallel(n_jobs=8)(delayed(x)(i) for i in range(10))
return result
if __name__ == '__main__':
print y(f)
when I run the above code, it keeps running forever without generating any result or message.
Can anyone figure out the reason for this strange behavior(I am using windows)? thanks
The problem is in this line of code:
result=Parallel(n_jobs=8)(delayed(x)(i) for i in range(10))
It should instead be:
result=Parallel(n_jobs=8)(delayed(f)(i) for i in range(10))
You have to pass the function name to delayed, just like you did with the first example using the sqrt.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With