centos中mpich的安裝及使用


https://www.itdaan.com/blog/2017/04/29/4184b453ec6c.html

安裝(騰訊雲centos 6.5 64位)

  • yum list mpich* 查看有什么版本的mpich包,在此處有版本2的,所以裝版本2的
  • yum install mpich2 mpich2-devel mpich2-doc
  • which mpicc 發現找不到該命令
  • find / -name "mpich" 然后會找到mpich的目錄,可能會有好幾個,有bin的那個就是我們要找的目錄
  • cd ~
  • vi .bashrc
  • 在后面加上MPI_ROOT=/usr/lib64/mpich
  • export PATH=$MPI_ROOT/bin:$PATH 這里的目錄視具體情況而定
  • source .bashrc 使之生效

使用(新建文件hello.c)

#include <mpi.h>
#include <stdio.h>
#include <math.h>
int main(int argc,char* argv[])
{
    int myid, numprocs;
    int namelen;
    char processor_name[MPI_MAX_PROCESSOR_NAME];

    MPI_Init(&argc,&argv);/* 初始化並行環境 */
    MPI_Comm_rank(MPI_COMM_WORLD,&myid);/* 當前進程的ID號 */
    MPI_Comm_size(MPI_COMM_WORLD,&numprocs);/* 進程的總數 */
    MPI_Get_processor_name(processor_name,&namelen);/* 當前處理器的名稱 */

    fprintf(stderr,"Hello World! Process %d of %d on %s\n",
                  myid, numprocs, processor_name);

    MPI_Finalize();/* 結束並行環境 */
    return 0;
}

 

  • 1
mpicc -o hello hello.c
mpirun -np 4 ./helloc

centos7(自測成功)

yum -y mpich*

[root@localhost ~]# yum -y mpich*
Loaded plugins: fastestmirror
No such command: mpich*. Please use /usr/bin/yum --help
[root@localhost ~]# yum list mpich*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * epel: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.163.com
 * updates: mirrors.163.com
Installed Packages
mpich-3.0.x86_64                                                                                                                           3.0.4-10.el7                                                                                                                  @base
mpich-3.0-devel.x86_64                                                                                                                     3.0.4-10.el7                                                                                                                  @base
mpich-3.0-doc.noarch                                                                                                                       3.0.4-10.el7                                                                                                                  @base
Available Packages
mpich-3.0.i686                                                                                                                             3.0.4-10.el7                                                                                                                  base 
mpich-3.0-autoload.x86_64                                                                                                                  3.0.4-10.el7                                                                                                                  base 
mpich-3.0-devel.i686                                                                                                                       3.0.4-10.el7                                                                                                                  base 
mpich-3.2.i686                                                                                                                             3.2-2.el7                                                                                                                     base 
mpich-3.2.x86_64                                                                                                                           3.2-2.el7                                                                                                                     base 
mpich-3.2-autoload.x86_64                                                                                                                  3.2-2.el7                                                                                                                     base 
mpich-3.2-devel.i686                                                                                                                       3.2-2.el7                                                                                                                     base 
mpich-3.2-devel.x86_64                                                                                                                     3.2-2.el7                                                                                                                     base 
mpich-3.2-doc.noarch                                                                                                                       3.2-2.el7                                                                                                                     base

 

yum install mpich3 mpich3-devel mpich3-doc  #不可以,單獨運行下面的
yum install mpich-3.0.x86_64 
yum install mpich-3.0-devel.x86_64
yum install mpich-3.0-doc.noarch

  

 


Linux下MPI並行編程環境搭建配置

本文永久鏈接地址: http://www.lifeba.org/arch/linux_mpi.html

MPI的全稱是Message Passing Interface即標准消息傳遞界面,可以用於並行計算。MPI有多種實現版本,如MPICH, CHIMP以及OPENMPI。這里我們采用MPICH版本。

一、MPICH安裝

下載:http://www.mpich.org/static/downloads/3.0.4/mpich-3.0.4.tar.gz

tar -xzvf soft/mpich-3.0.4.tar.gz
cd mpich-3.0.4/
./configure --prefix=/usr/local/mpich
make && make install

安裝后加入環境變量/etc/profile,並執行 source /etc/profile

PATH=$PATH:/usr/local/mpich/bin
MANPATH=$MANPATH:/usr/local/mpich/man
export PATH MANPATH

二、單節點測試

復制源代碼包下的examples目錄到安裝目錄下

cp -r examples/ /usr/local/mpich

執行

mpirun -np 10 ./examples/cpi

輸出結果如下:

Process 0 of 10 is on server150
Process 9 of 10 is on server150
Process 1 of 10 is on server150
Process 4 of 10 is on server150
Process 5 of 10 is on server150
Process 7 of 10 is on server150
Process 2 of 10 is on server150
Process 3 of 10 is on server150
Process 6 of 10 is on server150
Process 8 of 10 is on server150

pi is approximately 3.1415926544231256, Error is 0.0000000008333325
wall clock time = 0.020644

如果我們現在想編譯文件: 在/home/houqingdong下執行:  mpicc -o hello  hello.c 這時候會提醒:-bash:mpicc  command not found 這是因為我們還沒有配置路徑

在命令行下輸入: export PATH=/home/houqingdong/mpiexe/bin:$PATH  注意:這里僅僅是暫時的設置路徑,在重啟后效果會消失,如果想一勞永逸的配置,請google查詢

看一下我們配置是否成功可以執行一下  echo $PATH 看一下輸出結果中是否有我們的路徑

  

三、集群配置

1、集群機器上面需要配置ssh登錄權限。參考:Hadoop-0.21.0在linux分布式集群配置  中的ssh配置(密鑰無密碼登錄)部分。

2、復制編譯程序到其他機器上面

scp -r mpich server140:/usr/local/
scp -r mpich server151:/usr/local/
scp -r mpich server130:/usr/local/
scp -r mpich server143:/usr/local/

同時在每台機器上面相應加入環境變量中。

3、
在/usr/local/mpich 下新建servers文件,內容如下:

server150:2 #run 2 process
server140:2
server130:2
server143:2
server151:2

執行下面命令,並指定servers文件

mpiexec -n 10 -f servers ./examples/cpi

輸出

Process 0 of 10 is on server150
Process 1 of 10 is on server150
Process 4 of 10 is on server140
Process 5 of 10 is on server140
Process 6 of 10 is on server143
Process 7 of 10 is on server143
Process 8 of 10 is on server130
Process 9 of 10 is on server130
Process 2 of 10 is on server151
Process 3 of 10 is on server151
pi is approximately 3.1415926544231256, Error is 0.0000000008333325
wall clock time = 0.018768

四、參考資料

 
 


免責聲明!

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



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