# print the input to screen
    x = np.arange(N * nodes, dtype=np.float64)
    print("Input: %s\n" % x)


    # run sin2 in series, then print to screen
    print("Running serial python ...")
    y = list(map(sin2, x))
    print("Output: %s\n" % np.asarray(y))


    if HAS_PYINA:
        # map sin2 to the workers, then print to screen
        print("Running mpi4py on %d cores..." % nodes)
        y = MpiPool(nodes).map(sin2, x)
        print("Output: %s\n" % np.asarray(y))


    # map sin2 to the workers, then print to screen
    print("Running multiprocesing on %d processors..." % nodes)
    y = ProcessPool(nodes).map(sin2, x)
    print("Output: %s\n" % np.asarray(y))


    # map sin2 to the workers, then print to screen
    print("Running multiprocesing on %d threads..." % nodes)
    y = ThreadPool(nodes).map(sin2, x)
    print("Output: %s\n" % np.asarray(y))

    freeze_support()

    # print the input to screen
    x = np.arange(N * nodes, dtype=np.float64)
    xp = np.arange(N * nodes, dtype=np.float64)[::-1]
    print("Input: %s\n" % x)

    # map sin_diff to the workers, then print to screen
    print("Running serial python ...")
    y = list(map(sin_diff, x, xp))
    print("Output: %s\n" % np.asarray(y))

    if HAS_PYINA:
        # map sin_diff to the workers, then print to screen
        print("Running mpi4py on %d cores..." % nodes)
        y = MpiPool(nodes).map(sin_diff, x, xp)
        print("Output: %s\n" % np.asarray(y))

    # map sin_diff to the workers, then print to screen
    print("Running multiprocesing on %d processors..." % nodes)
    y = ProcessPool(nodes).map(sin_diff, x, xp)
    print("Output: %s\n" % np.asarray(y))

    # map sin_diff to the workers, then print to screen
    print("Running multiprocesing on %d threads..." % nodes)
    y = ThreadPool(nodes).map(sin_diff, x, xp)
    print("Output: %s\n" % np.asarray(y))

    # map sin_diff to the workers, then print to screen
    print("Running parallelpython on %d cpus..." % nodes)
    y = ParallelPool(nodes).map(sin_diff, x, xp)
Exemple #3
0
import scipy.integrate
scipy.integrate.quad(lambda x: 4.0/(1+x*x), 0, 1)
"""

from numpy import arange

# default # of rectangles
n = 20000

integration_points = (arange(1, n + 1) - 0.5) / n


def f(x):
    return 4.0 / (1.0 + x * x)


#from pyina.launchers import MpiScatter as Mpi
from pyina.launchers import MpiPool as Mpi

if __name__ == '__main__':

    work = Mpi(2)
    out = work.map(f, integration_points)

    from pyina import mpi
    if mpi.world.rank == 0:
        print("approxmiate pi : ", sum(out) / n)
        print("calculated on %d nodes " % work.nodes)

# end of file
Exemple #4
0
def play(Q):
    id, l = Q
    import numpy
    return "3 x %d = %d" % (id, numpy.sum(l))

def play2(id,l):
    import numpy
    return "3 x %d = %d" % (id, numpy.sum(l))

args = [ (i, range(3)*i) for i in range(5) ]
arg1 = [ i for i in range(5) ]
arg2 = [ range(3)*i for i in range(5) ]

print "Using 12 nodes and a worker pool..."
print 'Evaluate a function that expects a n-tuple argument "map(f,args)"'
pool = MpiPool(12)
res1 = pool.map(play, args)
#res1 = map(play, args)
print pool
print '\n'.join(res1)
print ''

print 'Evaluate a function that expects n arguments "map(f,arg1,arg2)"'
res2 = pool.map(play2, arg1, arg2)
#res2 = map(play2, arg1, arg2)
print pool
print '\n'.join(res2)

# end of file
Exemple #5
0
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 1997-2016 California Institute of Technology.
# Copyright (c) 2016-2018 The Uncertainty Quantification Foundation.
# License: 3-clause BSD.  The full license text is available at:
#  - https://github.com/uqfoundation/pyina/blob/master/LICENSE

from pyina.launchers import MpiScatter, MpiPool

def host(id):
    import socket
    return "Rank: %d -- %s" % (id, socket.gethostname())

print("Evaluate 10 items on 3 nodes using a worker pool:")
pool = MpiPool(3)
res1 = pool.map(host, range(10)) 
print(pool)
print('\n'.join(res1))
print('')

print("Evaluate 10 items on 3 nodes using scatter-gather:")
scat = MpiScatter(3)
res2 = scat.map(host, range(10)) 
print(scat)
print('\n'.join(res2))
print('')

print("Evaluate 5 items on 2 nodes using a worker pool:")
pool.nodes = 2
res3 = pool.map(host, range(5))
Exemple #6
0
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 1997-2016 California Institute of Technology.
# Copyright (c) 2016-2019 The Uncertainty Quantification Foundation.
# License: 3-clause BSD.  The full license text is available at:
#  - https://github.com/uqfoundation/pyina/blob/master/LICENSE

from pyina.launchers import MpiScatter, MpiPool

def host(id):
    import socket
    return "Rank: %d -- %s" % (id, socket.gethostname())

print("Evaluate 10 items on 3 nodes using a worker pool:")
pool = MpiPool(3)
res1 = pool.map(host, range(10)) 
print(pool)
print('\n'.join(res1))
print('')

print("Evaluate 10 items on 3 nodes using scatter-gather:")
scat = MpiScatter(3)
res2 = scat.map(host, range(10)) 
print(scat)
print('\n'.join(res2))
print('')

print("Evaluate 5 items on 2 nodes using a worker pool:")
pool.nodes = 2
res3 = pool.map(host, range(5))
Exemple #7
0
        kill_all()
    elif len(sys.argv) > 2:
        if sys.argv[1] == "--workers":
            print("seting up mpi...")
            MASTERINFO = set_master()
            nodes = sys.argv[2:]
            nodes = [node.strip('[()]').strip(',').strip() for node in nodes]
            #nodes = nodes.strip('[()]').split(',')
            set_workers(nodes, MASTERINFO)
    #elif sys.argv[1] == "--alias":
    #    print "setting up mpi python..."
    #    nodes = sys.argv[2:]
    #    nodes = [node.strip('[()]').strip(',').strip() for node in nodes]
    #    for node in nodes:
    #        alias(int(node))
        elif sys.argv[1] == "--fetch":
            nnodes = int(sys.argv[2])
            try:
                pool = MpiPool()
                pool.nodes = nnodes
                hostnames = pool.map(host, range(nnodes))
                print('\n'.join(hostnames))
            except:  # "--help"
                print(__doc__)
        else:  # "--help"
            print(__doc__)
    else:  # "--help"
        print(__doc__)

# End of file
Exemple #8
0
import scipy.integrate
scipy.integrate.quad(lambda x: 4.0/(1+x*x), 0, 1)
"""

