2015年11月28日 星期六

MPI & MPE Helloworld

這次來介紹MPI搭配MPE(MPI Parallel Environment)來tracing程式的運作
主程式hello.c跟先前的相同, 程式碼如下:
/* C Example */
#include <mpi.h>
#include <stdio.h>

int main (int argc, char* argv[])
{
  int rank, size;

  MPI_Init (&argc, &argv);      /* starts MPI */
  MPI_Comm_rank (MPI_COMM_WORLD, &rank);        /* get current process id */
  MPI_Comm_size (MPI_COMM_WORLD, &size);        /* get number of processes */
  printf( "Hello world from process %d of %d\n", rank, size );
  MPI_Finalize();
  return 0;
}
Makefile內容如下:
all:
        mpecc -mpitrace -o hello hello.c

mpirun -np 5 ./hello 執行的結果如下:
Starting MPI_Init...
Starting MPI_Init...
Starting MPI_Init...
Starting MPI_Init...
Starting MPI_Init...
[0] Ending MPI_Init
[0] Starting MPI_Comm_rank...
[0] Ending MPI_Comm_rank
[0] Starting MPI_Comm_size...
[0] Ending MPI_Comm_size
Hello world from process 0 of 5
[0] Starting MPI_Finalize...
[0] Ending MPI_Finalize
[1] Ending MPI_Init
[1] Starting MPI_Comm_rank...
[1] Ending MPI_Comm_rank
[1] Starting MPI_Comm_size...
[1] Ending MPI_Comm_size
Hello world from process 1 of 5
[1] Starting MPI_Finalize...
[1] Ending MPI_Finalize
[2] Ending MPI_Init
[2] Starting MPI_Comm_rank...
[2] Ending MPI_Comm_rank
[2] Starting MPI_Comm_size...
[2] Ending MPI_Comm_size
Hello world from process 2 of 5
[2] Starting MPI_Finalize...
[3] Ending MPI_Init
[3] Starting MPI_Comm_rank...
[3] Ending MPI_Comm_rank
[3] Starting MPI_Comm_size...
[3] Ending MPI_Comm_size
Hello world from process 3 of 5
[3] Starting MPI_Finalize...
[4] Ending MPI_Init
[4] Starting MPI_Comm_rank...
[4] Ending MPI_Comm_rank
[4] Starting MPI_Comm_size...
[4] Ending MPI_Comm_size
Hello world from process 4 of 5
[4] Starting MPI_Finalize...
[2] Ending MPI_Finalize
[3] Ending MPI_Finalize
[4] Ending MPI_Finalize

沒有留言: