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

沒有留言:

一個小故事讓我們明白資金流通的意義

“又是炎熱小鎮慵懶的一天。太陽高掛,街道無人,每個人都債台高築,靠信用度日。這時,從外地來了一位有錢的旅客,他進了一家旅館,拿出一張1000 元鈔票放在櫃檯,說想先看看房間,挑一間合適的過夜,就在此人上樓的時候---- 店主抓了這張1000 元鈔,跑到隔壁屠戶那裡支付了他欠的肉錢...