MPI广播
2017-04-02 18:04
106 查看
/*------------------------MPI广播---------------------------*/ // Broadcasts a message from the process with rank "root" // to all other processes of the communicator,include itself. // 以某个进程作为根进程将buffer广播给同通信域中的所有进程. #include "mpi.h" #include <stdio.h> #define N 3 int main(int argc, char *argv[]) { int i, myrank, nprocs; int buffer ; //广播数据缓存 MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &myrank); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); //为每一个进程的buffer缓存赋初始值 printf("-------------------------------------------------\n"); printf("myrank = %d\nbefore bcasting my buffer's data is:\n", myrank); for (i = 0; i < N; i++) { buffer[i] = myrank+i; printf("buffer[%d] = %d\n",i, buffer[i]); } printf("\n"); /*---------------------------MPI_Bcast详解--------------------------*/ //功能: // broadcasts a message from the process with rank root to all // processes of the group, itself included. // 以某个进程作为根进程将buffer广播给同通信域中的所有进程. // On return, the contents of root's communication buffer has // been copied to all processes. // 函数返回后根进程数据缓冲区的数据将被拷贝到该通信域所有进程各自 // 的数据缓冲区中去 //函数参数: // MPI_Bcast(数据缓存地址,数据个数,数据类型,数据发送进程[root]的标识,通信域) MPI_Bcast(buffer, N, MPI_INT, 0, MPI_COMM_WORLD); /*结果输出*/ printf("after bcasting my buffer's data is:\n"); for (i = 0; i < N; i++) printf("buffer[%d] = %d\n", i, buffer[i]); printf("\n"); MPI_Finalize(); return 0; }
相关文章推荐
- 安装OpenMPI来配合C语言程序进行并行计算
- MPICH2(r8733)的错误容忍
- MPI单机多机方法
- MPI并行实现枚举排序
- 并行计算学习笔记(MPI)
- MPI通信域划分及新通信域各进程间的点对点阻塞式通信
- MPI函数列表
- pmpi简单实例
- MPI笔记
- MVAPICH2多线程支持问题
- ubuntu下MPICH的安装以及多机环境运行
- 基于单边Jacobi旋转的并行SVD算法-MPI框架
- MPI 学习笔记
- ubuntu16.04一步一步安装配置mpich
- MPI集体通讯(一)
- MS-MPI+boost 编译
- Application of Boost MPI
- Boost mpi gatherv example
- MPI安装步骤
- 实现并行运算的方法汇总