Blame src/mpi/coll/allgatherv/allgatherv.c

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
=== BEGIN_MPI_T_CVAR_INFO_BLOCK ===
Packit Service c5cf8c
Packit Service c5cf8c
cvars:
Packit Service c5cf8c
    - name        : MPIR_CVAR_ALLGATHERV_PIPELINE_MSG_SIZE
Packit Service c5cf8c
      category    : COLLECTIVE
Packit Service c5cf8c
      type        : int
Packit Service c5cf8c
      default     : 32768
Packit Service c5cf8c
      class       : device
Packit Service c5cf8c
      verbosity   : MPI_T_VERBOSITY_USER_BASIC
Packit Service c5cf8c
      scope       : MPI_T_SCOPE_ALL_EQ
Packit Service c5cf8c
      description : >-
Packit Service c5cf8c
        The smallest message size that will be used for the pipelined, large-message,
Packit Service c5cf8c
        ring algorithm in the MPI_Allgatherv implementation.
Packit Service c5cf8c
Packit Service c5cf8c
    - name        : MPIR_CVAR_ALLGATHERV_INTRA_ALGORITHM
Packit Service c5cf8c
      category    : COLLECTIVE
Packit Service c5cf8c
      type        : string
Packit Service c5cf8c
      default     : auto
Packit Service c5cf8c
      class       : device
Packit Service c5cf8c
      verbosity   : MPI_T_VERBOSITY_USER_BASIC
Packit Service c5cf8c
      scope       : MPI_T_SCOPE_ALL_EQ
Packit Service c5cf8c
      description : |-
Packit Service c5cf8c
        Variable to select allgatherv algorithm
Packit Service c5cf8c
        auto               - Internal algorithm selection
Packit Service c5cf8c
        brucks             - Force brucks algorithm
Packit Service c5cf8c
        nb                 - Force nonblocking algorithm
Packit Service c5cf8c
        recursive_doubling - Force recursive doubling algorithm
Packit Service c5cf8c
        ring               - Force ring algorithm
Packit Service c5cf8c
Packit Service c5cf8c
    - name        : MPIR_CVAR_ALLGATHERV_INTER_ALGORITHM
Packit Service c5cf8c
      category    : COLLECTIVE
Packit Service c5cf8c
      type        : string
Packit Service c5cf8c
      default     : auto
Packit Service c5cf8c
      class       : device
Packit Service c5cf8c
      verbosity   : MPI_T_VERBOSITY_USER_BASIC
Packit Service c5cf8c
      scope       : MPI_T_SCOPE_ALL_EQ
Packit Service c5cf8c
      description : |-
Packit Service c5cf8c
        Variable to select allgatherv algorithm
Packit Service c5cf8c
        auto                      - Internal algorithm selection
Packit Service c5cf8c
        nb                        - Force nonblocking algorithm
Packit Service c5cf8c
        remote_gather_local_bcast - Force remote-gather-local-bcast algorithm
Packit Service c5cf8c
Packit Service c5cf8c
    - name        : MPIR_CVAR_ALLGATHERV_DEVICE_COLLECTIVE
Packit Service c5cf8c
      category    : COLLECTIVE
Packit Service c5cf8c
      type        : boolean
Packit Service c5cf8c
      default     : true
Packit Service c5cf8c
      class       : device
Packit Service c5cf8c
      verbosity   : MPI_T_VERBOSITY_USER_BASIC
Packit Service c5cf8c
      scope       : MPI_T_SCOPE_ALL_EQ
Packit Service c5cf8c
      description : >-
Packit Service c5cf8c
        If set to true, MPI_Allgatherv will allow the device to override the
Packit Service c5cf8c
        MPIR-level collective algorithms. The device still has the
Packit Service c5cf8c
        option to call the MPIR-level algorithms manually.
Packit Service c5cf8c
        If set to false, the device-level allgatherv function will not be
Packit Service c5cf8c
        called.
