!2c. Modify exercise2.f90 to do 3D decomposition of a 4x4x4 grid ! into 8 blocks (along x, y, and z). !------------------------------------------------------------------ program main !-- Create a Cartesian 2D topology and define the ! physical coordinate arrays x,y, and z in each process. implicit none !--Include the mpi header file include 'mpif.h' integer i,j,k,ierr,rank,my_rank,numprocs,itag,ierror integer status(MPI_STATUS_SIZE) integer irc integer, parameter :: ndims=3 !dimension of the Cartesian grid integer, parameter :: dims_x=2, dims_y=2 ,dims_z=2 !same as dims(1:3) integer dims(ndims) integer COMM_CART logical periods(ndims),reorder integer coords(ndims) real x(2,2,2),y(2,2,2),z(2,2,2),dx,dy,dz real x_corner,y_corner,z_corner integer nx,ny,nz !--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=4 ny=4 nz=4 !--Create a Cartesian topology dims(1)=dims_x dims(2)=dims_y dims(3)=dims_z periods(1)=.true. ! periodic bdry. cond. along x periods(2)=.false. ! non-periodic bdry. cond. along y periods(3)=.false. ! non-periodic bdry. cond. along y reorder=.false. call MPI_CART_CREATE(MPI_COMM_WORLD,ndims,dims,periods, & reorder,COMM_CART,ierror) ! ---------------------------------------------------------------- ! | MPI_CART_CREATE will provide a 3D Cartesian array of processes | ! ======>| of dimensions 2x2x2. | ! | Each process rank is associated with a given sub-domain. | ! ---------------------------------------------------------------- !--Find my coordinate parameters (coords) in the Cartesial topology, and ! use them to compute the (physical coordinate) arrays x,y call MPI_CART_COORDS(COMM_CART,my_rank,3,coords,ierror) !--The physical coordinates of my left-bottom corner: dx=0.2 dy=0.2 dz=0.2 x_corner= float( nx/dims(1) * coords(1) ) * dx y_corner= float( ny/dims(2) * coords(2) ) * dy z_corner= float( nz/dims(3) * coords(3) ) * dz !--Use my corner's physical coordinates to compute the cell physical ! coordinates (arrays x,y) in my block. do i=1,2 x(i,:,:)=x_corner+(float(i)-0.5)*dx end do do j=1,2 y(:,j,:)=y_corner+(float(j)-0.5)*dy end do do k=1,2 z(:,:,k)=z_corner+(float(k)-0.5)*dz end do !--Print write(*,"('my rank.=',i2,', my coords=[',3i2,'] ,& & x= ',8f4.1)" ) & & my_rank, coords, x write(*,"('my rank.=',i2,', my coords=[',3i2,'] ,& & y= ',8f4.1)" ) & & my_rank, coords, y write(*,"('my rank.=',i2,', my coords=[',3i2,'] ,& & z= ',8f4.1)" ) & & my_rank, coords, z !--Finilize MPI call MPI_FINALIZE(irc) stop end