!Homework 7 !Programmer: Chad Brewbaker !Email address: crb002@iastate.edu !Date: Febuary 25, 2004 !Machine used: hpc-class.iastate.edu (Intel Xenon cluster) !Compiler options used: program implicit none integer, parameter :: n=3 real*8::A(1:n),B(1:n),C(1:n) include "mpif.h" integer::i,j,ierror,p,rank,status(mpi_status_size) call mpi_init(ierror) call mpi_comm_size(mpi_comm_world,p,ierror) call mpi_comm_rank(mpi_comm_world,rank,ierror) do i=1,n A(i)=float(i)+rank B(i)=-A(i) enddo print *,'Before the shift on processor ',rank,' A= ',A print *,'Before the shift on processor ',rank,' B= ',B !If p==1 do nothing if(p.ne.1)then call MPI_Sendrecv_replace(A(1),n,MPI_REAL8,modulo(rank+1,p),1,modulo(rank-1,p),1,MPI_COMM_WORLD,status,ierror) !!$ Different tags so we shouldn't need to call MPI_Barrier(MPI_COMM_WORLD,ierror) call MPI_Sendrecv_replace(B(1),n,MPI_REAL8,modulo(rank-1,p),2,modulo(rank+1,p),2,MPI_COMM_WORLD,status,ierror) endif print *,'After the shift on processor ',rank,' A= ',A print *,'After the shift on processor ',rank,' B= ',B call MPI_Finalize(ierror) end program !!$vincent% mpirun -np 4 hw7.exe !!$ Before the shift on processor 1 A= 2.00000000000000 !!$ 3.00000000000000 4.00000000000000 !!$ Before the shift on processor 1 B= -2.00000000000000 !!$ -3.00000000000000 -4.00000000000000 !!$ Before the shift on processor 3 A= 4.00000000000000 !!$ 5.00000000000000 6.00000000000000 !!$ Before the shift on processor 3 B= -4.00000000000000 !!$ -5.00000000000000 -6.00000000000000 !!$ Before the shift on processor 0 A= 1.00000000000000 !!$ After the shift on processor 3 A= 3.00000000000000 !!$ After the shift on processor 1 A= 1.00000000000000 !!$ Before the shift on processor 2 A= 3.00000000000000 !!$ 2.00000000000000 3.00000000000000 !!$ Before the shift on processor 0 B= -1.00000000000000 !!$ -2.00000000000000 -3.00000000000000 !!$ After the shift on processor 0 A= 4.00000000000000 !!$ 5.00000000000000 6.00000000000000 !!$ After the shift on processor 0 B= -2.00000000000000 !!$ -3.00000000000000 -4.00000000000000 !!$ 2.00000000000000 3.00000000000000 !!$ After the shift on processor 1 B= -3.00000000000000 !!$ -4.00000000000000 -5.00000000000000 !!$ 4.00000000000000 5.00000000000000 !!$ Before the shift on processor 2 B= -3.00000000000000 !!$ -4.00000000000000 -5.00000000000000 !!$ After the shift on processor 2 A= 2.00000000000000 !!$ 3.00000000000000 4.00000000000000 !!$ After the shift on processor 2 B= -4.00000000000000 !!$ -5.00000000000000 -6.00000000000000 !!$ 4.00000000000000 5.00000000000000 !!$ After the shift on processor 3 B= -1.00000000000000 !!$ -2.00000000000000 -3.00000000000000 !!$vincent%