Packit Service c5cf8c
Packit Service c5cf8c
=== END_MPI_T_CVAR_INFO_BLOCK ===
Packit Service c5cf8c
*/
Packit Service c5cf8c
Packit Service c5cf8c
/* -- Begin Profiling Symbol Block for routine MPI_Allgatherv */
Packit Service c5cf8c
#if defined(HAVE_PRAGMA_WEAK)
Packit Service c5cf8c
#pragma weak MPI_Allgatherv = PMPI_Allgatherv
Packit Service c5cf8c
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
Packit Service c5cf8c
#pragma _HP_SECONDARY_DEF PMPI_Allgatherv  MPI_Allgatherv
Packit Service c5cf8c
#elif defined(HAVE_PRAGMA_CRI_DUP)
Packit Service c5cf8c
#pragma _CRI duplicate MPI_Allgatherv as PMPI_Allgatherv
Packit Service c5cf8c
#elif defined(HAVE_WEAK_ATTRIBUTE)
Packit Service c5cf8c
int MPI_Allgatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf,
Packit Service c5cf8c
                   const int *recvcounts, const int *displs, MPI_Datatype recvtype, MPI_Comm comm)
Packit Service c5cf8c
    __attribute__ ((weak, alias("PMPI_Allgatherv")));
Packit Service c5cf8c
#endif
Packit Service c5cf8c
/* -- End Profiling Symbol Block */
Packit Service c5cf8c
Packit Service c5cf8c
/* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
Packit Service c5cf8c
   the MPI routines */
