/* * Copyright (C) by Argonne National Laboratory * See COPYRIGHT in top-level directory */ #include "mpiimpl.h" /* Pairwise Exchange * * We use a pairwise exchange algorithm similar to the one used in * intracommunicator alltoall for long messages. Since the local and * remote groups can be of different sizes, we first compute the max * of local_group_size, remote_group_size. At step i, 0 <= i < * max_size, each process receives from src = (rank - i + max_size) % * max_size if src < remote_size, and sends to dst = (rank + i) % * max_size if dst < remote_size. */ int MPIR_Ialltoall_inter_sched_pairwise_exchange(const void *sendbuf, MPI_Aint sendcount, MPI_Datatype sendtype, void *recvbuf, MPI_Aint recvcount, MPI_Datatype recvtype, MPIR_Comm * comm_ptr, MPIR_Sched_t s) { int mpi_errno = MPI_SUCCESS; int local_size, remote_size, max_size, i; MPI_Aint sendtype_extent, recvtype_extent; int src, dst, rank; char *sendaddr, *recvaddr; local_size = comm_ptr->local_size; remote_size = comm_ptr->remote_size; rank = comm_ptr->rank; /* Get extent of send and recv types */ MPIR_Datatype_get_extent_macro(sendtype, sendtype_extent); MPIR_Datatype_get_extent_macro(recvtype, recvtype_extent); /* Do the pairwise exchanges */ max_size = MPL_MAX(local_size, remote_size); for (i = 0; i < max_size; i++) { src = (rank - i + max_size) % max_size; dst = (rank + i) % max_size; if (src >= remote_size) { src = MPI_PROC_NULL; recvaddr = NULL; } else { recvaddr = (char *) recvbuf + src * recvcount * recvtype_extent; } if (dst >= remote_size) { dst = MPI_PROC_NULL; sendaddr = NULL; } else { sendaddr = (char *) sendbuf + dst * sendcount * sendtype_extent; } mpi_errno = MPIR_Sched_send(sendaddr, sendcount, sendtype, dst, comm_ptr, s); MPIR_ERR_CHECK(mpi_errno); mpi_errno = MPIR_Sched_recv(recvaddr, recvcount, recvtype, src, comm_ptr, s); MPIR_ERR_CHECK(mpi_errno); MPIR_SCHED_BARRIER(s); } fn_exit: return mpi_errno; fn_fail: goto fn_exit; }