openMPI小集群安裝


經過一天的努力,終於完成了openMPI的多節點安裝,即小集群安裝。本文使用的是openmpi-1.6.5,下載地址見:http://www.open-mpi.org/software/ompi/v1.6/

1.安裝准備

1.1 首先肯定是需要安裝GCC和G++編譯器,這個直接apt-get就OK了;

sudo apt-get g++ gfortran

1.2 設置主機名

先在/etc/hosts中刪除原來的hostname,然后 vi /etc/hostname改成你想要的,注意必須頂行寫。然后使用hostname命令來重新得到hostname, logout一下再login就會改掉。

這里我用的是node1-ubuntu和node2-ubuntu。

1.3 修改hosts文件,修改如下:

 192.168.1.133    node1-ubuntu server
 192.168.1.135    node2-ubuntu

1.4 配置自動ssh登錄

這里主要是要各個機器之間能無密碼訪問,主要用到的就是SSH,因此需要一些設置。

首先,我們需要導出各個節點的公鑰和私鑰:

$ ssh-keygen -t rsa 

在運行過程中,會提示你輸入這個輸入那個,不用管那么多,直接回車就完了。等運行結束后,進入.ssh目錄,你會看到公鑰和私鑰文件;

$ cd ~/.ssh 
$ ls  
id_rsa   id_rsa.pub  

其中id_rsa就是私鑰,id_rsa.pub就是公鑰,現在我們需要把各個節點上的公鑰都集中發送到一個節點上,來制作授權文件(authorized_keys).

注意:在兩台機器必須安裝ssh(sudo apt-get install ssh openssh-server)而且必須設置root密碼(sudo passwd root),才能遠程登錄

$ scp ~/.ssh/id_rsa.pub node1-ubuntu:~/.ssh/1.pub

在將node2-ubuntu拷貝到node1-ubuntu后,在node1-ubuntu進行如下處理:

$ cp ~/.ssh/id_rsa.pub authorized_keys  
$ cat ~/.ssh/1.pub >> authorized_keys  

在node1-ubuntu上制作好的authorized_keys拷貝到node2-ubuntu上:(node1-ubuntu使用scp)

$ scp ~/.ssh/authorized_keys node2-ubuntu:~/.ssh/

要想讓這兩台機器無密碼登錄,所以我們需要更改一下必要的文件的權限(所有節點都要更改):其實只要保證authorized_keys的文件權限為600或者644

$ chmod 755 ~  
$ chmod 755 ~/.ssh  
$ chmod 600 ~/.ssh/authorized_keys  
$ chmod 600 ~/.ssh/id_rsa  
$ chmod 644 ~/.ssh/id_rsa.pub  

至此,SSH配置就完成了。下面檢驗一下:

在一個主機上面SSH另一個主機:

$ ssh node1-ubuntu

 

2.安裝openMPI

2.1  首先將下載的文件解壓,下載的文件在當前用戶目錄里面的“下載”目錄里面,我直接解壓到當前目錄:

$ tar xvfz openmpi-1.6.5.tar.gz  

2.2 安裝官方文檔配置的,可以查看解壓后的README文檔參考:由於是bash,因此選擇以下命令,prefix指示安裝路徑,USERNAME就是當前用戶的用戶名,,

在此之前當然要建立安裝openMPI的路徑,也就是:

$ mkdir openmpi

運行shell程序configure對openmpi進行一些配置,關於configure選項,參見openmpi-1.6.5下的README文件。

$ ./configure --prefix=/home/<USERNAME>/openmpi  2>&1 | tee install1.log  

而且在之前的安裝過程中,我發現如果不禁止fortran,安裝會出問題,會導致openMPI安裝不完全而出錯,是因為沒有安裝fortran編譯器,如果使用C/C++的話,這里建議禁用fortran。

接下來,編譯和安裝:

$ make all 2>&1 | tee make.log  
$ make install 2>&1 | tee install2.log  

安裝完成后,會有如下情況:

至此,OpenMPI安裝完成。

2.3 設置進程的配置環境

這里設置環境變量主要是將openmpi的安裝目錄加到系統環境變量中,這里我在/etc/environment中加入對應的路徑:

用vim編輯器打開/etc/environment:

$ sudo vim /etc/environment

輸入密碼之后,將下面語句添加到最后一行:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/awy/openmpi/bin"
LD_LIBRARY_PATH=/home/awy/openmpi/lib

3.驗證是否成功:

1 3 $ which mpicc
4 /home/awy/openmpi/bin/mpicc
5 $ which mpiexec
6 /home/awy/openmpi/bin/mpiexec
7 $ which mpirun
8 /home/awy/openmpi/bin/mpirun

這樣就說明openmpi已經安裝成功了。

 

運行安裝目錄中examples下的例子,在此之前,先編譯下make:

mpiexec -np 2 ./openmpi-1.6.5/examples/hell_f90

4 配置機器數量以及進程數

用vim編輯一個文件命名為hosts:如果你想在一個節點上運行多個進程,那么hostfile 可以使用 "slots" 屬性。如果沒有指定"slots",那么將假設其數目為1.

node1-ubuntu
node2-ubuntu

或者

node1-ubuntu    slots=4
node2-ubuntu    slots=2

讓兩個節點並行運行例子程序,如下所示:

$ mpiexec -hostfile hosts -np 8 ./openmpi-1.6.5/examples/hello_f90

 

5.安裝過程中遇到的問題:

1.出現這種錯誤./openmpi-1.6.5/examples/hello_f90: error while loading shared libraries: libmpi_f77.so.1: cannot open shared object file: No such file or directory,或者

bash: orted: command not found
--------------------------------------------------------------------------
A daemon (pid 27974) 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.
--------------------------------------------------------------------------
mpiexec: clean termination accomplished

說明是LD_LIBRARY_PATH為空,可以進行這樣查看:

mpiexec -n 1 printenv | grep PATH

查看LD_LIBRARY_PATH,如果沒有,則可以進行如下操作:

$    source /etc/environment
$    export LD_LIBRARY_PATH

如此,便可以成功了。

2.如果要在IPv6的環境下運行openMPI,則安裝的時候要開啟:即在./configure --prefix=/home/<username>/openmpi --enable-ipv6,這樣便可以了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM