# Author: Mike McKerns (mmckerns @caltech and @uqfoundation) # Copyright (c) 1997-2015 California Institute of Technology. # License: 3-clause BSD. The full license text is available at: # - http://trac.mystic.cacr.caltech.edu/project/pathos/browser/pathos/LICENSE def host(id): import socket return "Rank: %d -- %s" % (id, socket.gethostname()) if __name__ == '__main__': from pathos.pools import ThreadPool as TPool tpool = TPool() print "Evaluate 10 items on 1 thread" tpool.nthreads = 1 res3 = tpool.map(host, range(10)) print tpool print '\n'.join(res3) print '' print "Evaluate 10 items on 2 threads" tpool.nthreads = 2 res5 = tpool.map(host, range(10)) print tpool print '\n'.join(res5) print '' print "Evaluate 10 items on ? threads" tpool.nthreads = None res9 = tpool.map(host, range(10))
# Copyright (c) 2016-2017 The Uncertainty Quantification Foundation. # License: 3-clause BSD. The full license text is available at: # - https://github.com/uqfoundation/pathos/blob/master/LICENSE def host(id): import socket return "Rank: %d -- %s" % (id, socket.gethostname()) if __name__ == '__main__': from pathos.pools import ThreadPool as TPool tpool = TPool() print("Evaluate 10 items on 1 thread") tpool.nthreads = 1 res3 = tpool.map(host, range(10)) print(tpool) print('\n'.join(res3)) print('') print("Evaluate 10 items on 2 threads") tpool.nthreads = 2 res5 = tpool.map(host, range(10)) print(tpool) print('\n'.join(res5)) print('') print("Evaluate 10 items on ? threads") tpool.nthreads = None res9 = tpool.map(host, range(10))
from pathos.helpers import freeze_support freeze_support() from pathos.pools import ProcessPool as Pool from pathos.pools import ThreadPool as TPool pool = Pool() tpool = TPool() # test 'dilled' multiprocessing for inner print("Evaluate 10 items on 2 proc:") pool.ncpus = 2 print(pool) print(pool.map(add_me, range(10))) print('') # test 'dilled' multiprocessing for lambda print("Evaluate 10 items on 4 proc:") pool.ncpus = 4 print(pool) print(pool.map(squ, range(10))) print('') # test for lambda, but with threads print("Evaluate 10 items on 4 threads:") tpool.nthreads = 4 print(tpool) print(tpool.map(squ, range(10))) print('') # end of file