program easydiff implicit none include 'mpif.h' real u,v,dt,t,f1,f2,Time,w(2) integer ierror,istatus,nProc,myProc,tag,n,i call MPI_Init(ierror) call MPI_Comm_Rank(MPI_COMM_WORLD, myProc, ierror) call MPI_Comm_Size(MPI_COMM_WORLD, nProc, ierror) u=1 Time=2 n=100 dt=Time/n t=0 v=u do i=0, n-1 if(myProc .eq. 0) then write(*,*)'U(',t,') = ', u endif if (i .eq. 0) then w(1)=u w(2)=v u=u+dt*(-u**2) w(1)=u endif if (i .gt. 0) then C write(*,*)'here',i,myProc if(myProc .eq. 0) then call MPI_Send(u,1,MPI_REAL,1,tag,MPI_COMM_WORLD,ierror) call MPI_Send(w,2,MPI_REAL,2,tag,MPI_COMM_WORLD,ierror) endif if(myProc .eq. 1) then call MPI_Recv(u,1,MPI_REAL,0,tag,MPI_COMM_WORLD,istatus,ierror) f1=-u**2 call MPI_Send(f1,1,MPI_REAL,0,tag,MPI_COMM_WORLD,ierror) endif if(myProc .eq. 2) then call MPI_Recv(w,2,MPI_REAL,0,tag,MPI_COMM_WORLD,istatus,ierror) f2=-(2*w(1)-w(2))**2 call MPI_Send(f2,1,MPI_REAL,0,tag,MPI_COMM_WORLD,ierror) endif if(myProc .eq. 0) then call MPI_Recv(f1,1,MPI_REAL,1,tag,MPI_COMM_WORLD,istatus,ierror) call MPI_Recv(f2,1,MPI_REAL,2,tag,MPI_COMM_WORLD,istatus,ierror) w(2)=u u=u+(dt/2)*(f1+f2) w(1)=u endif endif t=t+dt enddo call MPI_Finalize(ierror) stop end