MPI 多机并行

主要涉及到的指令如下:

$mpdallexit

$mpdtrace -l

$mpdboot -n 5 -f  ~/mpd.hosts   /*5表示启动的结点的个数,该参数的值≤numprocs*/


Example:

//testMultiCompuParallel.c
/*求PI值*/
#include <stdio.h>
#include "mpi.h"
#define N 10000000

int main ( int argc, char *argv[] ) {
int myid, numprocs;
int i;
double t,mypi,pi;
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);
printf("Process %d of %d on %s\n",myid,numprocs,processor_name);
for (i=myid + 1; i <= N ; i += numprocs){
t = (double)(i-0.5)/N;
mypi += (double) 4 / ( t*t + 1 );
}

MPI_Reduce ( &mypi, &pi, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD );

if(myid==0){
pi *= (double)1/N;
printf("The pi is %lf\n",pi);
}

MPI_Finalize();
return 0;
}

-----------------------------------------------------------------------------------------------------------

[qq@node1 test_MultiCompuParallel]$ mpdallexit
[qq@node1 test_MultiCompuParallel]$ mpdtrace -l
mpdtrace: cannot connect to local mpd (/tmp/mpd2.console_qq); possible causes:
  1. no mpd is running on this host
  2. an mpd is running but was started without a "console" (-n option)
[qq@node1 test_MultiCompuParallel]$ mpdboot -n 5 -f ~/mpd.hosts
[qq@node1 test_MultiCompuParallel]$ mpdtrace -l
node1_48739 (10.3.1.152)
node4_39991 (10.3.1.155)
node3_57325 (10.3.1.154)
node2_38906 (10.3.1.153)
node0_35575 (10.3.1.151)
[qq@node1 test_MultiCompuParallel]$ mpicc -o testMultiCompuParallel testMultiCompuParallel.c
[qq@node1 test_MultiCompuParallel]$ mpirun -machinefile ~/mpd.hosts -np 1 testMultiCompuParallel
Process 0 of 1 on node0
The pi is 3.141593
[qq@node1 test_MultiCompuParallel]$ mpirun -machinefile ~/mpd.hosts -np 2 testMultiCompuParallel
Process 0 of 2 on node0
Process 1 of 2 on node1
The pi is 3.141593
[qq@node1 test_MultiCompuParallel]$ mpirun -machinefile ~/mpd.hosts -np 3 testMultiCompuParallel
Process 1 of 3 on node1
Process 0 of 3 on node0
Process 2 of 3 on node2
The pi is 3.141593
[qq@node1 test_MultiCompuParallel]$ mpirun -machinefile ~/mpd.hosts -np 4 testMultiCompuParallel
Process 2 of 4 on node2
Process 1 of 4 on node1
Process 0 of 4 on node0
Process 3 of 4 on node3
The pi is 3.141593
[qq@node1 test_MultiCompuParallel]$ mpirun -machinefile ~/mpd.hosts -np 5 testMultiCompuParallel
Process 3 of 5 on node3
Process 2 of 5 on node2
Process 1 of 5 on node1
Process 0 of 5 on node0
Process 4 of 5 on node4
The pi is 3.141593
[qq@node1 test_MultiCompuParallel]$ mpirun -machinefile ~/mpd.hosts -np 6 testMultiCompuParallel
too few entries in machinefile


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值