我得到的错误是:蟒蛇问题,客户端无法连接
回溯(最近通话最后一个): 文件 “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)
你是如何启动这些? – 2011-05-30 17:05:25
我试了mpirun和mpiexec: mpirun -np 1 python server.py和 mpiexec -np 1 python server.py – oguzcan 2011-05-30 17:24:21