openMPI多节点无法执行的问题

机房有多台HP服务器,有个任务计算量大,而且并行度高,非常适合并行计算,于是准备配置openMPI来做加速。

创建ssh免密登陆、安装openMPI 1.65 都非常顺利,每个节点上单独运行例子都正常,诡异的是,一旦在命令中加入 --hostfile hosts 参数,指定多节点运行,马上出现 

bash: orted: 未找到命令
--------------------------------------------------------------------------
A daemon (pid 8793) died unexpectedly with status 127 while attempting
to launch so we are aborting.

There may be more information reported by the environment (see above).

This may be because the daemon was unable to find all the needed shared
libraries on the remote node. You may set your LD_LIBRARY_PATH to have the
location of the shared libraries on the remote nodes and this will
automatically be forwarded to the remote nodes.
--------------------------------------------------------------------------
--------------------------------------------------------------------------
mpirun noticed that the job aborted, but has no info as to the process
that caused that situation.

百度了很多网页,众说纷纭,有的说在.bashrc中加入 PATH和 LD_LIBRARY_PATH 目录,有的说在 /etc/profile 中加入,还有的说在/root/.bashrc中加入。

关键是每个节点上用 env 命令查看 ,路径都正确,打 which mpirun ,都能找到路径。 单节点例子都能正确运行,明显不是路径问题。

看来只能从原始文档里找答案了,

先 man openmpi

从中得知 mpirun/ mpiexec/ orterun 这几个命令完全相同,是同义词,更详细命令参数建议查看 mpirun 文档。

于是 man mpirun

文档第一页中显示,可以用 --prefix 来指定 一个绝对运行目录,查看更详细的Remote Execution,该参数用来指向远程节点的openMPI安装目录,让远程节点可以顺利找到 mpirun、mpiexec、 orterun 来运行程序。

 

   Remote Execution
       Open  MPI requires that the PATH environment variable be set to find executables on remote nodes (this is typically only necessary in rsh- or ssh-
       based environments -- batch/scheduled environments typically copy the current environment to the execution of remote jobs, so if the current envi‐
       ronment  has  PATH  and/or  LD_LIBRARY_PATH  set properly, the remote nodes will also have it set properly).  If Open MPI was compiled with shared
       library support, it may also be necessary to have the LD_LIBRARY_PATH environment variable set on remote nodes as well  (especially  to  find  the
       shared libraries required to run user MPI applications).

       However,  it  is not always desirable or possible to edit shell startup files to set PATH and/or LD_LIBRARY_PATH.  The --prefix option is provided
       for some simple configurations where this is not possible.

       The --prefix option takes a single argument: the base directory on the remote node where Open MPI is installed.  Open MPI will use this  directory
       to  set  the remote PATH and LD_LIBRARY_PATH before executing any Open MPI or user applications.  This allows running Open MPI jobs without having
       pre-configured the PATH and LD_LIBRARY_PATH on the remote nodes.

       Open MPI adds the basename of the current node's "bindir" (the directory where Open MPI's executables are installed) to the prefix and  uses  that
       to  set  the  PATH  on  the  remote  node.   Similarly,  Open MPI adds the basename of the current node's "libdir" (the directory where Open MPI's
       libraries are installed) to the prefix and uses that to set the LD_LIBRARY_PATH on the remote node.  For example:

       Local bindir:  /localde/directory/bin

       Local libdir:  /localde/directoryb64

于是尝试加上该参数,全部节点正常工作。

语法: [mpirun | mpiexec | orterun ]  -np 参与运行的核心数  --hostfile 多节点名文件    --prefix  远程节点openmpi安装目录  待执行程序

例子: mpirun -np 20 --hostfile myhosts  --prefix /usr/local/my_mpi   a.out

分析原因: .bashrc 中设置的 PATH 和 LD_LIBRARY_PATH 只对直接登录的用户生效,对 mpi 通过 ssh 登录进来的用户无效,所以会提示  orted : 命令未找到 , 即在远程节点上找不到 mpirun/ mpiexec/ orterun 命令,更无法执行程序。

解决办法:主节点启动命令时, 通过 --prefix 参数指定远程节点的 openMPI 安装目录,让远程主机能顺利找到这些命令。

另外:安装过程中的一些说法

(1)运行 openMPI 可以不用 root 用户,普通用户只要添加到权限合适的组中(我把用户加入到了 adm 、root 、sudo组,基本和root权限一样了),也能正常运行;

(2)编译openMPI时建议加 prefix 参数来指定安装目录,并且全部节点都用同一个目录,这样将来管理方便,我编译用  ./configrue --prefix /usr/local/my_mpi 

(3)运行程序时,把待执行程序用scp命令拷贝到各 子节点上,也要放到同一目录下。

结论:起码对计算机专业来说,学英语还是很有必要的,遇到问题,最权威的解释,往往不再网络上,而是在你本机的文档中。

 

顺便把测试代码也放上,这个其实是 mpich( 另一个 mpi 实现)的实例代码,不但能显示当前是第几个进程,还能显示各节点的主机名,方便测试。

//HelloMpi.c
#include <stdio.h>
#include <mpi.h>

