0

我得到的错误是:蟒蛇问题,客户端无法连接

回溯(最近通话最后一个): 文件 “client2.py”,14号线在 端口= MPI.Lookup_name(service,info) mpi4py.MPI.Lookup_name(src/mpi4py.MPI.c:64562)中的文件“Comm.pyx”,第1676行, mpi4py.MPI.Exception:MPI_ERR_NAME:无效名称参数

我试图实现使用mpi4py客户机/服务器模式。服务器可以Publish_name并等待客户端。但是,客户端不能使用在API中描述的必要方法如下图所示:

#! /usr/bin/env python 

from mpi4py import MPI 

rank = MPI.COMM_WORLD.Get_rank() 

def log(msg, *args): 
    if rank == 0: 
     print msg % args 

info = MPI.INFO_NULL 
service = 'pyeval' 
log("looking-up service '%s'", service) 
port = MPI.Lookup_name(service, info) // PROBLEM HERE ! 
log("service located at port '%s'", port) 

root = 0 
log('waiting for server connection...') 
comm = MPI.COMM_WORLD.Connect(port, info, root) 
log('server connected...') 

while True: 
    done = False 
    if rank == root: 
     try: 
      message = raw_input('pyeval>>> ') 
      if message == 'quit': 
       message = None 
       done = True 
     except EOFError: 
      message = None 
      done = True 
     comm.Send(message, dest=0, tag=0) 
    else: 
     message = None 
    done = MPI.COMM_WORLD.Bcast(done, root) 
    if done: 
     break 

log('disconnecting server...') 
comm.Disconnect() 

我也张贴在服务器端代码,因为它可能会有所帮助:

#! /usr/bin/env python 

from mpi4py import MPI 

rank = MPI.COMM_WORLD.Get_rank() 

def log(msg, *args): 
    if rank == 0: 
     print msg % args 


log('') 

info = MPI.INFO_NULL 

port = MPI.Open_port(info) 
log("opened port: '%s'", port) 

service = 'pyeval' 
MPI.Publish_name(service, info, port) 
log("published service: '%s'", service) 

root = 0 
log('waiting for client connection...') 
comm = MPI.COMM_WORLD.Accept(port, info, root) 
log('client connected...') 

while True: 
    done = False 
    if rank == root: 
     message = comm.Recv(source=0, tag=0) 
     if message is None: 
      done = True 
     else: 
      try: 
       print 'eval(%r) -> %r' % (message, eval(message)) 
      except StandardError: 
       print "invalid expression: %s" % message 
    done = MPI.COMM_WORLD.Bcast(done, root) 
    if done: 
     break 

log('disconnecting client...') 
comm.Disconnect() 

log('upublishing service...') 
MPI.Unpublish_name(service, info, port) 

log('closing port...') 
MPI.Close_port(port) 
+0

你是如何启动这些? – 2011-05-30 17:05:25

+0

我试了mpirun和mpiexec: mpirun -np 1 python server.py和 mpiexec -np 1 python server.py – oguzcan 2011-05-30 17:24:21

回答

1

您希望服务器产生客户,以便他们可以沟通。另外,你的Send/Recv/Bcast应该是send/recv/bcast; mpi4py同时支持发送和发送的Recv和recv等,但大写版本采取“常规” C/C++/Fortran的参数,而小写的人是更Python。

所以成功地以下运行,我 - client.py:

#! /usr/bin/env python 
from mpi4py import MPI 

rank = MPI.COMM_WORLD.Get_rank() 

def log(msg, *args): 
    if rank == 0: 
     print msg % args 

info = MPI.INFO_NULL 
service = "pyeval" 
log("looking-up service '%s'", service) 
port = MPI.Lookup_name(service) 
log("service located at port '%s'", port) 

root = 0 
log('waiting for server connection...') 
comm = MPI.COMM_WORLD.Connect(port, info, root) 
log('server connected...') 

while True: 
    done = False 
    if rank == root: 
     try: 
      message = raw_input('pyeval>>> ') 
      if message == 'quit': 
       message = None 
       done = True 
     except EOFError: 
      message = None 
      done = True 
     comm.send(message, dest=0, tag=0) 
    else: 
     message = None 
    done = MPI.COMM_WORLD.bcast(done, root) 
    if done: 
     break 

log('disconnecting server...') 
comm.Disconnect() 

和server.py:

#! /usr/bin/env python 

from mpi4py import MPI 

rank = MPI.COMM_WORLD.Get_rank() 

def log(msg, *args): 
    if rank == 0: 
     print msg % args 

log('') 

info = MPI.INFO_NULL 

port = MPI.Open_port(info) 
log("opened port: '%s'", port) 

service = 'pyeval' 
MPI.Publish_name(service, info, port) 
log("published service: '%s'", service) 

MPI.COMM_WORLD.Spawn("./client.py", maxprocs=1) 

root = 0 
log('waiting for client connection...') 
comm = MPI.COMM_WORLD.Accept(port, info, root) 
log('client connected...') 

while True: 
    done = False 
    if rank == root: 
     message = comm.recv(source=0, tag=0) 
     if message is None: 
      done = True 
     else: 
      try: 
       print 'eval(%r) -> %r' % (message, eval(message)) 
      except StandardError: 
       print "invalid expression: %s" % message 
    done = MPI.COMM_WORLD.bcast(done, root) 
    if done: 
     break 

log('disconnecting client...') 
comm.Disconnect() 

log('upublishing service...') 
MPI.Unpublish_name(service, info, port) 

log('closing port...') 
MPI.Close_port(port) 

但在这里,你还必须应付的事实,大多数MPI实现只会给标准输入排名0,所以客户没有一个很好的方式从终端获取输入(一般来说,你会如果有多个客户端的工作?)我需要

+0

你如何运行这些?如果我运行server.py这样的:'的mpirun -n 1条蟒蛇server.py'我得到以下错误,即使client.py是在同一个目录: '的mpirun无法启动指定的应用程序,因为它可以尝试启动过程排名0.' 与mpiexec的相同oguzcan联想-3000-G530 :不能访问或执行可执行文件: 可执行文件:./client.py 节点。 – oguzcan 2011-05-31 09:56:44

+0

@oguzcan:确保您的客户端可执行。我刚刚运行该程序,它正在工作。尝试'chmod + x。/ client.py',然后用'python server.py'执行服务器。 – 2017-04-18 21:54:05

1

使用Ø用于名称发布和名称查找的mpi-server。继执行服务器和客户端的步骤为我工作:

OMPI服务器

rm -f /tmp/ompi-server.txt 
killall ompi-server 
ompi-server -r /tmp/ompi-server.txt 

服务器

mpiexec --ompi-server file:/tmp/ompi-server.txt -n 1 python server.py 

客户

mpiexec --ompi-server file:/tmp/ompi-server.txt -n 1 python client.py 
+0

这也可以工作,而无需在服务器产卵客户端。 – 2011-06-01 00:32:34