一、簡介
通過安裝MPICH構建MPI編程環境,從而進行並行程序的開發。MPICH是MPI(Message-Passing Interface)的一個應用實現,支持最新的MPI-2接口標准,是用於並行運算的工具。
二、安裝配置
http://www.cnblogs.com/liyanwei/archive/2010/04/26/1721142.html http://blog.csdn.net/yujiflying/article/details/7206961
三、程序示例
//hello.c
#include "mpi.h"
#include <stdio.h>
#include <math.h>
int main (int argc, char **argv)
{
int myid, numprocs;
int namelen;
char processor_name[MPI_MAX_PROCESSOR_NAME];
MPI_Init (&argc, &argv);
MPI_Comm_rank (MPI_COMM_WORLD, &myid);
MPI_Comm_size (MPI_COMM_WORLD, &numprocs);
MPI_Get_processor_name (processor_name, &namelen);
fprintf (stderr, "Hello World! Process %d of %d on %s\n", myid, numprocs, processor_name);
MPI_Finalize ();
return 0;
}
編譯
mpicc -o hello hello.c
運行
Hello World! Process 1 of 4 on jack-laptop Hello World! Process 3 of 4 on jack-laptop Hello World! Process 2 of 4 on jack-laptop Hello World! Process 0 of 4 on jack-laptop