Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Python

Idiom #30 Parallelize execution of 1000 independent tasks

Launch the concurrent execution of the procedure f with parameter i from 1 to 1000.
Tasks are independent and f(i) doesn't return any value.
Tasks need not run all at the same time, so you may use a pool.

from multiprocessing import Pool
pool = Pool()
for i in range(1, 1001):
	pool.apply_async(f, [i])
(dorun (pmap f (range 1 1001)))

New implementation...