I am trying to parallelize a simple function in python as follows:
import numpy as np
import math
import concurrent.futures
def f(x):
return x * math.sin(x) + x * x * math.cos(x)
xs = np.random.normal(0, 1, 100000)
#This takes about a second
ans1 = map(f, xs)
#This ran about 30 minutes before I gave up
with concurrent.futures.ProcessPoolExecutor() as executor:
ans2 = executor.map(f, xs)
I understand that this problem is probably too small for parallelization to actually be effective, but I expected the parallelized version of this to take on the order of seconds, not 30+ minutes. What is going wrong here?