Ejemplo n.º 1
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.mpi_scatter import parallel_map
from pyina.mpi_pool import parallel_map


if __name__ == '__main__':

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


# end of file
Ejemplo n.º 2
0
    argfilename = sys.argv[2]
    outfilename = sys.argv[3]

    if funcname.endswith('.pik'):  # used pickled func
        workdir = None
        func = pickle.load(open(funcname, 'r'))
    else:  # used tempfile for func
        workdir = sys.argv[4]
        sys.path = [workdir] + sys.path
        modname = os.path.splitext(os.path.basename(funcname))[0]
        module = __import__(modname)
        sys.path.pop(0)
        func = module.FUNC
    args, kwds = pickle.load(open(argfilename, 'r'))

    if world.rank == 0:
        log.info('funcname: %s' % funcname)  # sys.argv[1]
        log.info('argfilename: %s' % argfilename)  # sys.argv[2]
        log.info('outfilename: %s' % outfilename)  # sys.argv[3]
        log.info('workdir: %s' % workdir)  # sys.argv[4]
        log.info('func: %s' % func)
        log.info('args: %s' % str(args))
        log.info('kwds: %s' % str(kwds))
    res = parallel_map(func, *args, **kwds)  #XXX: called on ALL nodes ?

    if world.rank == 0:
        log.info('res: %s' % str(res))
        pickle.dump(res, open(outfilename, 'w'))

# end of file
Ejemplo n.º 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.mpi_scatter import parallel_map
from pyina.mpi_pool import parallel_map


if __name__ == '__main__':

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


# end of file
Ejemplo n.º 4
0
    outfilename = sys.argv[3]

    if funcname.endswith('.pik'):  # used pickled func
        workdir = None
        func = pickle.load(open(funcname,'r'))
    else:  # used tempfile for func
        workdir = sys.argv[4]
        sys.path = [workdir] + sys.path
        modname = os.path.splitext(os.path.basename(funcname))[0]
        module = __import__(modname)
        sys.path.pop(0)
        func = module.FUNC
    args,kwds = pickle.load(open(argfilename,'r'))

    if world.rank == 0:
        log.info('funcname: %s' % funcname)        # sys.argv[1]
        log.info('argfilename: %s' % argfilename)  # sys.argv[2] 
        log.info('outfilename: %s' % outfilename)  # sys.argv[3]
        log.info('workdir: %s' % workdir)          # sys.argv[4]
        log.info('func: %s' % func)
        log.info('args: %s' % str(args))
        log.info('kwds: %s' % str(kwds))
    res = parallel_map(func, *args, **kwds) #XXX: called on ALL nodes ?

    if world.rank == 0:
        log.info('res: %s' % str(res))
        pickle.dump(res, open(outfilename,'w'))


# end of file