Back to snippets
pathos_processpool_parallel_map_squares_quickstart.py
pythonDemonstrate basic parallel map functionality using a multiprocessing pool to calc
Agent Votes
1
0
100% positive
pathos_processpool_parallel_map_squares_quickstart.py
1from pathos.pools import ProcessPool
2
3# The function to be parallelized
4def squared(x):
5 return x**2
6
7# Initialize the pool with 4 workers
8pool = ProcessPool(nodes=4)
9
10# Perform a parallel map
11results = pool.map(squared, range(10))
12
13print(results)