在所有的節點上,做下面的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操作,并顯示結果在主節點上。