我编写了一个OpenMPI应用程序,它由一个服务器和一个客户端部分组成,它们分别启动:
me@server1:~> mpirun server
Run Code Online (Sandbox Code Playgroud)
和
me@server2:~> mpirun client
Run Code Online (Sandbox Code Playgroud)
server使用创建端口MPI_Open_port.问题是:OpenMPI是否有将端口通信的机制client?我想这MPI_Publish_name并且MPI_Lookup_name在这里不起作用,因为server不知道应该向哪台其他计算机发送信息.
对我来说,看起来只有使用单个程序启动的进程mpirun才能与之通信MPI_Publish_name.
我也发现了ompi-server,但文档太简约了,我无法理解这一点.有谁知道这是如何使用的?
相关:MPICH:如何使用publish_name使客户端应用程序可以lookup_name呢?和/sf/ask/648442091/
MPI_Publish_name提供了一个MPI信息对象,它可以有一个Open MPI特定的布尔键ompi_global_scope.如果此键设置为true,则该名称将发布到全局范围,即已发布的实例ompi-server.MPI_Lookup_name默认情况下,如果提供了URI,则首先执行全局名称查找ompi-server.
该过程包括几个步骤:
1)从ompi-server集群中的某个位置开始,可以从所有节点访问它.出于调试目的,您可以将--no-daemonize -r +参数传递给它.它会启动并在标准输出中打印一个与此类似的URI:
$ ompi-server --no-daemonize -r +
1221656576.0;tcp://10.1.13.164:36351;tcp://192.168.221.41:36351
Run Code Online (Sandbox Code Playgroud)
2)在服务器中,构建一个MPI信息对象并将ompi_global_scope键设置为true:
MPI_Info info;
MPI_Info_create(&info);
MPI_Info_set(info, "ompi_global_scope", "true");
Run Code Online (Sandbox Code Playgroud)
然后将info对象传递给MPI_Publish_name:
MPI_Publish_name("server", info, port_name);
Run Code Online (Sandbox Code Playgroud)
3)在客户端中,调用MPI_Lookup_name将首先在全局上下文中自动执行查找(这可以通过在MPI信息对象中提供正确的密钥来更改,但在您的情况下,默认行为应该足够).
为了使客户端和服务器代码都知道ompi-server它所在的位置,您必须mpirun使用该--ompi-server 1221656576.0;tcp://10.1.13.164:36351;tcp://192.168.221.41:36351选项为两个命令提供URI .
另一种选择是ompi-server将URI写入文件,然后可以在mpirun要运行的节点上读取该文件.例如,如果在mpirun执行两个命令的同一节点上启动服务器,则可以使用文件/tmp.如果你ompi-server在另一个节点上启动,那么共享文件系统(NFS,Lustre等)就可以了.无论哪种方式,命令集将是:
$ ompi-server [--no-daemonize] -r file:/path/to/urifile
...
$ mpirun --ompi-server file:/path/to/urifile server
...
$ mpirun --ompi-server file:/path/to/urifile client
Run Code Online (Sandbox Code Playgroud)
如果mpirun在同一节点上同时运行,则--ompi-server还可以指定mpirun要用作名称服务器的已运行实例的PID .它允许您在服务器中使用本地名称发布(即跳过"运行ompi-server"和"创建信息对象"部分).命令序列如下:
head-node$ mpirun --report-pid server
[ note the PID of this mpirun instance ]
...
head-node$ mpirun --ompi-server pid:12345 client
Run Code Online (Sandbox Code Playgroud)
这里12345应该由服务器的实际PID来代替mpirun.
您还可以让服务器mpirun打印其URI并将该URI传递给客户端mpirun:
$ mpirun --report-uri + server
[ note the URI ]
...
$ mpirun --ompi-server URI client
Run Code Online (Sandbox Code Playgroud)
如果您指定/path/to/file(注意:file:此处没有前缀)而不是+在--report-uri选项之后,您也可以将URI写入文件:
$ mpirun --report-uri /path/to/urifile server
...
$ mpirun --ompi-server file:/path/to/urifile client
Run Code Online (Sandbox Code Playgroud)
请注意,返回的URI mpirun具有与a相同的格式ompi-server,即它包含主机IP地址,因此如果第二个mpirun节点在另一个节点上执行,它也可以工作,该节点能够通过TCP/IP与第一个节点通信(/path/to/urifile并存在于共享文件系统中).
我使用Open MPI 1.6.1测试了上述所有内容.某些变体可能不适用于早期版本.