program cart_coords_example ! mpirun -np 6 cart_coords_example implicit none integer nv, mv, i, j integer p, reorder, ierr, new_comm integer Iam, rank, ndim, root parameter (nv=3, mv=2, ndim=2, reorder=1) include "mpif.h" !! This brings in pre-defined MPI constants, ... integer dims(ndim), coords(0:ndim-1) logical periods(ndim) data root/0/ !! designate root process to be process 0 data periods/.true.,.false./ !! no circular shift permited in y-direction c**Starts MPI processes ... call MPI_Init(ierr) !! starts MPI call MPI_Comm_rank(MPI_COMM_WORLD, Iam, ierr) !! get current process id call MPI_Comm_size(MPI_COMM_WORLD, p, ierr) !! get number of processes c**create cartesian topology for processes dims(1) = nv !! number of rows dims(2) = mv !! number of columns call MPI_Cart_create(MPI_COMM_WORLD, ndim, dims, & periods, reorder, new_comm, ierr) if(Iam .eq. root) then write(*,*)' rank i j' do rank=0,p-1 call MPI_Cart_coords(new_comm, rank, ndim, coords, ierr) write(*,'(3i8)')rank, coords enddo endif call MPI_Finalize(ierr) !! let MPI finish up ... end