# Linux下MPI并行编程环境搭建配置

MPI的全称是Message Passing Interface即标准消息传递界面，可以用于并行计算。MPI有多种实现版本，如MPICH， CHIMP以及OPENMPI。这里我们采用MPICH版本。

tar -xzvf soft/mpich-3.0.4.tar.gz
cd mpich-3.0.4/
./configure --prefix=/usr/local/mpich
make && make install

PATH=$PATH:/usr/local/mpich/bin MANPATH=$MANPATH:/usr/local/mpich/man
export PATH MANPATH

cp -r examples/ /usr/local/mpich

mpirun -np 10 ./examples/cpi

Process 0 of 10 is on server150
Process 9 of 10 is on server150
Process 1 of 10 is on server150
Process 4 of 10 is on server150
Process 5 of 10 is on server150
Process 7 of 10 is on server150
Process 2 of 10 is on server150
Process 3 of 10 is on server150
Process 6 of 10 is on server150
Process 8 of 10 is on server150

pi is approximately 3.1415926544231256, Error is 0.0000000008333325
wall clock time = 0.020644

2、复制编译程序到其他机器上面

scp -r mpich server140:/usr/local/
scp -r mpich server151:/usr/local/
scp -r mpich server130:/usr/local/
scp -r mpich server143:/usr/local/

3、

server150:2 #run 2 process
server140:2
server130:2
server143:2
server151:2

mpiexec -n 10 -f servers ./examples/cpi

Process 0 of 10 is on server150
Process 1 of 10 is on server150
Process 4 of 10 is on server140
Process 5 of 10 is on server140
Process 6 of 10 is on server143
Process 7 of 10 is on server143
Process 8 of 10 is on server130
Process 9 of 10 is on server130
Process 2 of 10 is on server151
Process 3 of 10 is on server151
pi is approximately 3.1415926544231256, Error is 0.0000000008333325
wall clock time = 0.018768

• 写评论