Packit Service c5cf8c
#ifndef MPICH_MPI_FROM_PMPI
Packit Service c5cf8c
#undef MPI_Allgatherv
Packit Service c5cf8c
#define MPI_Allgatherv PMPI_Allgatherv
Packit Service c5cf8c
Packit Service c5cf8c
#undef FUNCNAME
Packit Service c5cf8c
#define FUNCNAME MPIR_Allgatherv_intra_auto
Packit Service c5cf8c
#undef FCNAME
Packit Service c5cf8c
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit Service c5cf8c
int MPIR_Allgatherv_intra_auto(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, i;
Packit Service c5cf8c
    int mpi_errno = MPI_SUCCESS;
Packit Service c5cf8c
    int total_count, recvtype_size;
Packit Service c5cf8c
Packit Service c5cf8c
    comm_size = comm_ptr->local_size;
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_size_macro(recvtype, recvtype_size);
Packit Service c5cf8c
Packit Service c5cf8c
    if ((total_count * recvtype_size < MPIR_CVAR_ALLGATHER_LONG_MSG_SIZE) &&
Packit Service c5cf8c
        !(comm_size & (comm_size - 1))) {
Packit Service c5cf8c
        /* Short or medium size message and power-of-two no. of processes. Use
Packit Service c5cf8c
         * recursive doubling algorithm */
Packit Service c5cf8c
Packit Service c5cf8c
        mpi_errno =
Packit Service c5cf8c
            MPIR_Allgatherv_intra_recursive_doubling(sendbuf, sendcount, sendtype, recvbuf,
Packit Service c5cf8c
                                                     recvcounts, displs, recvtype, comm_ptr,
Packit Service c5cf8c
                                                     errflag);
Packit Service c5cf8c
        if (mpi_errno)
Packit Service c5cf8c
            MPIR_ERR_POP(mpi_errno);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    else if (total_count * recvtype_size < MPIR_CVAR_ALLGATHER_SHORT_MSG_SIZE) {
Packit Service c5cf8c
        /* Short message and non-power-of-two no. of processes. Use Bruck algorithm. */
Packit Service c5cf8c
Packit Service c5cf8c
        mpi_errno =
Packit Service c5cf8c
            MPIR_Allgatherv_intra_brucks(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs,
Packit Service c5cf8c
                                         recvtype, comm_ptr, errflag);
Packit Service c5cf8c
        if (mpi_errno)
Packit Service c5cf8c
            MPIR_ERR_POP(mpi_errno);
Packit Service c5cf8c
Packit Service c5cf8c
    } else {
Packit Service c5cf8c
        /* long message or medium-size message and non-power-of-two
Packit Service c5cf8c
         * no. of processes. Use ring algorithm. */
Packit Service c5cf8c
Packit Service c5cf8c
        mpi_errno =
Packit Service c5cf8c
            MPIR_Allgatherv_intra_ring(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs,
Packit Service c5cf8c
                                       recvtype, comm_ptr, errflag);
Packit Service c5cf8c
        if (mpi_errno)
Packit Service c5cf8c
            MPIR_ERR_POP(mpi_errno);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
  fn_exit:
Packit Service c5cf8c
    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
}
Packit Service c5cf8c
Packit Service c5cf8c
Packit Service c5cf8c
#undef FUNCNAME
Packit Service c5cf8c
#define FUNCNAME MPIR_Allgatherv_inter_auto
Packit Service c5cf8c
#undef FCNAME
Packit Service c5cf8c
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit Service c5cf8c
int MPIR_Allgatherv_inter_auto(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 mpi_errno = MPI_SUCCESS;
Packit Service c5cf8c
Packit Service c5cf8c
    mpi_errno = MPIR_Allgatherv_inter_remote_gather_local_bcast(sendbuf, sendcount, sendtype,
Packit Service c5cf8c
                                                                recvbuf, recvcounts, displs,
Packit Service c5cf8c
                                                                recvtype, comm_ptr, errflag);
Packit Service c5cf8c
Packit Service c5cf8c
    return mpi_errno;
Packit Service c5cf8c
}
Packit Service c5cf8c
Packit Service c5cf8c
#undef FUNCNAME
Packit Service c5cf8c
#define FUNCNAME MPIR_Allgatherv_impl
Packit Service c5cf8c
#undef FCNAME
Packit Service c5cf8c
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit Service c5cf8c
int MPIR_Allgatherv_impl(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
Packit Service c5cf8c
                         void *recvbuf, const int *recvcounts, const int *displs,
Packit Service c5cf8c
                         MPI_Datatype recvtype, MPIR_Comm * comm_ptr, MPIR_Errflag_t * errflag)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int mpi_errno = MPI_SUCCESS;
Packit Service c5cf8c
Packit Service c5cf8c
    if (comm_ptr->comm_kind == MPIR_COMM_KIND__INTRACOMM) {
Packit Service c5cf8c
        /* intracommunicator */
Packit Service c5cf8c
        switch (MPIR_Allgatherv_intra_algo_choice) {
Packit Service c5cf8c
            case MPIR_ALLGATHERV_INTRA_ALGO_BRUCKS:
Packit Service c5cf8c
                mpi_errno = MPIR_Allgatherv_intra_brucks(sendbuf, sendcount, sendtype,
Packit Service c5cf8c
                                                         recvbuf, recvcounts, displs, recvtype,
Packit Service c5cf8c
                                                         comm_ptr, errflag);
Packit Service c5cf8c
                break;
Packit Service c5cf8c
            case MPIR_ALLGATHERV_INTRA_ALGO_RECURSIVE_DOUBLING:
Packit Service c5cf8c
                mpi_errno = MPIR_Allgatherv_intra_recursive_doubling(sendbuf, sendcount, sendtype,
Packit Service c5cf8c
                                                                     recvbuf, recvcounts, displs,
Packit Service c5cf8c
                                                                     recvtype, comm_ptr, errflag);
Packit Service c5cf8c
                break;
Packit Service c5cf8c
            case MPIR_ALLGATHERV_INTRA_ALGO_RING:
Packit Service c5cf8c
                mpi_errno = MPIR_Allgatherv_intra_ring(sendbuf, sendcount, sendtype,
Packit Service c5cf8c
                                                       recvbuf, recvcounts, displs, recvtype,
Packit Service c5cf8c
                                                       comm_ptr, errflag);
Packit Service c5cf8c
                break;
Packit Service c5cf8c
            case MPIR_ALLGATHERV_INTRA_ALGO_NB:
Packit Service c5cf8c
                mpi_errno = MPIR_Allgatherv_allcomm_nb(sendbuf, sendcount, sendtype,
Packit Service c5cf8c
                                                       recvbuf, recvcounts, displs, recvtype,
Packit Service c5cf8c
                                                       comm_ptr, errflag);
Packit Service c5cf8c
                break;
Packit Service c5cf8c
            case MPIR_ALLGATHERV_INTRA_ALGO_AUTO:
Packit Service c5cf8c
                MPL_FALLTHROUGH;
Packit Service c5cf8c
            default:
Packit Service c5cf8c
                mpi_errno = MPIR_Allgatherv_intra_auto(sendbuf, sendcount, sendtype,
Packit Service c5cf8c
                                                       recvbuf, recvcounts, displs, recvtype,
Packit Service c5cf8c
                                                       comm_ptr, errflag);
Packit Service c5cf8c
                break;
Packit Service c5cf8c
        }
Packit Service c5cf8c
    } else {
Packit Service c5cf8c
        /* intercommunicator */
Packit Service c5cf8c
        switch (MPIR_Allgatherv_inter_algo_choice) {
Packit Service c5cf8c
            case MPIR_ALLGATHERV_INTER_ALGO_REMOTE_GATHER_LOCAL_BCAST:
Packit Service c5cf8c
                mpi_errno =
Packit Service c5cf8c
                    MPIR_Allgatherv_inter_remote_gather_local_bcast(sendbuf, sendcount, sendtype,
Packit Service c5cf8c
                                                                    recvbuf, recvcounts, displs,
Packit Service c5cf8c
                                                                    recvtype, comm_ptr, errflag);
Packit Service c5cf8c
                break;
Packit Service c5cf8c
            case MPIR_ALLGATHERV_INTER_ALGO_NB:
Packit Service c5cf8c
                mpi_errno = MPIR_Allgatherv_allcomm_nb(sendbuf, sendcount, sendtype,
Packit Service c5cf8c
                                                       recvbuf, recvcounts, displs, recvtype,
Packit Service c5cf8c
                                                       comm_ptr, errflag);
Packit Service c5cf8c
                break;
Packit Service c5cf8c
            case MPIR_ALLGATHERV_INTER_ALGO_AUTO:
Packit Service c5cf8c
                MPL_FALLTHROUGH;
Packit Service c5cf8c
            default:
Packit Service c5cf8c
                mpi_errno = MPIR_Allgatherv_inter_auto(sendbuf, sendcount, sendtype,
Packit Service c5cf8c
                                                       recvbuf, recvcounts, displs, recvtype,
Packit Service c5cf8c
                                                       comm_ptr, errflag);
Packit Service c5cf8c
                break;
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
    if (mpi_errno)
Packit Service c5cf8c
        MPIR_ERR_POP(mpi_errno);
Packit Service c5cf8c
Packit Service c5cf8c
  fn_exit:
Packit Service c5cf8c
    return mpi_errno;
Packit Service c5cf8c
  fn_fail:
Packit Service c5cf8c
Packit Service c5cf8c
    goto fn_exit;
Packit Service c5cf8c
}
Packit Service c5cf8c
Packit Service c5cf8c
#undef FUNCNAME
Packit Service c5cf8c
#define FUNCNAME MPIR_Allgatherv
Packit Service c5cf8c
#undef FCNAME
Packit Service c5cf8c
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit Service c5cf8c
int MPIR_Allgatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
Packit Service c5cf8c
                    void *recvbuf, const int *recvcounts, const int *displs, MPI_Datatype recvtype,
Packit Service c5cf8c
                    MPIR_Comm * comm_ptr, MPIR_Errflag_t * errflag)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int mpi_errno = MPI_SUCCESS;
Packit Service c5cf8c
Packit Service c5cf8c
    if (MPIR_CVAR_ALLGATHERV_DEVICE_COLLECTIVE && MPIR_CVAR_DEVICE_COLLECTIVES) {
Packit Service c5cf8c
        mpi_errno = MPID_Allgatherv(sendbuf, sendcount, sendtype,
Packit Service c5cf8c
                                    recvbuf, recvcounts, displs, recvtype, comm_ptr, errflag);
Packit Service c5cf8c
    } else {
Packit Service c5cf8c
        mpi_errno = MPIR_Allgatherv_impl(sendbuf, sendcount, sendtype,
Packit Service c5cf8c
                                         recvbuf, recvcounts, displs, recvtype, comm_ptr, errflag);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    return mpi_errno;
Packit Service c5cf8c
}
Packit Service c5cf8c
Packit Service c5cf8c
#endif
Packit Service c5cf8c
Packit Service c5cf8c
Packit Service c5cf8c
#undef FUNCNAME
Packit Service c5cf8c
#define FUNCNAME MPI_Allgatherv
Packit Service c5cf8c
#undef FCNAME
Packit Service c5cf8c
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit Service c5cf8c
/*@
Packit Service c5cf8c
Packit Service c5cf8c
MPI_Allgatherv - Gathers data from all tasks and deliver the combined data
Packit Service c5cf8c
                 to all tasks
Packit Service c5cf8c
Packit Service c5cf8c
Input Parameters:
Packit Service c5cf8c
+ sendbuf - starting address of send buffer (choice)
Packit Service c5cf8c
. sendcount - number of elements in send buffer (integer)
Packit Service c5cf8c
. sendtype - data type of send buffer elements (handle)
Packit Service c5cf8c
. recvcounts - integer array (of length group size)
Packit Service c5cf8c
containing the number of elements that are to be received from each process
Packit Service c5cf8c
. displs - integer array (of length group size). Entry
Packit Service c5cf8c
 'i'  specifies the displacement (relative to recvbuf) at
Packit Service c5cf8c
which to place the incoming data from process  'i'
Packit Service c5cf8c
. recvtype - data type of receive buffer elements (handle)
Packit Service c5cf8c
- comm - communicator (handle)
Packit Service c5cf8c
Packit Service c5cf8c
Output Parameters:
Packit Service c5cf8c
. recvbuf - address of receive buffer (choice)
Packit Service c5cf8c
Packit Service c5cf8c
Notes:
Packit Service c5cf8c
 The MPI standard (1.0 and 1.1) says that
Packit Service c5cf8c
.n
Packit Service c5cf8c
.n
Packit Service c5cf8c
 The jth block of data sent from
Packit Service c5cf8c
 each process is received by every process and placed in the jth block of the
Packit Service c5cf8c
 buffer 'recvbuf'.
Packit Service c5cf8c
.n
Packit Service c5cf8c
.n
Packit Service c5cf8c
 This is misleading; a better description is
Packit Service c5cf8c
.n
Packit Service c5cf8c
.n
Packit Service c5cf8c
 The block of data sent from the jth process is received by every
Packit Service c5cf8c
 process and placed in the jth block of the buffer 'recvbuf'.
Packit Service c5cf8c
.n
Packit Service c5cf8c
.n
Packit Service c5cf8c
 This text was suggested by Rajeev Thakur, and has been adopted as a
Packit Service c5cf8c
 clarification to the MPI standard by the MPI-Forum.
Packit Service c5cf8c
Packit Service c5cf8c
.N ThreadSafe
Packit Service c5cf8c
Packit Service c5cf8c
.N Fortran
Packit Service c5cf8c
Packit Service c5cf8c
.N Errors
Packit Service c5cf8c
.N MPI_ERR_BUFFER
Packit Service c5cf8c
.N MPI_ERR_COUNT
Packit Service c5cf8c
.N MPI_ERR_TYPE
Packit Service c5cf8c
@*/
Packit Service c5cf8c
int MPI_Allgatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
Packit Service c5cf8c
                   void *recvbuf, const int *recvcounts, const int *displs,
Packit Service c5cf8c
                   MPI_Datatype recvtype, MPI_Comm comm)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int mpi_errno = MPI_SUCCESS;
Packit Service c5cf8c
    MPIR_Comm *comm_ptr = NULL;
Packit Service c5cf8c
    MPIR_Errflag_t errflag = MPIR_ERR_NONE;
Packit Service c5cf8c
    MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_ALLGATHERV);
