并行程序设计实验报告 公共部分 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 处接收各自的消息,并存在 recv bu f 中第 root 号位置 MPI_Recv (recv bu f + root, 1, recv ty pe, root, root, comm., &statu s) _MPI_Alltoall: 进程 0 到进程 5 存储的数据分别为”000000”到”555555”,经全局交换之后运行结果如下: 伪代码如下: _MPI_Alltoall(sendbu f, sendcou nt, sendty pe, recv bu f, recv cou nt, recv ty pe, comm) 对每个处理器执行以下代码: for i = 0 to p-1 _MPI_Scatter(sendbu f, sendcou nt, sendty pe, recv bu f, recv cou nt, recv ty pe, i, comm) //_MPI_Scatter 即为前一个程序的伪代码 //Alltoall 就是每一个进程都以自己为root 执行一次 Scatter end for _MPI_Gather: 将四个进程的第 3 个字符汇聚到进程 2,执行结果如下: 伪代码如下: _MPI_Gather(sendbu f, sendcou nt, sendty pe, recv bu f, recv cou nt, recv ty pe, root, comm) 对每个进程执行以下代码 MPI_Send(sendbu f, sendcou nt, sendty pe, root, root, c...