!Homework 6 !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) 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) call random_number(A) A=A+rank print *,'Before the shift on processor ',rank,' A= ',A !Evens send to odds then recive !Odds recive, then send to evens. !If p==1 do nothing if(p.ne.1)then if(mod(p,2)==0)then call MPI_send(A(1),n,MPI_REAL8,modulo(rank+1,p),1,MPI_COMM_WORLD,ierror) call MPI_recv(A(1),n,MPI_REAL8,modulo(rank-1,p),1,MPI_COMM_WORLD,status,ierror) else call MPI_recv(B(1),n,MPI_REAL8,modulo(rank-1,p),1,MPI_COMM_WORLD,status,ierror) call MPI_send(A(1),n,MPI_REAL8,modulo(rank+1,p),1,MPI_COMM_WORLD,ierror) A=B endif endif print *,'After the shift on processor ',rank,' A= ',A call MPI_Finalize(ierror) end program !!$vincent% mpirun -np 4 hw6.exe !!$ Before the shift on processor 1 A= 1.77326712988589 !!$ 1.82325123434867 1.14812062030844 !!$ Before the shift on processor 2 A= 2.77326712988589 !!$ 2.82325123434867 2.14812062030844 !!$ After the shift on processor 2 A= 1.77326712988589 !!$ 1.82325123434867 1.14812062030844 !!$ Before the shift on processor 3 A= 3.77326712988589 !!$ 3.82325123434867 3.14812062030844 !!$ After the shift on processor 3 A= 2.77326712988589 !!$ 2.82325123434867 2.14812062030844 !!$ After the shift on processor 1 A= 0.773267129885890 !!$ Before the shift on processor 0 A= 0.773267129885890 !!$ 0.823251234348674 0.148120620308437 !!$ After the shift on processor 0 A= 3.77326712988589 !!$ 3.82325123434867 3.14812062030844 !!$ 0.823251234348674 0.148120620308437 !!$vincent%