program example18 include 'mpif.h' integer ierr, rank, rank1, i, size, MAXPROC, MAXEDGES parameter (MAXPROC = 128, MAXEDGES = 512) integer a, b integer status(MPI_STATUS_SIZE) integer comm_graph, index(MAXPROC), edges(MAXEDGES) integer num, neighbors(MAXPROC) call MPI_INIT(ierr) call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr) call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr) do i = 1, size index(i) = size+i-2 end do do i = 1, size-1 edges(i) = i edges(size+i-1) = 0 end do call MPI_GRAPH_CREATE(MPI_COMM_WORLD, size, index, edges, & .TRUE., comm_graph, ierr) call MPI_GRAPH_NEIGHBORS_COUNT(comm_graph, rank, num, & ierr) call MPI_GRAPH_NEIGHBORS(comm_graph, rank, num, neighbors, & ierr) do i = 1, num call MPI_SENDRECV(rank, 1, MPI_INTEGER, neighbors(i), & 1, rank1, 1, MPI_INTEGER, & neighbors(i), 1, comm_graph, & status, ierr) print *, 'procecc ', rank, ' communicate with process', & rank1 end do call MPI_FINALIZE(ierr) end