|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* (C) 2001 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#include "mpiimpl.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* Pairwise Exchange
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* We use a pairwise exchange algorithm similar to the one used in
|
|
Packit Service |
c5cf8c |
* intracommunicator alltoallw. Since the local and remote groups can
|
|
Packit Service |
c5cf8c |
* be of different sizes, we first compute the max of
|
|
Packit Service |
c5cf8c |
* local_group_size, remote_group_size. At step i, 0 <= i < max_size,
|
|
Packit Service |
c5cf8c |
* each process receives from src = (rank - i + max_size) % max_size
|
|
Packit Service |
c5cf8c |
* if src < remote_size, and sends to dst = (rank + i) % max_size if
|
|
Packit Service |
c5cf8c |
* dst < remote_size.
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* FIXME: change algorithm to match intracommunicator alltoallv
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#undef FUNCNAME
|
|
Packit Service |
c5cf8c |
#define FUNCNAME MPIR_Alltoallw_inter_pairwise_exchange
|
|
Packit Service |
c5cf8c |
#undef FCNAME
|
|
Packit Service |
c5cf8c |
#define FCNAME MPL_QUOTE(FUNCNAME)
|
|
Packit Service |
c5cf8c |
int MPIR_Alltoallw_inter_pairwise_exchange(const void *sendbuf, const int sendcounts[],
|
|
Packit Service |
c5cf8c |
const int sdispls[], const MPI_Datatype sendtypes[],
|
|
Packit Service |
c5cf8c |
void *recvbuf, const int recvcounts[],
|
|
Packit Service |
c5cf8c |
const int rdispls[], const MPI_Datatype recvtypes[],
|
|
Packit Service |
c5cf8c |
MPIR_Comm * comm_ptr, MPIR_Errflag_t * errflag)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int local_size, remote_size, max_size, i;
|
|
Packit Service |
c5cf8c |
int mpi_errno = MPI_SUCCESS;
|
|
Packit Service |
c5cf8c |
int mpi_errno_ret = MPI_SUCCESS;
|
|
Packit Service |
c5cf8c |
MPI_Status status;
|
|
Packit Service |
c5cf8c |
int src, dst, rank, sendcount, recvcount;
|
|
Packit Service |
c5cf8c |
char *sendaddr, *recvaddr;
|
|
Packit Service |
c5cf8c |
MPI_Datatype sendtype, recvtype;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
local_size = comm_ptr->local_size;
|
|
Packit Service |
c5cf8c |
remote_size = comm_ptr->remote_size;
|
|
Packit Service |
c5cf8c |
rank = comm_ptr->rank;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Use pairwise exchange algorithm. */
|
|
Packit Service |
c5cf8c |
max_size = MPL_MAX(local_size, remote_size);
|
|
Packit Service |
c5cf8c |
for (i = 0; i < max_size; i++) {
|
|
Packit Service |
c5cf8c |
src = (rank - i + max_size) % max_size;
|
|
Packit Service |
c5cf8c |
dst = (rank + i) % max_size;
|
|
Packit Service |
c5cf8c |
if (src >= remote_size) {
|
|
Packit Service |
c5cf8c |
src = MPI_PROC_NULL;
|
|
Packit Service |
c5cf8c |
recvaddr = NULL;
|
|
Packit Service |
c5cf8c |
recvcount = 0;
|
|
Packit Service |
c5cf8c |
recvtype = MPI_DATATYPE_NULL;
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
recvaddr = (char *) recvbuf + rdispls[src];
|
|
Packit Service |
c5cf8c |
recvcount = recvcounts[src];
|
|
Packit Service |
c5cf8c |
recvtype = recvtypes[src];
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (dst >= remote_size) {
|
|
Packit Service |
c5cf8c |
dst = MPI_PROC_NULL;
|
|
Packit Service |
c5cf8c |
sendaddr = NULL;
|
|
Packit Service |
c5cf8c |
sendcount = 0;
|
|
Packit Service |
c5cf8c |
sendtype = MPI_DATATYPE_NULL;
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
sendaddr = (char *) sendbuf + sdispls[dst];
|
|
Packit Service |
c5cf8c |
sendcount = sendcounts[dst];
|
|
Packit Service |
c5cf8c |
sendtype = sendtypes[dst];
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIC_Sendrecv(sendaddr, sendcount, sendtype,
|
|
Packit Service |
c5cf8c |
dst, MPIR_ALLTOALLW_TAG, recvaddr,
|
|
Packit Service |
c5cf8c |
recvcount, recvtype, src,
|
|
Packit Service |
c5cf8c |
MPIR_ALLTOALLW_TAG, comm_ptr, &status, errflag);
|
|
Packit Service |
c5cf8c |
if (mpi_errno) {
|
|
Packit Service |
c5cf8c |
/* for communication errors, just record the error but continue */
|
|
Packit Service |
c5cf8c |
*errflag =
|
|
Packit Service |
c5cf8c |
MPIX_ERR_PROC_FAILED ==
|
|
Packit Service |
c5cf8c |
MPIR_ERR_GET_CLASS(mpi_errno) ? MPIR_ERR_PROC_FAILED : MPIR_ERR_OTHER;
|
|
Packit Service |
c5cf8c |
MPIR_ERR_SET(mpi_errno, *errflag, "**fail");
|
|
Packit Service |
c5cf8c |
MPIR_ERR_ADD(mpi_errno_ret, mpi_errno);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (mpi_errno_ret)
|
|
Packit Service |
c5cf8c |
mpi_errno = mpi_errno_ret;
|
|
Packit Service |
c5cf8c |
else if (*errflag != MPIR_ERR_NONE)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_SET(mpi_errno, *errflag, "**coll_fail");
|
|
Packit Service |
c5cf8c |
return mpi_errno;
|
|
Packit Service |
c5cf8c |
}
|