|
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 |
* Bruck's Algorithm:
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* This algorithm is from the IEEE TPDS Nov 97 paper by Jehoshua Bruck
|
|
Packit Service |
c5cf8c |
* et al. It is a variant of the disemmination algorithm for barrier.
|
|
Packit Service |
c5cf8c |
* It takes ceiling(lg p) steps.
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* Cost = lgp.alpha + n.((p-1)/p).beta
|
|
Packit Service |
c5cf8c |
* where n is total size of data gathered on each process.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#undef FUNCNAME
|
|
Packit Service |
c5cf8c |
#define FUNCNAME MPIR_Allgatherv_intra_brucks
|
|
Packit Service |
c5cf8c |
#undef FCNAME
|
|
Packit Service |
c5cf8c |
#define FCNAME MPL_QUOTE(FUNCNAME)
|
|
Packit Service |
c5cf8c |
int MPIR_Allgatherv_intra_brucks(const void *sendbuf,
|
|
Packit Service |
c5cf8c |
int sendcount,
|
|
Packit Service |
c5cf8c |
MPI_Datatype sendtype,
|
|
Packit Service |
c5cf8c |
void *recvbuf,
|
|
Packit Service |
c5cf8c |
const int *recvcounts,
|
|
Packit Service |
c5cf8c |
const int *displs,
|
|
Packit Service |
c5cf8c |
MPI_Datatype recvtype,
|
|
Packit Service |
c5cf8c |
MPIR_Comm * comm_ptr, MPIR_Errflag_t * errflag)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int comm_size, rank, j, 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 |
MPI_Aint recvbuf_extent, recvtype_extent, recvtype_true_extent, recvtype_true_lb;
|
|
Packit Service |
c5cf8c |
int pof2, src, rem, send_cnt;
|
|
Packit Service |
c5cf8c |
MPI_Aint curr_cnt, recv_cnt;
|
|
Packit Service |
c5cf8c |
int dst, total_count;
|
|
Packit Service |
c5cf8c |
void *tmp_buf;
|
|
Packit Service |
c5cf8c |
MPIR_CHKLMEM_DECL(1);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
comm_size = comm_ptr->local_size;
|
|
Packit Service |
c5cf8c |
rank = comm_ptr->rank;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
total_count = 0;
|
|
Packit Service |
c5cf8c |
for (i = 0; i < comm_size; i++)
|
|
Packit Service |
c5cf8c |
total_count += recvcounts[i];
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (total_count == 0)
|
|
Packit Service |
c5cf8c |
goto fn_exit;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_Datatype_get_extent_macro(recvtype, recvtype_extent);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* allocate a temporary buffer of the same size as recvbuf. */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* get true extent of recvtype */
|
|
Packit Service |
c5cf8c |
MPIR_Type_get_true_extent_impl(recvtype, &recvtype_true_lb, &recvtype_true_extent);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_Ensure_Aint_fits_in_pointer(total_count * MPL_MAX(recvtype_true_extent, recvtype_extent));
|
|
Packit Service |
c5cf8c |
recvbuf_extent = total_count * (MPL_MAX(recvtype_true_extent, recvtype_extent));
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_CHKLMEM_MALLOC(tmp_buf, void *, recvbuf_extent, mpi_errno, "tmp_buf", MPL_MEM_BUFFER);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* adjust for potential negative lower bound in datatype */
|
|
Packit Service |
c5cf8c |
tmp_buf = (void *) ((char *) tmp_buf - recvtype_true_lb);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* copy local data to the top of tmp_buf */
|
|
Packit Service |
c5cf8c |
if (sendbuf != MPI_IN_PLACE) {
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Localcopy(sendbuf, sendcount, sendtype,
|
|
Packit Service |
c5cf8c |
tmp_buf, recvcounts[rank], recvtype);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Localcopy(((char *) recvbuf +
|
|
Packit Service |
c5cf8c |
displs[rank] * recvtype_extent),
|
|
Packit Service |
c5cf8c |
recvcounts[rank], recvtype, tmp_buf, recvcounts[rank], recvtype);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* do the first \floor(\lg p) steps */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
curr_cnt = recvcounts[rank];
|
|
Packit Service |
c5cf8c |
pof2 = 1;
|
|
Packit Service |
c5cf8c |
while (pof2 <= comm_size / 2) {
|
|
Packit Service |
c5cf8c |
src = (rank + pof2) % comm_size;
|
|
Packit Service |
c5cf8c |
dst = (rank - pof2 + comm_size) % comm_size;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIC_Sendrecv(tmp_buf, curr_cnt, recvtype, dst,
|
|
Packit Service |
c5cf8c |
MPIR_ALLGATHERV_TAG,
|
|
Packit Service |
c5cf8c |
((char *) tmp_buf + curr_cnt * recvtype_extent),
|
|
Packit Service |
c5cf8c |
total_count - curr_cnt, recvtype,
|
|
Packit Service |
c5cf8c |
src, MPIR_ALLGATHERV_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 |
recv_cnt = 0;
|
|
Packit Service |
c5cf8c |
} else
|
|
Packit Service |
c5cf8c |
MPIR_Get_count_impl(&status, recvtype, &recv_cnt);
|
|
Packit Service |
c5cf8c |
curr_cnt += recv_cnt;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
pof2 *= 2;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* if comm_size is not a power of two, one more step is needed */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
rem = comm_size - pof2;
|
|
Packit Service |
c5cf8c |
if (rem) {
|
|
Packit Service |
c5cf8c |
src = (rank + pof2) % comm_size;
|
|
Packit Service |
c5cf8c |
dst = (rank - pof2 + comm_size) % comm_size;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
send_cnt = 0;
|
|
Packit Service |
c5cf8c |
for (i = 0; i < rem; i++)
|
|
Packit Service |
c5cf8c |
send_cnt += recvcounts[(rank + i) % comm_size];
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIC_Sendrecv(tmp_buf, send_cnt, recvtype,
|
|
Packit Service |
c5cf8c |
dst, MPIR_ALLGATHERV_TAG,
|
|
Packit Service |
c5cf8c |
((char *) tmp_buf + curr_cnt * recvtype_extent),
|
|
Packit Service |
c5cf8c |
total_count - curr_cnt, recvtype,
|
|
Packit Service |
c5cf8c |
src, MPIR_ALLGATHERV_TAG, comm_ptr, MPI_STATUS_IGNORE, 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 |
|
|
Packit Service |
c5cf8c |
/* Rotate blocks in tmp_buf down by (rank) blocks and store
|
|
Packit Service |
c5cf8c |
* result in recvbuf. */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
send_cnt = 0;
|
|
Packit Service |
c5cf8c |
for (i = 0; i < (comm_size - rank); i++) {
|
|
Packit Service |
c5cf8c |
j = (rank + i) % comm_size;
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Localcopy((char *) tmp_buf + send_cnt * recvtype_extent,
|
|
Packit Service |
c5cf8c |
recvcounts[j], recvtype,
|
|
Packit Service |
c5cf8c |
(char *) recvbuf + displs[j] * recvtype_extent,
|
|
Packit Service |
c5cf8c |
recvcounts[j], recvtype);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
send_cnt += recvcounts[j];
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (i = 0; i < rank; i++) {
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Localcopy((char *) tmp_buf + send_cnt * recvtype_extent,
|
|
Packit Service |
c5cf8c |
recvcounts[i], recvtype,
|
|
Packit Service |
c5cf8c |
(char *) recvbuf + displs[i] * recvtype_extent,
|
|
Packit Service |
c5cf8c |
recvcounts[i], recvtype);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
send_cnt += recvcounts[i];
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
fn_exit:
|
|
Packit Service |
c5cf8c |
MPIR_CHKLMEM_FREEALL();
|
|
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 |
|
|
Packit Service |
c5cf8c |
return mpi_errno;
|
|
Packit Service |
c5cf8c |
fn_fail:
|
|
Packit Service |
c5cf8c |
goto fn_exit;
|
|
Packit Service |
c5cf8c |
}
|