Changeset 672 for branches


Ignore:
Timestamp:
06/01/13 20:42:22 (3 years ago)
Author:
mmckerns
Message:

updated HPCtut to use pathos and pyina Pools

Location:
branches/HPCtut
Files:
7 edited
3 moved

Legend:

Unmodified
Added
Removed
  • branches/HPCtut/all_scatter_gather.py

    r534 r672  
    1111 
    1212import numpy as np 
    13 from pyina.ez_map import ez_map2 as mpi_map  # mpi4py 
    14 from pathos.mp_map import mp_map             # multiprocessing 
    15 from pathos.pp_map import pp_map             # parallelpython 
     13from pyina.launchers import Mpi as MpiPool 
     14from pathos.multiprocessing import ProcessingPool 
     15from pathos.pp import ParallelPythonPool 
    1616nodes = 2; N = 3 
    1717 
     
    3636# map sin2 to the workers, then print to screen 
    3737print("Running mpi4py on %d cores..." % nodes) 
    38 y = mpi_map(sin2, x, nnodes=nodes) 
     38y = MpiPool(nodes).map(sin2, x) 
    3939print("Output: %s\n" % np.asarray(y)) 
    4040 
     
    4242# map sin2 to the workers, then print to screen 
    4343print("Running multiprocesing on %d processors..." % nodes) 
    44 y = mp_map(sin2, x, nproc=nodes) 
     44y = ProcessingPool(nodes).map(sin2, x) 
    4545print("Output: %s\n" % np.asarray(y)) 
    4646 
     
    4848# map sin2 to the workers, then print to screen 
    4949print("Running parallelpython on %d cpus..." % nodes) 
    50 y = pp_map(sin2, x, ncpus=nodes, servers=('mycpu.mydomain.com',)) 
     50y = ParallelPythonPool(nodes).map(sin2, x) 
    5151print("Output: %s\n" % np.asarray(y)) 
    5252 
  • branches/HPCtut/all_scatter_gather2.py

    r534 r672  
    1111 
    1212import numpy as np 
    13 from pyina.ez_map import ez_map2 as mpi_map  # mpi4py 
    14 from pathos.pp_map import pp_map             # parallelpython 
    15 from pathos.mp_map import mp_map             # multiprocessing 
     13from pyina.launchers import Mpi as MpiPool 
     14from pathos.multiprocessing import ProcessingPool 
     15from pathos.pp import ParallelPythonPool 
    1616nodes = 2; N = 3 
    1717 
     
    3636# map sin_diff to the workers, then print to screen 
    3737print("Running mpi4py on %d cores..." % nodes) 
    38 y = mpi_map(sin_diff, x, xp, nnodes=nodes) 
     38y = MpiPool(nodes).map(sin_diff, x, xp) 
     39print("Output: %s\n" % np.asarray(y)) 
     40 
     41 
     42# map sin_diff to the workers, then print to screen 
     43print("Running multiprocesing on %d processors..." % nodes) 
     44y = ProcessingPool(nodes).map(sin_diff, x, xp) 
    3945print("Output: %s\n" % np.asarray(y)) 
    4046 
     
    4248# map sin_diff to the workers, then print to screen 
    4349print("Running parallelpython on %d cpus..." % nodes) 
    44 y = pp_map(sin_diff, x, xp, ncpus=nodes) 
    45 print("Output: %s\n" % np.asarray(y)) 
    46  
    47  
    48 # map sin2 to the workers, then print to screen 
    49 print("Running multiprocesing on %d processors..." % nodes) 
    50 y = mp_map(sin_diff, x, xp, nproc=nodes) 
     50y = ParallelPythonPool(nodes).map(sin_diff, x, xp) 
    5151print("Output: %s\n" % np.asarray(y)) 
    5252 
  • branches/HPCtut/optimize.py

    r534 r672  
    3232 
    3333    # minimize the function 
    34     from itertools import imap                   # itertools 
    35     results = imap(the_solver, model, x0, **kwds) 
     34    results = map(the_solver, model, x0) 
    3635 
    3736    # find the results with the lowest energy 
  • branches/HPCtut/optimize_cheby_diffev_map.py

    r534 r672  
    22""" 
    33Solve Nth-order Chebyshev polynomial coefficients with Differential Evolution. 
    4 Launch optimizers in parallel with itertools map. 
     4Launch optimizers with python's map. 
    55 
    6 Requires: development version of mystic 
     6Requires: development version of mystic, pathos 
    77  http://pypi.python.org/pypi/mystic 
     8  http://pypi.python.org/pypi/pathos 
    89""" 
    910 
     
    2829 
    2930    # minimize the function 
    30     results = mapper(solver, x0, **kwds) 
     31    results = mapper(nodes).map(solver, x0) 
    3132 
    3233    # find the results with the lowest energy 
     
    5152 
    5253# get the map functions 
    53 from itertools import imap                   # itertools 
     54from pathos.python import PythonSerial as serial 
    5455 
    5556 
     
    5859    print "Function: %s" % target 
    5960    print "Solver: %s" % 'diffev' 
    60     optimize(diffev_chebyshev, imap, nodes=1, target=target) 
     61    optimize(diffev_chebyshev, serial, nodes=1, target=target) 
    6162 
    6263  
  • branches/HPCtut/optimize_cheby_powell_map.py

    r534 r672  
    22""" 
    33Solve Nth-order Chebyshev polynomial coefficients with Powell's method. 
    4 Launch optimizers in parallel with itertools map. 
     4Launch optimizers with python's map. 
    55 
    6 Requires: development version of mystic 
     6Requires: development version of mystic, pathos 
    77  http://pypi.python.org/pypi/mystic 
     8  http://pypi.python.org/pypi/pathos 
    89""" 
    910 
     
    2829 
    2930    # minimize the function 
    30     results = mapper(solver, x0, **kwds) 
     31    results = mapper(nodes).map(solver, x0) 
    3132 
    3233    # find the results with the lowest energy 
     
    5152 
    5253# get the map functions 
    53 from itertools import imap                   # itertools 
     54from pathos.python import PythonSerial as serial 
    5455 
    5556 
     
    5859    print "Function: %s" % target 
    5960    print "Solver: %s" % 'fmin_powell' 
    60     optimize(powell_chebyshev, imap, nodes=1, target=target) 
     61    optimize(powell_chebyshev, serial, nodes=1, target=target) 
    6162 
    6263  
  • branches/HPCtut/optimize_cheby_powell_mpimap.py

    r534 r672  
    22""" 
    33Solve Nth-order Chebyshev polynomial coefficients with Powell's method. 
    4 Launch optimizers in parallel with mpi4py map. 
     4Launch optimizers with mpi4py's map. 
    55 
    66Requires: development version of mystic, pyina 
     
    2929 
    3030    # minimize the function 
    31     results = mapper(solver, x0, **kwds) 
     31    results = mapper(nodes).map(solver, x0) 
    3232 
    3333    # find the results with the lowest energy 
     
    5252 
    5353# get the map functions 
    54 from pyina.ez_map import ez_map2 as mpi_map  # mpi4py 
     54from pyina.launchers import Mpi as mpipool 
    5555 
    5656 
     
    5959    print "Function: %s" % target 
    6060    print "Solver: %s" % 'fmin_powell' 
    61     optimize(powell_chebyshev, mpi_map, nodes=10, target=target, nnodes=10) 
     61    optimize(powell_chebyshev, mpipool, nodes=10, target=target) 
    6262 
    6363  
  • branches/HPCtut/optimize_cheby_powell_mpmap.py

    r534 r672  
    22""" 
    33Solve Nth-order Chebyshev polynomial coefficients with Powell's method. 
    4 Launch optimizers in parallel with multiprocessing map. 
     4Launch optimizers with multiprocessing's map. 
    55 
    66Requires: development version of mystic, pathos 
     
    2929 
    3030    # minimize the function 
    31     results = mapper(solver, x0, **kwds) 
     31    results = mapper(nodes).map(solver, x0) 
    3232 
    3333    # find the results with the lowest energy 
     
    5252 
    5353# get the map functions 
    54 from pathos.mp_map import mp_map             # multiprocessing 
     54from pathos.multiprocessing import ProcessingPool as mppool 
    5555 
    5656 
     
    5959    print "Function: %s" % target 
    6060    print "Solver: %s" % 'fmin_powell' 
    61     optimize(powell_chebyshev, mp_map, nodes=10, target=target, nproc=10) 
     61    optimize(powell_chebyshev, mppool, nodes=10, target=target) 
    6262 
    6363  
  • branches/HPCtut/optimize_cheby_powell_ppmap.py

    r534 r672  
    22""" 
    33Solve Nth-order Chebyshev polynomial coefficients with Powell's method. 
    4 Launch optimizers in parallel with parallelpython map. 
     4Launch optimizers with parallelpython's map. 
    55 
    66Requires: development version of mystic, pathos 
     
    2929 
    3030    # minimize the function 
    31     results = mapper(solver, x0, **kwds) 
     31    results = mapper(nodes).map(solver, x0) 
    3232 
    3333    # find the results with the lowest energy 
     
    5252 
    5353# get the map functions 
    54 from pathos.pp_map import pp_map             # parallelpython 
     54from pathos.pp import ParallelPythonPool as pppool 
    5555 
    5656 
     
    5959    print "Function: %s" % target 
    6060    print "Solver: %s" % 'fmin_powell' 
    61     optimize(powell_chebyshev, pp_map, nodes=10, target=target, ncpus=10) 
     61    optimize(powell_chebyshev, pppool, nodes=10, target=target) 
    6262 
    6363  
  • branches/HPCtut/optimize_powell.py

    r534 r672  
    3434 
    3535    # minimize the function 
    36     results = mapper(the_solver, model, x0, **kwds) 
     36    results = mapper(nodes).map(the_solver, model, x0) 
    3737 
    3838    # find the results with the lowest energy 
     
    5151 
    5252# get the map functions 
    53 from itertools import imap                   # itertools 
    54 from pathos.pp_map import pp_map             # parallelpython 
    55 from pathos.mp_map import mp_map             # multiprocessing 
    56 from pyina.ez_map import ez_map2 as mpi_map  # mpi4py 
     53from pathos.python import PythonSerial as serial 
     54from pathos.pp import ParallelPythonPool as pppool 
     55from pathos.multiprocessing import ProcessingPool as mppool 
     56from pyina.launchers import Mpi as mpipool 
    5757 
    5858 
     
    6363    print "Solver: %s" % 'fmin_powell' 
    6464   #NOTE: some of the below should fail, due to how objects are shipped in map 
    65     optimize(the_solver, imap, nodes=1, target=target) 
    66    #optimize(the_solver, pp_map, nodes=1, target=target, ncpus=1) 
    67    #optimize(the_solver, mpi_map, nodes=1, target=target, nnodes=1) 
    68    #optimize(the_solver, mp_map, nodes=1, target=target, nproc=1) 
     65    optimize(the_solver, serial, nodes=2, target=target) 
     66   #optimize(the_solver, mppool, nodes=2, target=target) 
     67   #optimize(the_solver, pppool, nodes=2, target=target) 
     68   #optimize(the_solver, mpipool, nodes=2, target=target)  #XXX: Fails 
    6969 
    7070  
  • branches/HPCtut/optimize_rosen_powell_map.py

    r534 r672  
    22""" 
    33Minimize the Rosenbrock function with Powell's method. 
    4 Launch optimizers in parallel with itertools map. 
     4Launch optimizers with python's map. 
    55 
    6 Requires: development version of mystic 
     6Requires: development version of mystic, pathos 
    77  http://pypi.python.org/pypi/mystic 
     8  http://pypi.python.org/pypi/pathos 
    89""" 
    910 
     
    2829 
    2930    # minimize the function 
    30     results = mapper(solver, x0, **kwds) 
     31    results = mapper(nodes).map(the_solver, model, x0) 
    3132 
    3233    # find the results with the lowest energy 
     
    5152 
    5253# get the map functions 
    53 from itertools import imap                   # itertools 
     54from pathos.python import PythonSerial as serial 
    5455 
    5556 
     
    5859    print "Function: %s" % target 
    5960    print "Solver: %s" % 'fmin_powell' 
    60     optimize(powell_rosen, imap, nodes=10, target=target) 
     61    optimize(powell_rosen, serial, nodes=10, target=target) 
    6162 
    6263  
Note: See TracChangeset for help on using the changeset viewer.