예제 #1
0
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 1997-2016 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

from pathos.parallel import stats
from pathos.parallel import ParallelPool as Pool
pool = Pool()

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


print "Evaluate 10 items on 1 cpu"
pool.ncpus = 1
res3 = pool.map(host, range(10))
print pool
print '\n'.join(res3)
print stats()

print "Evaluate 10 items on 2 cpus"
pool.ncpus = 2
res5 = pool.map(host, range(10)) 
print pool
print '\n'.join(res5)
print stats()

# end of file
예제 #2
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/pathos/blob/master/LICENSE

from pathos.parallel import stats
from pathos.parallel import ParallelPool as Pool
pool = Pool()


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


print("Evaluate 10 items on 2 cpus")  #FIXME: reset lport below
pool.ncpus = 2
pool.servers = ('localhost:5653', )
res5 = pool.map(host, range(10))
print(pool)
print('\n'.join(res5))
print(stats())
print('')

# end of file
예제 #3
0
            word_count[word] = 1
    return word_count

def top_ten(wordcount):
    for key, value in sorted(word_count.items(), key=operator.itemgetter(1), reverse=True)[:10]:
        print key, value

def wordcount(f):
    words = word_list(f)
    clean = cleanup(words)
    word_dict(clean)

if __name__ == '__main__':
    info('Mainline function')

    pool.ncpus = 2
    pool.servers = ('localhost:17320',)

    words = pool.map(m_word_list, f) 
    pool.join()

    pool.servers = ('localhost:17320',)
    clean_list = pool.map(m_cleanup, words)
    pool.join(clean_list, )

    pool.servers = ('localhost:17320',)
    word_count = pool.map(word_dict, cleanlist)
    pool.join(word_count, )

    top_ten(word_count)