#include <iostream.h>
#include<stdio.h>
#include <mpi.h>
#define totalsize 256
#define mysize (totalsize/4)
void main(int argc,char *argv[])
{
int steps=13;
int myid,numprocs,i,j,n;
float a[mysize+2][totalsize];
float b[mysize+2][totalsize];
int begin_row;
int end_row;
int top,down;
int tag1,tag2;
MPI_Status status;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
cout<< "Process "<<' '<<myid<<' '<< " of "<<' '<< numprocs<<' '<< " is alive"<<endl;
for(i=0;i<mysize+2;i++)
{
for(j=0;j<totalsize;j++)
{
a[i][j]=0.0;
}
}
for(i=0;i<totalsize;i++)
{
a[1][i]=8.0;
a[mysize][i]=8.0;
}
tag1=3;
tag2=4;
if(myid>0)
{
top=myid-1;
}
else
{
top=MPI_PROC_NULL;
}
if(myid<3)
{
down=myid+1;
}
else
{
down=MPI_PROC_NULL;
}
for(n=0;n<steps;n++)
{
MPI_Sendrecv(&a[1][0], totalsize, MPI_FLOAT, top, tag1,& a[mysize+1][0],totalsize, MPI_FLOAT, down, tag1, MPI_COMM_WORLD, &status );/*向上数据传送*/
begin_row=1;
MPI_Sendrecv(&a[mysize][0], totalsize, MPI_FLOAT, down, tag2,& a[0][0],totalsize, MPI_FLOAT, top, tag2,MPI_COMM_WORLD, &status );/*向下数据传送*/
end_row=mysize;
if(myid==0)
{
begin_row=2;
}
if(myid==3)
{
end_row=mysize-1;
}
for(i=begin_row;i<=end_row;i++)
for(j=1;j<=totalsize;j++)
b[i][j]=(a[i][j+1]+a[i][j-1]+a[i+1][j]+a[i-1][j])*0.25;
for(i=begin_row;i<=end_row;i++)
for(j=1;j<=totalsize;j++)
a[i][j]=b[i][j];
}
if(myid==1)
{
for(i=mysize-8;i<mysize;i++)
{
for(j=1;j<=4;j++)
{
printf("%f ",a[i][j]);
}
cout<<endl;
}
}
MPI_Finalize();
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
lpi.c.rar (39个子文件)
l3pcf.c 2KB
SoundTutorial
bin
classes.dex 7KB
com
Tutorial
Sound
Activity2$1.class 1016B
SoundManager.class 2KB
SoundTutorial$1.class 1KB
SoundTutorial$2.class 851B
R$layout.class 427B
Activity2.class 1KB
R$id.class 500B
R$drawable.class 488B
SoundTutorial$3.class 851B
Activity2$2.class 827B
R$attr.class 340B
R.class 575B
Activity2$3.class 827B
SoundTutorial.class 2KB
R$string.class 427B
R$raw.class 423B
resources.ap_ 67KB
SoundTutorial.apk 72KB
res
raw
starwars.wav 13KB
terminator.wav 27KB
drawable
soundactivitybgmain.jpg 10KB
soundactivitybgsecond.jpg 10KB
icon.png 3KB
values
strings.xml 177B
layout
main.xml 1015B
activity2.xml 1017B
assets
default.properties 449B
gen
com
Tutorial
Sound
R.java 1KB
src
com
Tutorial
Sound
SoundManager.java 3KB
Activity2.java 2KB
SoundTutorial.java 2KB
.project 849B
.classpath 280B
AndroidManifest.xml 733B
lpi.c 1KB
3pcf.c 2KB
mpi
mpi.txt 2KB
共 39 条
- 1
资源评论
朱moyimi
- 粉丝: 61
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功