LoginSignup
5
0

More than 1 year has passed since last update.

Microsoft MPI(MS-MPI)の導入から実行まで

Posted at

はじめに

MS-MPIを使ってみたので、メモを残します。Visual Studioでなく、clangを使って、コマンドプロンプト(もしくはPowerShell)でコードをコンパイルする方法で利用します。

環境

  • Windows 10 home x64
  • clang++(7.0.1)
  • emacs(26.2)

MS_MPIのインストール

MS-MPIのサイトDownloadsを選択します。
image.png

Downloadボタンを押します。
image.png

ダウンロードするファイル選択をする画面が出てきます。コードをコンパイルし、実行する必要があるので、MS-MPIとMS-MPI SDKどちらもダウンロードします。

それぞれのファイルをインストールします。インストールパスはデフォルトです。
image.png

image.png

コンパイラ

clang++を利用してコマンドラインでコンパイルします。clang++を利用するため、llvmをダウンロードし、インストールします。llvmのほかMSBuild toolsを入れておきます。clang++コマンドをコマンドプロンプトで実行するため、llvm/binのパスを通します。

set PATH=%PATH%;"C:\Program Files\LLVM\bin"

プログラムの作成

テストプログラムとして、ランク表示をするだけのプログラムを作成します。(参考:https://www.hpci-office.jp/materials/MPI-2017-03-23.pdf)

sample.cpp
#include <iostream>
#include <mpi.h>
using namespace std;
int main(int argc, char*argv[])
{
  int size, rank;
  MPI_Init(&argc, &argv);
  MPI_Comm_size(MPI_COMM_WORLD, &size);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  cout << "Hello world I am "  << rank << " of " << size <<endl;
  MPI_Finalize();
  return 0;
}

プログラムのコンパイル

include pathとlibrary pathを指定してコンパイルします。

clang++ sample.cpp -I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include" -L"C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64" -lmsmpi

実行

mpiexec -n 7 a.exe

で実行します。MS-MPIをインストールすると環境変数PATHに"C:\Program Files\Microsoft MPI\Bin\"が自動的に追加されますが、もし、mpiexecがないといわれたら下のようにフルパスで実行するか、環境変数PATHに"C:\Program Files\Microsoft MPI\Bin\"を追記します。

"C:\Program Files\Microsoft MPI\Bin\mpiexec.exe" -n 7 a.exe

mpi_run_only.png

5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0