!2a. Modify exercise2.f90 so it decomposes an 8x8 grid into 4 blocks ! (along x and y). !---------------------------------------------------------------------- program main !-- Create a Cartesian 2D topology and define the ! physical coordinate arrays x,y in each process. implicit none !--Include the mpi header file include 'mpif.h' integer i,j,ierr,rank,my_rank,numprocs,itag,ierror integer status(MPI_STATUS_SIZE) integer irc integer, parameter :: ndims=2 !dimension of the Cartesian grid integer, parameter :: dims_x=2, dims_y=2 !same as dims(1:2) integer dims(ndims) integer COMM_CART logical periods(ndims),reorder integer coords(ndims) real x(4,4),y(4,4),dx,dy real x_corner,y_corner integer nx,ny !--Initialize MPI call MPI_INIT( ierr ) !--Who am I? --- get my rank=my_rank call MPI_COMM_RANK( MPI_COMM_WORLD, my_rank, ierr ) !--How many processes in the global group? call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr ) !--The size of the domain: nx=8 ny=8 !--Create a Cartesian topology dims(1)=dims_x dims(2)=dims_y periods(1)=.true. ! periodic bdry. cond. along x periods(2)=.false. ! non-periodic bdry. cond. along y call MPI_CART_CREATE(MPI_COMM_WORLD,ndims,dims,periods, & reorder,COMM_CART,ierror) ! ---------------------------------------------------------------- ! | MPI_CART_CREATE will provide a 2D Cartesian array of processes | ! ======>| of dimensions 2x2. | ! | Each process rank is associated with a given sub-domain. | ! ---------------------------------------------------------------- !--Find my coordinate parameters in the Cartesial topology, and use them ! to compute the arrays x,y call MPI_CART_COORDS(COMM_CART,my_rank,2,coords,ierror) !--The physical coordinates of my left-bottom corner: dx=0.2 dy=0.2 x_corner= float( nx/dims(1) * coords(1) ) * dx y_corner= float( ny/dims(2) * coords(2) ) * dy !--Use my corner's physical coordinates to compute the cell physical ! coordinates (arrays x,y) in my block do i=1,4 x(i,:)=x_corner+(float(i)-0.5)*dx end do do j=1,4 y(:,j)=y_corner+(float(j)-0.5)*dy end do !--Print write(*,"('my rank.=',i2,', my coords=[',2i2,'] ,& & x= ',16f4.1)" ) & & my_rank, coords, x write(*,"('my rank.=',i2,', my coords=[',2i2,'] ,& & y= ',16f4.1)" ) & & my_rank, coords, y !--Finilize MPI call MPI_FINALIZE(irc) stop end