Blame src/mpi/comm/comm_agree.c

Packit Service c5cf8c
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
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
#include "mpicomm.h"
Packit Service c5cf8c
#include <stdint.h>
Packit Service c5cf8c
Packit Service c5cf8c
/* -- Begin Profiling Symbol Block for routine MPIX_Comm_agree */
Packit Service c5cf8c
#if defined(HAVE_PRAGMA_WEAK)
Packit Service c5cf8c
#pragma weak MPIX_Comm_agree = PMPIX_Comm_agree
Packit Service c5cf8c
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
Packit Service c5cf8c
#pragma _HP_SECONDARY_DEF PMPIX_Comm_agree  MPIX_Comm_agree
Packit Service c5cf8c
#elif defined(HAVE_PRAGMA_CRI_DUP)
Packit Service c5cf8c
#pragma _CRI duplicate MPIX_Comm_agree as PMPIX_Comm_agree
Packit Service c5cf8c
#elif defined(HAVE_WEAK_ATTRIBUTE)
Packit Service c5cf8c
int MPIX_Comm_agree(MPI_Comm comm, int *flag) __attribute__ ((weak, alias("PMPIX_Comm_agree")));
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 MPIX_Comm_agree
Packit Service c5cf8c
#define MPIX_Comm_agree PMPIX_Comm_agree
Packit Service c5cf8c
Packit Service c5cf8c
#undef FUNCNAME
Packit Service c5cf8c
#define FUNCNAME MPIR_Comm_agree
Packit Service c5cf8c
#undef FCNAME
Packit Service c5cf8c
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit Service c5cf8c
int MPIR_Comm_agree(MPIR_Comm * comm_ptr, int *flag)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int mpi_errno = MPI_SUCCESS, mpi_errno_tmp = MPI_SUCCESS;
Packit Service c5cf8c
    MPIR_Group *comm_grp = NULL, *failed_grp = NULL, *new_group_ptr = NULL, *global_failed = NULL;
Packit Service c5cf8c
    int result, success = 1;
Packit Service c5cf8c
    MPIR_Errflag_t errflag = MPIR_ERR_NONE;
Packit Service c5cf8c
    int values[2];
Packit Service c5cf8c
Packit Service c5cf8c
    MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPIR_COMM_AGREE);
Packit Service c5cf8c
    MPIR_FUNC_TERSE_ENTER(MPID_STATE_MPIR_COMM_AGREE);
Packit Service c5cf8c
Packit Service c5cf8c
    MPIR_Comm_group_impl(comm_ptr, &comm_grp);
Packit Service c5cf8c
Packit Service c5cf8c
    /* Get the locally known (not acknowledged) group of failed procs */
Packit Service c5cf8c
    mpi_errno = MPID_Comm_failure_get_acked(comm_ptr, &failed_grp);
Packit Service c5cf8c
    if (mpi_errno)
Packit Service c5cf8c
        MPIR_ERR_POP(mpi_errno);
Packit Service c5cf8c
Packit Service c5cf8c
    /* First decide on the group of failed procs. */
Packit Service c5cf8c
    mpi_errno = MPID_Comm_get_all_failed_procs(comm_ptr, &global_failed, MPIR_AGREE_TAG);
Packit Service c5cf8c
    if (mpi_errno)
Packit Service c5cf8c
        errflag = MPIR_ERR_PROC_FAILED;
Packit Service c5cf8c
Packit Service c5cf8c
    mpi_errno = MPIR_Group_compare_impl(failed_grp, global_failed, &result);
Packit Service c5cf8c
    if (mpi_errno)
Packit Service c5cf8c
        MPIR_ERR_POP(mpi_errno);
Packit Service c5cf8c
Packit Service c5cf8c
    /* Create a subgroup without the failed procs */
Packit Service c5cf8c
    mpi_errno = MPIR_Group_difference_impl(comm_grp, global_failed, &new_group_ptr);
Packit Service c5cf8c
    if (mpi_errno)
Packit Service c5cf8c
        MPIR_ERR_POP(mpi_errno);
Packit Service c5cf8c
Packit Service c5cf8c
    /* If that group isn't the same as what we think is failed locally, then
Packit Service c5cf8c
     * mark it as such. */
Packit Service c5cf8c
    if (result == MPI_UNEQUAL || errflag)
Packit Service c5cf8c
        success = 0;
Packit Service c5cf8c
Packit Service c5cf8c
    /* Do an allreduce to decide whether or not anyone thinks the group
Packit Service c5cf8c
     * has changed */
Packit Service c5cf8c
    mpi_errno_tmp = MPII_Allreduce_group(MPI_IN_PLACE, &success, 1, MPI_INT, MPI_MIN, comm_ptr,
Packit Service c5cf8c
                                         new_group_ptr, MPIR_AGREE_TAG, &errflag);
Packit Service c5cf8c
    if (!success || errflag || mpi_errno_tmp)
Packit Service c5cf8c
        success = 0;
Packit Service c5cf8c
Packit Service c5cf8c
    values[0] = success;
