我正在尝试在Windows 10上使用带有Python 3.5的Parallel Python。我是新手,所以请原谅这个术语。
我已经在每台计算机(节点)上安装了Python和所有必需的软件包,并且已经在每个节点上运行批处理脚本,以使它们对根计算机可见:
python ppserver.py -p 35000 -a -w 4 -s "secretword"
我将通过尝试运行一个我在互联网上找到并编辑的简单示例来解释这个问题,该示例应找到每个节点,但是,只找到少数几个节点。它始终是缺少的相同节点:
import math, time, sys, _thread
import pp
import numpy as np
import pandas as pd
import os
print("Begin")
# class for callbacks - This class is to allow the output of each node to be
# safely combined
class Sum:
def __init__(self):
self.value = 0.0
self.lock = _thread.allocate_lock()
self.count = 0
#the callback function
def add(self, value):
# we must use lock here because += is not atomic
self.count += 1
self.lock.acquire()
self.value += value
self.lock.release()
# This is the function that is sent to each node for independent analysis
def part_sum(start, end):
"""Calculates partial sum"""
sum = 0
for x in range(int(start), int(end)):
if int(x) % 2 == 0:
sum -= 1.0 / x
else:
sum += 1.0 / x
return sum
# Control script - run by the master to control the analysis and each of the
# nodes
print("""Usage: python callback.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
""")
start = 1
end = 200000000
# Divide the task into 128 subtasks
parts = 128
step = (end - start) / parts + 1
# tuple of all parallel python servers to connect with
ppservers = ("*:35000",) #find all available servers listening on port 35000!!!
if len(sys.argv) > 1:
ncpus = int(sys.argv[1])
# Creates jobserver with ncpus workers
job_server = pp.Server(ncpus, ppservers=ppservers)
print("Starting pp with", ncpus, "workers")
else:
# Creates jobserver with automatically detected number of workers
# also uses 2 local cpus!
job_server = pp.Server(ppservers=ppservers,secret="secretword")
#ncpus = job_server.get_ncpus() - 2
print("Starting pp with auto discovery")
# Create an instance of callback class
sum = Sum()
# Execute the same task with different amount of active workers and measure the time
start_time = time.time()
for index in range(parts):
starti = int(start+index*step)
endi = int(min(start+(index+1)*step, end))
# Submit a job which will calculate partial sum
# part_sum - the function
# (starti, endi) - tuple with arguments for part_sum
# callback=sum.add - callback function
job_server.submit(part_sum, (starti, endi), callback=sum.add)
#wait for jobs in all groups to finish
job_server.wait()
# Print the partial sum
print("Partial sum is", sum.value, "| diff =", math.log(2) - sum.value)
job_server.print_stats()
print("Done")
# Parallel Python Software: http://www.parallelpython.com
所有计算机都运行Windows 10,并且具有相同版本的Python和使用过的软件包。批处理脚本正在运行。这些计算机都在同一个网络上。我没有看到所有节点的可能原因是什么?
由于
答案 0 :(得分:0)
我遇到的问题是无法连接的计算机正在运行VirtualBox。我卸载了这个,发现计算机没问题。