分佈式-在ubuntu12.04上安裝mpi

參考鏈接:http://jetcracker.wordpress.com/2012/03/01/how-to-install-mpi-in-ubuntu/


1. 安裝:

sudo apt-get install libcr-dev mpich2 mpich2-doc


2. 例子:

mpi_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;
}


3. 編譯以及運行:

mpicc mpi_hello.c -o hello
mpirun -np 2 ./hello

發佈了367 篇原創文章 · 獲贊 48 · 訪問量 139萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章