企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
在所有的节点上,做下面的1—3操作 1,安装openmpi http://www.open-mpi.org/software/ompi/v1.6/ 之前系统默认带有openMPI,先把旧的删掉 2,配置无密码ssh登录: 请参考:[如何配置无密码SSH](http://hanhuzi.blogspot.com/2008/09/ssh.html) 3,在工作目录下编制配置文件(文件名随意),内容包括所有节点的名称,例如: ~~~ #>cat hosts host1 slots=4 host2 slots=4 host3 slots=4 ~~~ ———————— 所有节点上的工作目录必需相同,配置文件名和内容也必需相同,简单的办法是所有节点的工作目录都mount到同一个nfs输出上 ———————— 在主节点上写程序并编译执行4—8 4,例子程序: ~~~ [root@dhcp-beijing-cdc-10-182-120-155 ~]# cat hello.c #include #include "mpi.h" int main(int argc, char *argv[]) { int nproc; int iproc; char proc_name[MPI_MAX_PROCESSOR_NAME]; int nameLength; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&nproc); MPI_Comm_rank(MPI_COMM_WORLD,&iproc); MPI_Get_processor_name(proc_name,&nameLength); printf("Hello World, Iam host %s with rank %d of %d\n", proc_name,iproc,nproc); MPI_Finalize(); return 0; } ~~~ 5,编译这个例子: ~~~ mpicc -o hello hello.c ~~~ 6,拷贝可执行文件hello到所有节点的相同工作目录(如果使用nfs可忽略此步) 7,执行hello ~~~ #> mpirun -np 2 hello -hostfiles hosts mpirun -hostfile ./hosts ./hello_cxx ~~~ (上面的数字2代表在两个节点上运行hello) 此时,是不是已经看到了来自其它节点的问候? 8,当然,你可以用其他命令来替换hello比如: ~~~ #> mpirun -np 3 ls -hostfiles hosts ~~~ 此命令在各节点上执行ls操作,并显示结果在主节点上。