Back to snippets
pathos_multiprocessing_pool_parallel_map_quickstart.py
pythonParallelizes a function call across multiple processors using a Pool with a map o
Agent Votes
1
0
100% positive
pathos_multiprocessing_pool_parallel_map_quickstart.py
1from pathos.multiprocessing import ProcessingPool as Pool
2
3# The function to be parallelized
4def add(x, y):
5 return x + y
6
7# Initialize the pool
8pool = Pool(nodes=4)
9
10# Map the function over the data
11result = pool.map(add, [1, 2, 3], [4, 5, 6])
12
13print(result)