1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 2015-2016 California Institute of Technology.
# Copyright (c) 2016-2026 The Uncertainty Quantification Foundation.
# License: 3-clause BSD. The full license text is available at:
# - https://github.com/uqfoundation/pathos/blob/master/LICENSE
def g(x):
import random
return int(x * random.random())
def h(x):
return sum(tmap(g, x))
def f(x,y):
return x*y
x = range(10)
y = range(5)
if __name__ == '__main__':
from pathos.helpers import freeze_support, shutdown
freeze_support()
from pathos.pools import ProcessPool, ThreadPool
from pathos.maps import Map, Amap
amap = Amap(ProcessPool)#, close=True, join=True, clear=True)
tmap = Map(ThreadPool, close=True, join=True, clear=True)
print(amap(f, [h(x),h(x),h(x),h(x),h(x)], y).get())
def _f(m, g, x, y):
return sum(m(g,x))*y
print(amap(_f, [tmap]*len(y), [g]*len(y), [x]*len(y), y).get())
from math import sin, cos
print(amap(tmap, [sin,cos], [x,x]).get())
shutdown()
# EOF
|