program main !-- Create a Cartesian 2D topology and print out the ! coordinate parameters of each process. !--Include the mpi header file use mpi implicit none integer i,ierr,rank,my_rank,numprocs,itag,ierror integer status(MPI_STATUS_SIZE) integer irc parameter (ndims=2) !dimension of the cartesian grid integer ndims,dims(ndims) integer COMM_CART logical periods(ndims),reorder integer coords(ndims) integer nx=4, ny=4 real x(nx,nx), y(nx,nx), dx=0.2, dy=0.2 x(1:4,j)= (0.1, 0.3, 0.5, 0.7) y(i,1:4)= (0.1, 0.3, 0.5, 0.7) # The cell size is dx=dy=0.2 !--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 ) !--Create a cartesian topology dims(1:ndims)=2 ! 2x2 grid of sub-domains 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 and print the coordinate parameters of each process in the ! Cartesian topology. if (my_rank == 0) then do i=1,numprocs rank=i-1 call MPI_CART_COORDS(COMM_CART,rank,2,coords,ierror) write(*,*)'The coords of process ',rank,' are: ',coords end do end if !--Finilize MPI call MPI_FINALIZE(irc) stop end