MPI聚合通信之MPI_Bcast函数
2014-05-25 15:20
232 查看
MPI_Bcast函数指一个进程(称为根进程)同时发送同样的消息给通信器中的所有其它进程。
如下面的例子中,0进程对数组进行了赋值,随后通过Bcast()函数广播出去,其它的进程在收到后将数组打印出来。
输出结果为:
如下面的例子中,0进程对数组进行了赋值,随后通过Bcast()函数广播出去,其它的进程在收到后将数组打印出来。
#include "stdio.h" #include "mpi.h" int main(int argc,char **argv) { int size,rank; static int max=20; int h[max]; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&size); MPI_Comm_rank(MPI_COMM_WORLD,&rank); if(rank==0) { for(int i=0;i<max;i++) h[i]=i+rank; } //sprintf(c,"highcomputing"); MPI_Bcast(h,max,MPI_INT,0,MPI_COMM_WORLD); if(rank) { printf("process %d is running\n",my_rank); for(int i=0;i<max;i++) { printf("%d ",h[i]); } printf("\n"); } MPI_Finalize(); return 0; }
输出结果为:
process 1 is running 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 process 2 is running 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 process 3 is running 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
相关文章推荐
- MPI之聚合通信-Scatter,Gather,Allgather
- MPI聚合通信之MPI_Gather函数
- MPI之聚合通信-Scatter,Gather,Allgather
- MPI之聚合通信-Scatter,Gather,Allgather
- MPI之聚合通信collective communication-广播
- MPI之聚合通信-Scatter,Gather,Allgather
- MPI之聚合通信collective communication-广播
- MPI之聚合通信-Scatter,Gather,Allgather
- MPI之聚合通信collective communication-广播
- MPI之聚合通信-Scatter,Gather,Allgather
- MPI之聚合通信collective communication-广播
- MPI之聚合通信-Scatter,Gather,Allgather
- MPI学习-聚合通信
- MPI之聚合通信collective communication-广播
- MPI之聚合通信-Scatter,Gather,Allgather
- MPI之聚合通信collective communication-广播
- MPI之聚合通信collective communication-广播
- MPI之聚合通信collective communication-广播
- MPI之聚合通信collective communication-广播
- MPI之聚合通信collective communication-广播