int main(int argc, char *argv[])
{
	int myrank, nprocs;
	char name[10];
	int name_len;
	int i,j,k,sum=0;
	MPI_Init(&argc, &argv);
	MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
	MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
	MPI_Get_processor_name(name, &name_len);
	printf("core[%3d] of [%3d] in {%s},  in dir[ ~/托腮etMPI ]\n", myrank, nprocs, name);
	/* for(i =0 ; i<10000; i++) */
		/* for(j=0 ;j< myrank ; j++) */
			/* sum +=j; */
	/* printf("core[%3d], sum= %12d\n", myrank,sum ); */

	MPI_Finalize();

	return 0;
}

 

<think>好的,用户想了解OpenMPI的相关介绍,包括是什么、作用、特点和使用场景。我需要先整理一下已有的引用信息,看看哪些部分相关。 首先,引用[3]提到了OpenPMIx,但用户可能打错了,正确的应该是OpenMPI。不过引用[3]中提到的OpenPMIx的应用场景可能和OpenMPI有类似之处,比如HPC集群、云计算平台和分布式数据库,这些可以作为参考。另外,引用[4]提到了OpenMPI的安装依赖包,说明它需要和GCC一起安装,可能涉及并行计算的环境搭建。 接下来,用户的问题具体是:OpenMPI是什么,作用,特点,使用场景。需要分别回答这四个方面。 1. **是什么**:OpenMPI是一个开源的MPI(消息传递接口)实现,用于高性能计算中的并行编程。需要解释MPI是什么,以及OpenMPI作为其实现的作用。 2. **作用**:主要作用是在分布式内存系统中实现进程间通信,支持并行计算任务的协调和数据交换。可能涉及到多节点、多进程的通信。 3. **特点**:根据引用[3]和[4],可以提到开源、跨平台、支持多种网络协议,兼容性好,易用性等。另外,引用[4]提到资源包包含依赖,说明安装方便,这也是一个特点。 4. **使用场景**:参考引用[3]中的HPC集群、云计算、分布式数据库,但需要调整成OpenMPI的典型应用,比如科学计算、大规模数值模拟、气候建模、流体动力学等。可能还要提到机器学习或者分布式训练,但要注意引用[1]指出某些情况更适合CUDA,所以可能需要区分场景。 需要注意的是,用户提供的引用中有提到OpenMP和CUDA的比较,但OpenMPI和OpenMP不同,一个是消息传递接口,另一个是共享内存的并行编程。所以需要避免混淆。 另外,用户可能将OpenMPI和OpenPMIx混淆了,但根据问题,应正确指向OpenMPI。需要确认OpenMPI的正确信息,可能结合已知知识和引用内容。 生成相关问题部分,需要围绕OpenMPI的应用、与其他技术对比、安装配置、优化方法等展开,确保问题有针对性且相关。</think>### OpenMPI 详细介绍 #### 1. **OpenMPI 是什么?** OpenMPI 是一个开源的 **消息传递接口(Message Passing Interface, MPI)** 实现,专为高性能计算(HPC)设计,支持多节点、多进程的并行编程。它提供了一套标准化接口,允许在不同计算节点之间高效传递消息,协调大规模并行任务[^3]。 --- #### 2. **作用** - **分布式内存通信**:在集群或超级计算机中,不同节点拥有独立内存,OpenMPI 通过消息传递实现跨节点的数据交换。 - **并行任务协调**:支持将复杂计算任务分解为多个子任务,分配到不同进程或节点并行执行。 - **资源管理**:与作业调度系统(如 Slurm)集成,管理计算资源分配和任务调度[^3][^4]。 --- #### 3. **特点** - **开源与跨平台**:支持 Linux、Windows、macOS 等操作系统,兼容多种硬件架构(x86、ARM 等)。 - **高性能**:优化了底层通信协议(如 InfiniBand、TCP/IP),减少消息传递延迟。 - **灵活扩展**:支持动态进程管理,可扩展至上万个计算节点。 - **兼容性**:遵循 MPI 标准,与其他 MPI 实现(如 Intel MPI)兼容。 - **易用性**:提供预编译包和依赖管理工具,简化安装流程[^4]。 --- #### 4. **使用场景** 1. **科学计算与数值模拟** - 例如:气候建模、流体动力学仿真(如计算流体力学 CFD)。 - 公式示例:$$ \frac{\partial u}{\partial t} = \nabla \cdot (D \nabla u) + S $$(扩散方程) 2. **大规模数据处理** - 分布式数据库的并行查询优化,或基因组学中的序列比对。 3. **机器学习分布式训练** - 在多 GPU/多节点环境下,通过 OpenMPI 协调参数同步(需结合 NCCL 等 GPU 通信库)[^2]。 4. **云计算与混合架构** - 在云环境中部署跨虚拟机的并行任务,例如金融风险模拟。 --- #### 代码示例(MPI 发送-接收) ```c #include <mpi.h> #include <stdio.h> int main(int argc, char** argv) { MPI_Init(&argc, &argv); int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (rank == 0) { int data = 123; MPI_Send(&data, 1, MPI_INT, 1, 0, MPI_COMM_WORLD); } else if (rank == 1) { int data; MPI_Recv(&data, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); printf("Received data: %d\n", data); } MPI_Finalize(); return 0; } ``` --- §§ 相关问题 §§ 1. OpenMPI 与 OpenMP 的区别是什么? 2. 如何配置 OpenMPI 以支持 InfiniBand 网络? 3. OpenMPI 在分布式机器学习中有哪些局限性? 4. 如何通过 OpenMPI 实现动态进程创建?
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值