【问题标题】:Parallel Python not seeing all computers并行 Python 看不到所有计算机
【发布时间】:2017-05-24 15:02:17
【问题描述】:

我正在尝试在 Windows 10 上将 Parallel Python 与 Python 3.5 一起使用。我是新手,所以请原谅这些术语。

我已经在每台计算机(节点)上安装了 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 和使用的包。批处理脚本正在运行。这些计算机都在同一个网络上。我没有看到所有节点的可能原因是什么?

谢谢

【问题讨论】:

  • 也许未找到的节点启用了阻止连接的软件防火墙?
  • 我尝试更改防火墙的设置以让 Python 通过,但似乎没有任何区别。此外,正在连接的计算机具有相同的防火墙,我没有更改它们的任何设置。

标签: python python-3.x parallel-processing parallel-python


【解决方案1】:

我遇到的问题是无法连接的计算机正在运行 VirtualBox。我卸载了这个,发现电脑没问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-29
    • 1970-01-01
    • 2011-03-05
    • 2021-12-19
    • 2014-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多