- 43
- 0
- 约5.09千字
- 约 10页
- 2016-12-24 发布于重庆
- 举报
并行程序设计实验报告
公共部分
1.用MPI_Send、MPI_Recv实现MPI_Bcast、MPI_Alltoall、MPI_Gather、MPI_Scatter等MPI群及通信函数功能。
_MPI_Bcast:
程序运行结果如下
伪代码如下:
_MPI_Bcast(sendbuf, sendcount, sendtype, root, comm)
对每个处理器执行以下算法
if my_rank = root then
for i = 0 to p do //p为进程个数
MPI_Send(sendbuf, sendcount, sendtype, i, root, comm) //root向每个进程发送消息
end for
end if
//每个进程从root接收带有root标签的消息,接受信息存在各自的sendbuf中
MPI_Recv(sendbuf, sendcount, sendtype, root, root, comm., status)
_MPI_Scatter:
将字符串”abcdefgh”以进程2为根散播出去,程序运行结果如下:
伪代码如下:
_MPI_Scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm)
各处理器执行以下算法
if my_rank = root then
for i = 0 to sendcount do
MPI_Send(sendbuf + i, 1, sendtype, i , root, comm)
//将sendbuf中的信息按进程标识顺序发送给各个进程
end for
end if
//每个进程从root处接收各自的消息,并存在recvbuf中第root号位置
MPI_Recv(recvbuf + root, 1, recvtype, root, root, comm., status)
_MPI_Alltoall:
进程0到进程5存储的数据分别为”000000”到”555555”,经全局交换之后运行结果如下:
伪代码如下:
_MPI_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm)
对每个处理器执行以下代码:
for i = 0 to p-1
_MPI_Scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, i, comm)
//_MPI_Scatter即为前一个程序的伪代码
//Alltoall就是每一个进程都以自己为root执行一次Scatter
end for
_MPI_Gather:
将四个进程的第3个字符汇聚到进程2,执行结果如下:
伪代码如下:
_MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm)
对每个进程执行以下代码
MPI_Send(sendbuf, sendcount, sendtype, root, root, comm)
if my_rank = root then
for i = 0 to p-1 do
MPI_Recv(recvbuf + i, recvcount, recvtype, i, root, comm., status)
end for
end if
2. LU分解的MPI实现(顺序划分)
5个节点、处理9x9矩阵时运行结果如下:
伪代码如下:
输入:矩阵A(nxn)
输出:下三角矩阵L(nxn),上三角矩阵U(nxn)
Begin
对所有处理器my_rank(0..p-1)同时执行如下算法:
for i = 0 to m-1 do //对处理器的各行**************
for j = 0 to p-1 do
if(my_rank = j) then
v = j * m + i; //当前主行************************
for k = v to n do
f[k] = a[i, k]
end for
else
v = j*m + i; //当前主行************************
接收主行所在处理器广播来的主行元素
End if
if(my_rank = j) then //编号为j的处理器对其i+1行以后各行进行变换
f
原创力文档

文档评论(0)