program myjacobi c%%%%%%%%%%%%%%%%%%% c%%% c%%%%%%%%%%%%%%%%%%%% c%%% calling sequence .... c%%% c%%%%%%%%%%%%%%%%%%%% c%% myn = size of problem c%% tol = tolerance for size of residual c%% maxiter = max number of iterations acceptable c%%%%%%%%%%%%%%%%%%%% implicit none c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% c%%%%% MPI declarations include 'mpif.h' integer nproc, rank, p, ierr, rc integer tag,status(MPI_STATUS_SIZE) c%%%%% problem declarations integer maxn integer myn parameter (maxn=100) c integer i double precision uleft, uright,u(maxn) c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% c%%%% start MPI c23456 call MPI_INIT(ierr) if (ierr .ne. MPI_SUCCESS) then print *,'Error starting MPI program. Terminating.' call MPI_ABORT(MPI_COMM_WORLD, rc, ierr) end if c%%%% what is my number (rank+1) and total number of processors call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr) call MPI_COMM_SIZE(MPI_COMM_WORLD, nproc, ierr) c p = rank + 1 if (rank.eq.0) then write(6,*) 'Number of processors=',nproc endif c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% myn = 4 c%%%%%%%%%%%%%%%%%%%%%%%%%%%%% uleft = 0D0; uright = 0D0; c%% %%% every processor records its number do i = 1, myn u(i) = p; enddo c write(6,*) 'Proc ',p,' data before ',uleft,(u(i),i=1,myn),uright c%%%%%%%%%%%%%%%%%%%%%%%%%%%% example of exchange data c exchaNnge data c CORRECT THE CODE tag = 0 if (p.lt.nproc) then call MPI_Send(u(myn), 1, MPI_DOUBLE_PRECISION, rank + 1, & tag,MPI_COMM_WORLD,ierr ); endif if (p.gt.1) then call MPI_Send(u(1), 1, MPI_DOUBLE_PRECISION, rank - 1, & tag,MPI_COMM_WORLD,ierr ); endif if (p.lt.nproc) then call MPI_RECV (uright, 1, MPI_DOUBLE_PRECISION, rank, & tag,MPI_COMM_WORLD,status,ierr ); endif if (p.ge.1) then call MPI_RECV (uleft, 1, MPI_DOUBLE_PRECISION, rank - 1, & tag,MPI_COMM_WORLD,status,ierr ); endif write(6,*) 'Proc ',p,' data after ',uleft,(u(i),i=1,myn),uright c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% call MPI_FINALIZE(ierr) end