MPI庫安裝、配置及測試程式
阿新 • • 發佈:2019-02-08
序
由於專案需求,最近一段時間學習了MPI,零星的資料拼拼湊湊,終於成功搭好了~ 詳細過程記錄如下,方便日後參考~一、安裝
【1】首先從官方網站下載MPI下載官方網站相應版本的原始檔mpich-3.2,並解壓縮 【2】在/tmp/下建立目錄(如/tmp/yangrui/mpich-3.2)儲存安裝log【3】在/opt/下建立目錄/opt/mpich-install,作為安裝目錄
【4】在/tmp/yangrui/mpich-3.2下執行安裝命令:
出現Configuration completed.
【5】執行make 2>&1 | tee m.txt ;
【6】執行make install |& tee mi.txt ;
【7】配置環境變數:
如圖:執行命令vim /etc/profile #set MPI path MPI_HOME=/opt/mpich-install/bin PATH=${PATH}:${MPI_HOME} export MPI_HOME
【8】驗證安裝成功:
二、授權
在每臺伺服器的/etc/下建立hosts.equiv檔案:檔案內容:
含義:
① dell-3 user:代表允許dell-3伺服器上的使用者user本地執行遠端命令而無須提供口令;
② amax user:代表允許dell-3伺服器上的使用者user本地執行遠端命令而無須提供口令;
③+ user:代表允許使用者user從任何遠端計算機在本地執行遠端命令而無須提供口令。
三、測試命令及程式
3.1 命令
[1]編譯命令mpicc –o test test.c 或 mpicxx –o test test.cpp
[2]執行命令
單機伺服器
mpiexec –n 6 ./test 或 mpirun –np 6 ./test
說明:mpiexec 和 mpirun為執行命令,-n或-np指定執行的程序個數
=============================================================================
叢集環境下
編輯machinefile檔案,內容為伺服器名稱及其執行的程序個數
mpiexec –machinefile mf –n 6 ./test 或 mpirun –machinefile mf –np 6 ./test
3.2 測試程式
#include <math.h> void main(argc,argv) int argc; char *argv[]; { /*myid 和 numprocs分別記錄某一個並行執行程序的標識和所有參加計算的程序的個數*/ int myid, numprocs; int namelen; /*MPI_MAX_PROCESSOR_NAME為MPI預定義的巨集,代表MPI的具體實現中允許機器名字的最大長度*/ char processor_name[MPI_MAX_PROCESSOR_NAME]; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &myid); MPI_Comm_size(MPI_COMM_WORLD, &numprocs); //機器名存在processor_name中,namelen是實際機器名的長度 MPI_Get_processor_name(processor_name, &namelen); fprintf(stderr , "Hello world! Process %d of %d on %s \n", myid, numprocs, processor_name); MPI_Finalize(); }
3.3 測試結果
1臺伺服器:叢集環境下執行: