并行程序设计实验报告 公共部分 1
用MPI_Send、MPI_Recv 实现 MPI_Bcast、MPI_Alltoall、MPI_Gather、MPI_Scatter等 MPI 群及通信函数功能
_MPI_Bcast: 程序运行结果如下 伪代码如下: _MPI_Bcast(sendbu f, sendcou nt, sendty pe, root, comm) 对每个处理器执行以下算法 if my _rank = root then for i = 0 to p do //p 为进程个数 MPI_Send(sendbu f, sendcou nt, sendty pe, i, root, comm) //root 向每个进程发送消息 end for end if //每个进程从 root 接收带有 root 标签的消息,接受信息存在各自的 sendbu f 中 MPI_Recv (sendbu f, sendcou nt, sendty pe, root, root, comm
, &statu s) _MPI_Scatter: 将字符串”abcdefgh”以进程2 为根散播出去,程序运行结果如下: 伪代码如下: _MPI_Scatter(sendbu f, sendcou nt, sendty pe, recv bu f, recv cou nt, recv ty pe, root, comm) 各处理器执行以下算法 if my _rank = root then for i = 0 to sendcou nt do MPI_Send(sendbu f + i, 1, sendty pe, i , root, comm) //将 sendbu f 中的信息按进程标识顺序发送给各个进程 end for end if //每个进程从 root 处接收各自的消息,并存在