Packit Service c5cf8c
Packit Service c5cf8c
    MPIR_ERRTEST_INITIALIZED_ORDIE();
Packit Service c5cf8c
Packit Service c5cf8c
    MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
Packit Service c5cf8c
    MPIR_FUNC_TERSE_COLL_ENTER(MPID_STATE_MPI_ALLGATHERV);
Packit Service c5cf8c
Packit Service c5cf8c
    /* Validate parameters, especially handles needing to be converted */
Packit Service c5cf8c
#ifdef HAVE_ERROR_CHECKING
Packit Service c5cf8c
    {
Packit Service c5cf8c
        MPID_BEGIN_ERROR_CHECKS;
Packit Service c5cf8c
        {
Packit Service c5cf8c
            MPIR_ERRTEST_COMM(comm, mpi_errno);
Packit Service c5cf8c
        }
Packit Service c5cf8c
        MPID_END_ERROR_CHECKS;
Packit Service c5cf8c
    }
Packit Service c5cf8c
#endif /* HAVE_ERROR_CHECKING */
Packit Service c5cf8c
Packit Service c5cf8c
    /* Convert MPI object handles to object pointers */
Packit Service c5cf8c
    MPIR_Comm_get_ptr(comm, comm_ptr);
Packit Service c5cf8c
Packit Service c5cf8c
    /* Validate parameters and objects (post conversion) */