from numpy import arange

# default # of rectangles
n = 20000

integration_points = (arange(1,n+1)-0.5)/n

def f(x):
    return 4.0/(1.0+x*x)

#from pyina.launchers import MpiScatter as Mpi
from pyina.launchers import MpiPool as Mpi


if __name__ == '__main__':

    work = Mpi(2)
    out = work.map(f, integration_points)
    
    from pyina import mpi
    if mpi.world.rank == 0:
        print "approxmiate pi : ", sum(out)/n
        print "calculated on %d nodes: " % work.nodes


# end of file
Exemple #9
0
    id, l = Q
    import numpy
    return "3 x %d = %d" % (id, numpy.sum(l))


def play2(id, l):
    import numpy
    return "3 x %d = %d" % (id, numpy.sum(l))


args = [(i, range(3) * i) for i in range(5)]
arg1 = [i for i in range(5)]
arg2 = [range(3) * i for i in range(5)]

print("Using 12 nodes and a worker pool...")
print('Evaluate a function that expects a n-tuple argument "map(f,args)"')
pool = MpiPool(12)
res1 = pool.map(play, args)
#res1 = map(play, args)
print(pool)
print('\n'.join(res1))
print('')

print('Evaluate a function that expects n arguments "map(f,arg1,arg2)"')
res2 = pool.map(play2, arg1, arg2)
#res2 = map(play2, arg1, arg2)
print(pool)
print('\n'.join(res2))

# end of file
Exemple #10
0
    elif len(sys.argv) > 2:
        if sys.argv[1] == "--workers":
            print("seting up mpi...")
            MASTERINFO = set_master()
            nodes = sys.argv[2:]
            nodes = [node.strip('[()]').strip(',').strip() for node in nodes]
            #nodes = nodes.strip('[()]').split(',')
            set_workers(nodes,MASTERINFO)
       #elif sys.argv[1] == "--alias": 
       #    print "setting up mpi python..."
       #    nodes = sys.argv[2:]
       #    nodes = [node.strip('[()]').strip(',').strip() for node in nodes]
       #    for node in nodes:
       #        alias(int(node))
        elif sys.argv[1] == "--fetch":
            nnodes = int(sys.argv[2])
            try:
                pool = MpiPool()
                pool.nodes = nnodes
                hostnames = pool.map(host, range(nnodes))
                print('\n'.join(hostnames))
            except: # "--help"
                print(__doc__)
        else: # "--help"
            print(__doc__)
    else: # "--help"
        print(__doc__)


# End of file