program examplel include "mpifh" IMPI系统头文件 integer status(MPI_STATUS_SIZE).my_rank,p,source,dest,tag.ierr,data c-进入MPI系统 call MPI Init(ier)) call MPI_Comm_rank(MPI_COMM_WORLD.my_rank.ierr) call MPI_Comm_size(MPI_COMM_WORLD.p.ierr) C。一数据交换 data=0 tag =5 source=my_rank-1 if(source.eq.-1)source=p-1 dest =my rank+l if(dest.eq-p)dest=0 if(my_rank.eq.0)then calIMPI_Send(data.1.MPI_INTEGER.dest.tag.MPI_COMM_WORLD.ierr) call MPI_Reev(data.1.MPI_INTEGER.source.tag.MPI_COMM_WORLD.status.ierr) else call MPI_Recv(data,1,MPI_INTEGER.source,tag.MPI_COMM_WORLD.status,ierr) data=data+l MPI Send(data.1.MPI INTEGER.dest,tag MPI_COMM WORLD.ic 。一广播数据 call MPI_Bcast(data.1.MPI_INTEGER.0.MPI_COMM_WORLD.ierr) c C一打印输出 if(my_rank.eq.0)then if(data.eq.p-1)then print"Successful,data=".data endif c call MPI Finalize(ierr) end12 program example1 include “mpif.h” !! MPI 系统头文件 integer status(MPI_STATUS_SIZE),my_rank,p,source,dest,tag,ierr,data c c-------进入 MPI 系统 call MPI_Init(ierr) call MPI_Comm_rank(MPI_COMM_WORLD,my_rank,ierr) call MPI_Comm_size(MPI_COMM_WORLD,p,ierr) c c-------数据交换 data=0 tag = 5 source= my_rank-1 if(source.eq.-1) source=p-1 dest =my_rank+1 if(dest.eq.p) dest=0 if(my_rank.eq.0) then call MPI_Send(data,1,MPI_INTEGER,dest,tag,MPI_COMM_WORLD,ierr) call MPI_Recv(data,1,MPI_INTEGER,source,tag,MPI_COMM_WORLD,status,ierr) else call MPI_Recv(data,1,MPI_INTEGER,source,tag,MPI_COMM_WORLD,status,ierr) data=data+1 call MPI_Send(data,1,MPI_INTEGER,dest,tag,MPI_COMM_WORLD,ierr) endif c c-------广播数据 call MPI_Bcast(data,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr) c c------打印输出 if(my_rank.eq.0) then if(data.eq.p-1) then print *,”Successful, data=”,data else print *,”Failure, data=”,data endif endif c call MPI_Finalize(ierr) end