Dec-05-2016, 01:53 PM
Many thanks, snippsat!
I've been able to reproduce the concurrent.futures.ProcessPoolExecutor example from the python manual.
Quod erat demonstrandum.
I've been able to reproduce the concurrent.futures.ProcessPoolExecutor example from the python manual.
import concurrent.futures import math PRIMES = [ 112272535095293, 112582705942171, 112272535095293, 115280095190773, 115797848077099, 1099726899285419] def is_prime(n): if n % 2 == 0: return False sqrt_n = int(math.floor(math.sqrt(n))) for i in range(3, sqrt_n + 1, 2): if n % i == 0: return False return True def main(): with concurrent.futures.ProcessPoolExecutor(max_workers= 2) as executor: for number, prime in zip(PRIMES, executor.map(is_prime, PRIMES)): print('%d is prime: %s' % (number, prime)) if __name__ == '__main__': main()However, concurrent futures computing on 2 cores as shown above is NOT significantly faster than serial processing.
for i in range(0, len(PRIMES)): print (PRIMES[i], is_prime(PRIMES[i]))Thus, the big head from calling a process (which is only necessary because of the GIL) makes parallel computing in Python unattractive until the GIL is removed.
Quod erat demonstrandum.