2
私は自分のプログラムで並列Pythonを使用しています。 私はCLIを使ってPythonプログラムを実行するとうまく動作します。parallel python:通信パイプの読み込みエラー
import math, sys, time
import pp
import os
def isprime(n):
"""Returns True if n is prime and False otherwise"""
if not isinstance(n, int):
raise TypeError("argument passed to is_prime is not of 'int' type")
if n < 2:
return False
if n == 2:
return True
max = int(math.ceil(math.sqrt(n)))
i = 2
while i <= max:
if n % i == 0:
return False
i += 1
return True
def sum_primes(n):
"""Calculates sum of all primes below given integer n"""
return sum([x for x in xrange(2,n) if isprime(x)])
print """Usage: python sum_primes.py [ncpus]
[ncpus] - the number of workers to run in parallel,
if omitted it will be set to the number of processors in the system
"""
print sys.argv
print sys.stdin
print sys.stdout
print sys.stderr
print 'read method'
#print 'str:', sys.stdin.read()
#print 'str:', sys.stdout.read()
print 'pptest print done'
# tuple of all parallel python servers to connect with
ppservers =()
#ppservers = ("10.0.0.1",)
if len(sys.argv) > 1:
ncpus = int(sys.argv[1])
# Creates jobserver with ncpus workers
job_server = pp.Server(ncpus, ppservers=ppservers)
else:
# Creates jobserver with automatically detected number of workers
job_server = pp.Server(ppservers=ppservers)
print "Starting pp with", job_server.get_ncpus(), "workers"
# Submit a job of calulating sum_primes(100) for execution.
# sum_primes - the function
# (100,) - tuple with arguments for sum_primes
# (isprime,) - tuple with functions on which function sum_primes depends
# ("math",) - tuple with module names which must be imported before sum_primes execution
# Execution starts as soon as one of the workers will become available
job1 = job_server.submit(sum_primes, (100,), (isprime,), ("math",))
# Retrieves the result calculated by job1
# The value of job1() is the same as sum_primes(100)
# If the job has not been finished yet, execution will wait here until result is available
result = job1()
print "Sum of primes below 100 is", result
start_time = time.time()
# The following submits 8 jobs and then retrieves the results
inputs = (100000, 100100, 100200, 100300, 100400, 100500, 100600, 100700)
jobs = [(input, job_server.submit(sum_primes,(input,), (isprime,), ("math",))) for input in inputs]
for input, job in jobs:
print "Sum of primes below", input, "is", job()
print "Time elapsed: ", time.time() - start_time, "s"
job_server.print_stats()
# Parallel Python Software: http://www.parallelpython.com
はの欠如に関連しているように見える: しかし、私は私のデバッガを通してそれを実行すると、それは次の頁の例を実行するときに
File "D:/Unief/Thesis/deepmedic-master\deepmedic\trainValidateTestVisualiseParallel.py", line 1063, in do_training
job_server = pp.Server(ncpus=1, ppservers=ppservers) # Creates jobserver with automatically detected number of workers
File "D:\Anaconda2\lib\site-packages\pp-1.6.4-py2.7.egg\pp.py", line 339, in __init__
self.set_ncpus(ncpus)
File "D:\Anaconda2\lib\site-packages\pp-1.6.4-py2.7.egg\pp.py", line 503, in set_ncpus
range(ncpus - len(self.__workers))])
File "D:\Anaconda2\lib\site-packages\pp-1.6.4-py2.7.egg\pp.py", line 138, in __init__
self.start()
File "D:\Anaconda2\lib\site-packages\pp-1.6.4-py2.7.egg\pp.py", line 149, in start
self.pid = int(self.t.receive())
File "D:\Anaconda2\lib\site-packages\pp-1.6.4-py2.7.egg\pptransport.py", line 140, in receive
raise RuntimeError("Communication pipe read error")
RuntimeError: Communication pipe read error
同じエラーが発生する次のエラーがスローされますが、デバッガの谷CLI。
解決方法はありますか?
最小例:。 輸入頁。 ppservers =(); job_server = pp.Server(ppservers = ppservers); print "Starting pp with"、job_server.get_ncpus()、 "workers"; – Dave