Packit Service c5cf8c
#ifdef HAVE_ERROR_CHECKING
Packit Service c5cf8c
    {
Packit Service c5cf8c
        MPID_BEGIN_ERROR_CHECKS;
Packit Service c5cf8c
        {
Packit Service c5cf8c
            MPIR_Datatype *recvtype_ptr = NULL, *sendtype_ptr = NULL;
Packit Service c5cf8c
            int i, comm_size;
Packit Service c5cf8c
Packit Service c5cf8c
            MPIR_Comm_valid_ptr(comm_ptr, mpi_errno, FALSE);
Packit Service c5cf8c
            if (mpi_errno != MPI_SUCCESS)
Packit Service c5cf8c
                goto fn_fail;
Packit Service c5cf8c
Packit Service c5cf8c
            if (comm_ptr->comm_kind == MPIR_COMM_KIND__INTERCOMM)
Packit Service c5cf8c
                MPIR_ERRTEST_SENDBUF_INPLACE(sendbuf, sendcount, mpi_errno);
Packit Service c5cf8c
            if (sendbuf != MPI_IN_PLACE) {
Packit Service c5cf8c
                MPIR_ERRTEST_COUNT(sendcount, mpi_errno);
Packit Service c5cf8c
                MPIR_ERRTEST_DATATYPE(sendtype, "sendtype", mpi_errno);
Packit Service c5cf8c
                if (HANDLE_GET_KIND(sendtype) != HANDLE_KIND_BUILTIN) {
Packit Service c5cf8c
                    MPIR_Datatype_get_ptr(sendtype, sendtype_ptr);
Packit Service c5cf8c
                    MPIR_Datatype_valid_ptr(sendtype_ptr, mpi_errno);
Packit Service c5cf8c
                    if (mpi_errno != MPI_SUCCESS)
Packit Service c5cf8c
                        goto fn_fail;
Packit Service c5cf8c
                    MPIR_Datatype_committed_ptr(sendtype_ptr, mpi_errno);
Packit Service c5cf8c
                    if (mpi_errno != MPI_SUCCESS)
Packit Service c5cf8c
                        goto fn_fail;
Packit Service c5cf8c
                }
Packit Service c5cf8c
                MPIR_ERRTEST_USERBUFFER(sendbuf, sendcount, sendtype, mpi_errno);
Packit Service c5cf8c
Packit Service c5cf8c
                /* catch common aliasing cases */
Packit Service c5cf8c
                if (comm_ptr->comm_kind == MPIR_COMM_KIND__INTRACOMM &&
Packit Service c5cf8c
                    sendtype == recvtype && recvcounts[comm_ptr->rank] != 0 && sendcount != 0) {
Packit Service c5cf8c
                    int recvtype_size;
Packit Service c5cf8c
                    MPIR_Datatype_get_size_macro(recvtype, recvtype_size);
Packit Service c5cf8c
                    MPIR_ERRTEST_ALIAS_COLL(sendbuf,
Packit Service c5cf8c
                                            (char *) recvbuf +
Packit Service c5cf8c
                                            displs[comm_ptr->rank] * recvtype_size, mpi_errno);
Packit Service c5cf8c
                }
Packit Service c5cf8c
            }
Packit Service c5cf8c
Packit Service c5cf8c
            if (comm_ptr->comm_kind == MPIR_COMM_KIND__INTRACOMM)
Packit Service c5cf8c
                comm_size = comm_ptr->local_size;
Packit Service c5cf8c
            else
Packit Service c5cf8c
                comm_size = comm_ptr->remote_size;
Packit Service c5cf8c
Packit Service c5cf8c
            for (i = 0; i < comm_size; i++) {
Packit Service c5cf8c
                MPIR_ERRTEST_COUNT(recvcounts[i], mpi_errno);
Packit Service c5cf8c
                MPIR_ERRTEST_DATATYPE(recvtype, "recvtype", mpi_errno);
Packit Service c5cf8c
            }
Packit Service c5cf8c
Packit Service c5cf8c
            if (HANDLE_GET_KIND(recvtype) != HANDLE_KIND_BUILTIN) {
Packit Service c5cf8c
                MPIR_Datatype_get_ptr(recvtype, recvtype_ptr);
Packit Service c5cf8c
                MPIR_Datatype_valid_ptr(recvtype_ptr, mpi_errno);
Packit Service c5cf8c
                if (mpi_errno != MPI_SUCCESS)
Packit Service c5cf8c
                    goto fn_fail;
Packit Service c5cf8c
                MPIR_Datatype_committed_ptr(recvtype_ptr, mpi_errno);
Packit Service c5cf8c
                if (mpi_errno != MPI_SUCCESS)
Packit Service c5cf8c
                    goto fn_fail;
Packit Service c5cf8c
            }
Packit Service c5cf8c
            for (i = 0; i < comm_size; i++) {
Packit Service c5cf8c
                if (recvcounts[i] > 0) {
Packit Service c5cf8c
                    MPIR_ERRTEST_RECVBUF_INPLACE(recvbuf, recvcounts[i], mpi_errno);
Packit Service c5cf8c
                    MPIR_ERRTEST_USERBUFFER(recvbuf, recvcounts[i], recvtype, mpi_errno);
Packit Service c5cf8c
                    break;
Packit Service c5cf8c
                }
Packit Service c5cf8c
            }
Packit Service c5cf8c
        }
Packit Service c5cf8c
        MPID_END_ERROR_CHECKS;
Packit Service c5cf8c
    }
