1. 程式人生 > >MPI 在Windows10 上安裝,使用VS2013編譯生成可執行程序

MPI 在Windows10 上安裝,使用VS2013編譯生成可執行程序

main int 附加 處理 shift window lib color 參考

參考博客: http://www.cnblogs.com/shixiangwan/p/6626156.html

      http://www.cnblogs.com/hantan2008/p/5390375.html

系統環境:

  Windows10  (Windows7及以上均可以)

  64bit

  VS2013

1. 下載並安裝MPICH For Windows

  進入http://www.mpich.org/downloads/站點根據操作系統下載。由於我們使用的是Windows,拉到下載網頁最底部,最新的MPICH實現已經由微軟官網托管,我們直接進去下載。

  技術分享

  然後,選擇最新的V8下載,包含兩個文件:msmpisdk.msi和MSMpiSetup.exe。

  技術分享

  下載完畢直接分別安裝這兩個程序 msmpisdk.msiMSMpiSetup.exe

  我安裝在了D盤

    技術分享

    技術分享 

2. VS配置以及demo演示

  新建一個VC++項目

  技術分享

  在項目屬性中配置修改如下:

    包含目錄裏面添加:C:\Program Files (x86)\Microsoft SDKs\MPI\Include;

    庫目錄的裏面添加:C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64;

  技術分享 

  其他必要配置:

    配置管理器,選擇x64編譯平臺;

    C/C++ -> 預處理器,添加:MPICH_SKIP_MPICXX;

    C/C++ -> 代碼生成 -> 運行庫,選擇:多線程調試(/MTd);

    鏈接器 -> 輸入 -> 附加依賴項,添加:msmpi.lib;

    技術分享

  demo測試,新建一個C++文件,命名為main.cpp

 1 #include<stdio.h>
 2 #include<mpi.h>
 3 #include<stdlib.h>
 4 #include<time.h>
 5 
 6 int main(int argc, char* argv[])
 7 {
 8     int myid, numprocs, namelen;
9 char processor_name[MPI_MAX_PROCESSOR_NAME]; 10 11 MPI_Init(&argc, &argv); // starts MPI 12 MPI_Comm_rank(MPI_COMM_WORLD, &myid); // get current process id 13 MPI_Comm_size(MPI_COMM_WORLD, &numprocs); // get number of processes 14 MPI_Get_processor_name(processor_name, &namelen); 15 16 if (myid == 0) printf("number of processes: %d\n...", numprocs); 17 printf("%s: Hello world from process %d \n", processor_name, myid); 18 19 MPI_Finalize(); 20 21 return 0; 22 }

  編譯整個項目,將編譯(1.項目右鍵重新生成 或者 2.使用編輯器編譯得到)得到的 exe文件(debug文件夾下)放在安裝的MS-MPI的bin目錄(默認為:C:\Program Files\Microsoft MPI\Bin 我安裝在了D盤)下,在這個Bin目錄下按住shift鍵於空白處右鍵單擊,打開命令行窗口,輸入 mpiexec -n 10 MPI-demo.exe 得到運行結果,如下圖:

  技術分享

  技術分享

MPI 在Windows10 上安裝,使用VS2013編譯生成可執行程序