Blame src/mpi/coll/bcast/bcast_inter_remote_send_local_bcast.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
/* Intercommunicator broadcast
Packit Service c5cf8c
 *
Packit Service c5cf8c
 * Root sends to rank 0 in remote group.  Remote group does local
Packit Service c5cf8c
 * intracommunicator broadcast.
Packit Service c5cf8c
 */
Packit Service c5cf8c
Packit Service c5cf8c
#undef FUNCNAME
Packit Service c5cf8c
#define FUNCNAME MPIR_Bcast_inter_remote_send_local_bcast
Packit Service c5cf8c
#undef FCNAME
Packit Service c5cf8c
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit Service c5cf8c
int MPIR_Bcast_inter_remote_send_local_bcast(void *buffer,
Packit Service c5cf8c
                                             int count,
Packit Service c5cf8c
                                             MPI_Datatype datatype,
Packit Service c5cf8c
                                             int root,
Packit Service c5cf8c
                                             MPIR_Comm * comm_ptr, MPIR_Errflag_t * errflag)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int rank, mpi_errno;
Packit Service c5cf8c
    int mpi_errno_ret = MPI_SUCCESS;
Packit Service c5cf8c
    MPI_Status status;
Packit Service c5cf8c
    MPIR_Comm *newcomm_ptr = NULL;
Packit Service c5cf8c
    MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPIR_BCAST_INTER);
Packit Service c5cf8c
Packit Service c5cf8c
    MPIR_FUNC_TERSE_ENTER(MPID_STATE_MPIR_BCAST_INTER);
Packit Service c5cf8c
Packit Service c5cf8c
Packit Service c5cf8c
    if (root == MPI_PROC_NULL) {
Packit Service c5cf8c
        /* local processes other than root do nothing */
Packit Service c5cf8c
        mpi_errno = MPI_SUCCESS;
Packit Service c5cf8c
    } else if (root == MPI_ROOT) {
Packit Service c5cf8c
        /* root sends to rank 0 on remote group and returns */
Packit Service c5cf8c
        mpi_errno = MPIC_Send(buffer, count, datatype, 0, MPIR_BCAST_TAG, comm_ptr, 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
    } else {
Packit Service c5cf8c
        /* remote group. rank 0 on remote group receives from root */
Packit Service c5cf8c
Packit Service c5cf8c
        rank = comm_ptr->rank;
Packit Service c5cf8c
Packit Service c5cf8c
        if (rank == 0) {
Packit Service c5cf8c
            mpi_errno = MPIC_Recv(buffer, count, datatype, root,
Packit Service c5cf8c
                                  MPIR_BCAST_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
Packit Service c5cf8c
        /* Get the local intracommunicator */
Packit Service c5cf8c
        if (!comm_ptr->local_comm) {
Packit Service c5cf8c
            mpi_errno = MPII_Setup_intercomm_localcomm(comm_ptr);
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
        newcomm_ptr = comm_ptr->local_comm;
Packit Service c5cf8c
Packit Service c5cf8c
        /* now do the usual broadcast on this intracommunicator
Packit Service c5cf8c
         * with rank 0 as root. */
Packit Service c5cf8c
        mpi_errno = MPIR_Bcast_intra_auto(buffer, count, datatype, 0, newcomm_ptr, 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
    MPIR_FUNC_TERSE_EXIT(MPID_STATE_MPIR_BCAST_INTER);
Packit Service c5cf8c
    /* --BEGIN ERROR HANDLING-- */
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, MPI_ERR_OTHER, "**coll_fail");
Packit Service c5cf8c
    /* --END ERROR HANDLING-- */
Packit Service c5cf8c
    return mpi_errno;
Packit Service c5cf8c
}