Amazon Web ServiceでMPI Cluster構築

MPIの基本

#include <mpi.h>
#include <stdio.h>
#include <string.h>

#define LENGTH 200
int main(int argc, char* argv[]){

  int my_rank;
  char message[LENGTH];
  int dest = 0;
  int tag = 0;

  // 初期化
  MPI_Init(&argc, &argv);

  // プロセス・ランク
  MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

  if(my_rank!=0){ // 送信側

    sprintf(message, "Hello, my proc rank : %d", my_rank);
    MPI_Send( message, strlen(message)+1, MPI_CHAR, dest, tag, MPI_COMM_WORLD);

  }else{ // 受信側

    int proc_num;
    int source;
    MPI_Status recv_status;

    MPI_Comm_size(MPI_COMM_WORLD, &proc_num);

    for(source=1; source<proc_num; source++){
      MPI_Recv(message,LENGTH, MPI_CHAR, source, tag, MPI_COMM_WORLD, &recv_status);
      fprintf(stdout, "%s\n", message);
    }
  }
  MPI_Finalize();
}
⇒  mpirun -np 8 a.out
Hello, my proc rank : 1
Hello, my proc rank : 2
Hello, my proc rank : 3
Hello, my proc rank : 4
Hello, my proc rank : 5
Hello, my proc rank : 6
Hello, my proc rank : 7

参考

MPI

MPIでhelloを作成してみる.

http://h50146.www5.hp.com/solutions/hpc/stc/soft/pdfs/mpi_training.pdf

shuns.sblo.jp

starcluster

Launching an Amazon EC2 MPI Cluster · MPI Tutorial

Using the Cluster — StarCluster 0.93.3 documentation