Packit Service c5cf8c
    values[1] = *flag;
Packit Service c5cf8c
Packit Service c5cf8c
    /* Determine both the result of this function (mpi_errno) and the result
Packit Service c5cf8c
     * of flag that will be returned to the user. */
Packit Service c5cf8c
    MPII_Allreduce_group(MPI_IN_PLACE, values, 2, MPI_INT, MPI_BAND, comm_ptr,
Packit Service c5cf8c
                         new_group_ptr, MPIR_AGREE_TAG, &errflag);
Packit Service c5cf8c
    /* Ignore the result of the operation this time. Everyone will either
Packit Service c5cf8c
     * return a failure because of !success earlier or they will return
Packit Service c5cf8c
     * something useful for flag because of this operation. If there was a new
Packit Service c5cf8c
     * failure in between the first allreduce and the second one, it's ignored
Packit Service c5cf8c
     * here. */
Packit Service c5cf8c
Packit Service c5cf8c
    if (failed_grp != MPIR_Group_empty)
Packit Service c5cf8c
        MPIR_Group_release(failed_grp);
Packit Service c5cf8c
    MPIR_Group_release(new_group_ptr);
Packit Service c5cf8c
    MPIR_Group_release(comm_grp);
Packit Service c5cf8c
    if (global_failed != MPIR_Group_empty)
Packit Service c5cf8c
        MPIR_Group_release(global_failed);
Packit Service c5cf8c
Packit Service c5cf8c
    success = values[0];
Packit Service c5cf8c
    *flag = values[1];
Packit Service c5cf8c
Packit Service c5cf8c
    if (!success) {
Packit Service c5cf8c
        MPIR_ERR_SET(mpi_errno_tmp, MPIX_ERR_PROC_FAILED, "**mpix_comm_agree");
Packit Service c5cf8c
        MPIR_ERR_ADD(mpi_errno, mpi_errno_tmp);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
  fn_exit:
Packit Service c5cf8c
    MPIR_FUNC_TERSE_EXIT(MPID_STATE_MPIR_COMM_AGREE);
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
#endif /* !defined(MPICH_MPI_FROM_PMPI) */
Packit Service c5cf8c
Packit Service c5cf8c
#undef FUNCNAME
Packit Service c5cf8c
#define FUNCNAME MPIX_Comm_agree
Packit Service c5cf8c
#undef FCNAME
Packit Service c5cf8c
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit Service c5cf8c
/*@
Packit Service c5cf8c
MPIX_Comm_agree - Performs agreement operation on comm
Packit Service c5cf8c
Packit Service c5cf8c
Input Parameters:
Packit Service c5cf8c
. comm - communicator (handle)
Packit Service c5cf8c
Packit Service c5cf8c
Output Parameters:
Packit Service c5cf8c
. newcomm - new communicator (handle)
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_SUCCESS
Packit Service c5cf8c
.N MPI_ERR_COMM
Packit Service c5cf8c
Packit Service c5cf8c
@*/
Packit Service c5cf8c
int MPIX_Comm_agree(MPI_Comm comm, int *flag)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int mpi_errno = MPI_SUCCESS;
Packit Service c5cf8c
    MPIR_Comm *comm_ptr = NULL;
Packit Service c5cf8c
    MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPIX_COMM_AGREE);
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_ENTER(MPID_STATE_MPIX_COMM_AGREE);
Packit Service c5cf8c
Packit Service c5cf8c
    /* Validate parameters, and convert MPI object handles to object pointers */
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
        MPIR_Comm_get_ptr(comm, comm_ptr);
Packit Service c5cf8c
Packit Service c5cf8c
        MPID_BEGIN_ERROR_CHECKS;
Packit Service c5cf8c
        {
Packit Service c5cf8c
            /* Validate comm_ptr */
Packit Service c5cf8c
            MPIR_Comm_valid_ptr(comm_ptr, mpi_errno, TRUE);
Packit Service c5cf8c
            if (mpi_errno)
Packit Service c5cf8c
                goto fn_fail;
Packit Service c5cf8c
        }
Packit Service c5cf8c
        MPID_END_ERROR_CHECKS;
Packit Service c5cf8c
    }
Packit Service c5cf8c
#else
Packit Service c5cf8c
    {
Packit Service c5cf8c
        MPIR_Comm_get_ptr(comm, comm_ptr);
Packit Service c5cf8c
    }
Packit Service c5cf8c
#endif
Packit Service c5cf8c
Packit Service c5cf8c
    /* ... body of routine ... */
Packit Service c5cf8c
    mpi_errno = MPIR_Comm_agree(comm_ptr, flag);
Packit Service c5cf8c
    if (mpi_errno)
Packit Service c5cf8c
        MPIR_ERR_POP(mpi_errno);
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_EXIT(MPID_STATE_MPIX_COMM_AGREE);
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__,
Packit Service c5cf8c
                                 MPI_ERR_OTHER, "**mpix_comm_agree", "**mpix_comm_agree %C", 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
}