C C Open Systems Laboratory C http://www.lam-mpi.org/tutorials/ C Indiana University C C MPI Tutorial C Lab - Datatypes C C Mail questions regarding tutorial material to lam at lam dash mpi dot org C C Create a datatype called submatrix that consists of elements in C alternate rows and alternate columns of the given original matrix. C C Use MPI_SENDRECV to send the submatrix to itself and print the C results. To test this program you can run the program on just C one processor. C C For example, if the given matrix is: C C 1 2 3 4 5 6 C 7 8 9 10 11 12 C 13 14 15 16 17 18 C 19 20 21 22 23 23 C 24 25 26 27 28 29 C C The submatrix created should look like: C C 1 3 5 C 13 15 17 C 24 26 28 C program main include 'mpif.h' integer ierr integer rank integer i, j integer a(10,10), c(5,5) integer subrow, submatrix integer status integer sizeofint integer blocks, blocksize, stride, bytes, numsend, numrecv integer tag call MPI_INIT(ierr) call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr) C Initialize the local array do 10 i = 1, 10 do 20 j = 1, 10 a(i, j) = (i - 1) * 10 + j 20 continue 10 continue do 31 i = 1, 10 do 41 j = 1, 10 print *, a(i, j) 41 continue 31 continue C Create a submatrix datatype call MPI_TYPE_EXTENT(MPI_INTEGER, sizeofint, ierr) C Create datatype for the sub-row blocks = 5 blocksize = 1 stride = 2 call MPI_TYPE_VECTOR(blocks, blocksize, stride, MPI_INTEGER, & subrow, ierr) call MPI_TYPE_SIZE(subrow, bytes, ierr) print *, 'size of ', bytes print *, 'size of int', sizeofint C Commit the datatype created call MPI_TYPE_COMMIT(subrow, ierr) C Create datatype for the sub-matrix bytes = 20 * sizeofint call MPI_TYPE_HVECTOR(blocks, blocksize, bytes, subrow, & submatrix, ierr) C Commit the datatype created call MPI_TYPE_COMMIT(submatrix, ierr) call MPI_TYPE_SIZE(submatrix, bytes, ierr) print *, 'size of ', bytes C Send it to self and print it numsend = 1 numrecv = 25 tag = 201 call MPI_SENDRECV(a(1, 1), numsend, submatrix, rank, tag, & c(1, 1), numrecv, MPI_INTEGER, rank, & tag, MPI_COMM_WORLD, status, ierr) C Print the submatrix print *, 'a ', c(1, 1) print *, 'a ', c(1, 3) print *, 'a ', c(1, 5) if (rank .eq. 0) then do 30 i = 1, 5 do 40 j = 1, 5 print *, c(i, j) 40 continue 30 continue end if call MPI_FINALIZE(ierr) end