I'm trying to parallelize a simulation that is replicated many times using pathos.multiprocessing
. However, the map
function keeps returning the same value for each iteration. Perhaps my understanding of map
is incorrect? This is what my code looks like:
def simulate(_):
# simulation occurs here
return result
reps = 10
# without parallelization
serial_result = []
for _ in range(reps):
result.append(simulate())
print(result)
# prints [5.6, 5.8, 4.2, 5.6, 5.8, 5.0, 12.4, 5.8, 4.4, 4.6]
# with parallelization
from pathos.multiprocessing import ProcessingPool as Pool
pool = Pool(10)
parallel_result = pool.map(simulate, range(reps))
print(parallel_result)
# prints [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]