Packit Service c5cf8c
#endif /* HAVE_ERROR_CHECKING */
Packit Service c5cf8c
Packit Service c5cf8c
    /* ... body of routine ...  */
Packit Service c5cf8c
Packit Service c5cf8c
    mpi_errno = MPIR_Allgatherv(sendbuf, sendcount, sendtype,
Packit Service c5cf8c
                                recvbuf, recvcounts, displs, recvtype, comm_ptr, &errflag);
Packit Service c5cf8c
    if (mpi_errno)
Packit Service c5cf8c
        goto fn_fail;
Packit Service c5cf8c
Packit Service c5cf8c
    /* ... end of body of routine ... */
Packit Service c5cf8c
Packit Service c5cf8c
  fn_exit:
Packit Service c5cf8c
    MPIR_FUNC_TERSE_COLL_EXIT(MPID_STATE_MPI_ALLGATHERV);
Packit Service c5cf8c
    MPID_THREAD_CS_EXIT(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
Packit Service c5cf8c
    return mpi_errno;
Packit Service c5cf8c
Packit Service c5cf8c
  fn_fail:
Packit Service c5cf8c
    /* --BEGIN ERROR HANDLING-- */
Packit Service c5cf8c
#ifdef HAVE_ERROR_CHECKING
Packit Service c5cf8c
    {
Packit Service c5cf8c
        mpi_errno =
Packit Service c5cf8c
            MPIR_Err_create_code(mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER,
Packit Service c5cf8c
                                 "**mpi_allgatherv", "**mpi_allgatherv %p %d %D %p %p %p %D %C",
Packit Service c5cf8c
                                 sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs,
Packit Service c5cf8c
                                 recvtype, comm);
Packit Service c5cf8c
    }
Packit Service c5cf8c
#endif
Packit Service c5cf8c
    mpi_errno = MPIR_Err_return_comm(comm_ptr, FCNAME, mpi_errno);
Packit Service c5cf8c
    goto fn_exit;
Packit Service c5cf8c
    /* --END ERROR HANDLING-- */
Packit Service c5cf8c
}