//Writed by YaoPu, Oct 10,2016
//if any question, send email to yaopu@iccas.ac.cn
#include"mpi.h"
#include"stdio.h"
int main(int argc,char **argv)
{
MPI_Init(&argc,&argv);
int np,rank;
MPI_Status status;
MPI_Comm_size(MPI_COMM_WORLD,&np);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
int A[3][3]={1,2,3,4,5,6,7,8,9};
int x[3]={3,2,1};
int B[3]={0};
int y=x[rank];
int mp1 =(rank+1)%np;
int mm1=(rank-1+np)%np;
for (int i=0;i<3;i++)
{
B[rank]+=A[rank][(rank+i)%3]*y;
if(i!=2){
MPI_Send(&y,1,MPI_INT,mm1,0,MPI_COMM_WORLD);
MPI_Recv(&y,1,MPI_INT,mp1,0,MPI_COMM_WORLD,&status);
}
}
printf("%d on rank %d process\n",B[rank],rank);
MPI_Finalize();
}
matrix2
最新推荐文章于 2023-03-27 17:43:30 发布