!Homework 15 !Programmer: Chad Brewbaker !Email address: crb002@iastate.edu !Date: April 22, 2004 !Machine used: hpc-class.iastate.edu (Intel Xenon/Myrinet cluster) !Compiler options used: implicit none include "mpif.h" integer,parameter :: n=5,dp=mpi_double_precision, comm=mpi_comm_world integer :: p, rank, i, status(mpi_status_size) integer :: ierror,newtype,blocklens(n),disp(n) double precision :: A(n,n), B(n,n) call mpi_init(ierror) call mpi_comm_size(comm, p, ierror) call mpi_comm_rank(comm, rank, ierror) if (rank == 0) then print *, ' ' print *, ' p = ', p, ' and n = ', n call random_number(A) print *, 'A= ', A(1:n,1:n) endif !!Get a lower triangular nxn matrix from the diagonal down. do i=1,n !Why does this do row major?? ! blocklens(i)=n-i+1 !disp(i)=(n*(i-1))+i-1 blocklens(i)=i disp(i)=(n*(i-1)) enddo call MPI_Type_indexed(n,blocklens,disp,dp,newtype,ierror) call MPI_Type_commit(newtype,ierror) if (rank==0) then call MPI_Send(A, 1, newtype, 1, 1, comm, ierror) endif if(rank==1) then B=0.d0 call MPI_Recv(B, 1, newtype, 0, 1,comm, status, ierror) print *, 'B= ', B(1:n,1:n) endif call MPI_Type_free(newtype,ierror) call mpi_finalize(ierror) endprogram !!$ B= 0.773267129885890 0.00000000000000D+000 0.00000000000000D+000 !!$ p = 2 and n = 5 !!$ A= 0.773267129885890 0.823251234348674 0.148120620308437 !!$ 0.656714907139731 0.842055630151761 0.628580122014474 !!$ 0.330478665894452 0.768815101108699 0.681063573564108 !!$ 0.104431626409966 0.285990417481750 0.809037499810276 !!$ 0.743652890654999 0.725900004139059 7.35362302760166D-002 !!$ 0.736122963470632 0.821746784010800 3.96838647115694D-002 !!$ 0.621942684745769 6.36071097359756D-002 0.356516153094329 !!$ 0.817688434831933 0.441321639580342 0.527589249423030 !!$ 0.873512638478219 !!$ 0.00000000000000D+000 0.00000000000000D+000 0.628580122014474 !!$ 0.330478665894452 0.00000000000000D+000 0.00000000000000D+000 !!$ 0.00000000000000D+000 0.285990417481750 0.809037499810276 !!$ 0.743652890654999 0.00000000000000D+000 0.00000000000000D+000 !!$ 0.736122963470632 0.821746784010800 3.96838647115694D-002 !!$ 0.621942684745769 0.00000000000000D+000 0.356516153094329 !!$ 0.817688434831933 0.441321639580342 0.527589249423030