!Homework 8 using collectives on 4 !Programmer: Chad Brewbaker !Email address: crb002@iastate.edu !Date: Febuary 16, 2004 !Machine used: hpc-class.iastate.edu (Intel Xenon cluster) !Compiler options used: program implicit none integer, parameter :: n=3 real*8,dimension(:,:),allocatable::A real*8::B(n) include "mpif.h" integer::i,j,k,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(B) B(1:n)=B(1:n)+rank print *, 'On processor',rank,'B=',B if(rank==0)then allocate(A(n,0:p-1)) endif call MPI_Gather(B,n,MPI_REAL8,A,n,MPI_REAL8,0,MPI_COMM_WORLD,ierror) if(rank==0)then do i=0,p-1 print *,'Column',i,' of A=',A(1:n,i) enddo deallocate(A) endif call MPI_Finalize(ierror) end program !!$vincent% mpirun -np 4 hw8.4.exe !!$ On processor 2 B= 2.77326712988589 2.82325123434867 !!$ 2.14812062030844 !!$ On processor 3 B= 3.77326712988589 3.82325123434867 !!$ 3.14812062030844 !!$ On processor 0 B= 0.773267129885890 0.823251234348674 !!$ On processor 1 B= 1.77326712988589 1.82325123434867 !!$ 0.148120620308437 !!$ Column 0 of A= 0.773267129885890 0.823251234348674 !!$ 0.148120620308437 !!$ Column 1 of A= 1.77326712988589 1.82325123434867 !!$ 1.14812062030844 !!$ Column 2 of A= 2.77326712988589 2.82325123434867 !!$ 2.14812062030844 !!$ Column 3 of A= 3.77326712988589 3.82325123434867 !!$ 3.14812062030844 !!$ 1.14812062030844 !!$vincent%