I want to run a simple function across seperate cores on my computer. My computer has four cores.
To start with, a simple function:
def exp(x):
return x**2
now I want to give this function four separate numbers, and use a different core to apply the function so that the calculations are done in parallel.
I am trying like this:
import multiprocessing as mp
if __name__ == "__main__":
check = [1, 5, 6, 8]
pool = mp.Pool( mp.cpu_count())
results = pool.map(exp, check)
but this seems to execute and then it gets hung up, so I am not sure I am using pool correctly here.
I also tried this:
results = [pool.apply_async(cube, args=(x,)) for x in range(1,7)]
output = [p.get() for p in results]
but it gets hung on the last line again.
I am using ipython in ancondas spyder environment, this could also be why? Maybe I need to use ipythons parallel?
EDIT:
The answer to my problem was found here, multiprocessing in IPython console on Windows machine - if __name_ requirement