|
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 |
/* -- Begin Profiling Symbol Block for routine MPI_Comm_compare */
|
|
Packit Service |
c5cf8c |
#if defined(HAVE_PRAGMA_WEAK)
|
|
Packit Service |
c5cf8c |
#pragma weak MPI_Comm_compare = PMPI_Comm_compare
|
|
Packit Service |
c5cf8c |
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
|
|
Packit Service |
c5cf8c |
#pragma _HP_SECONDARY_DEF PMPI_Comm_compare MPI_Comm_compare
|
|
Packit Service |
c5cf8c |
#elif defined(HAVE_PRAGMA_CRI_DUP)
|
|
Packit Service |
c5cf8c |
#pragma _CRI duplicate MPI_Comm_compare as PMPI_Comm_compare
|
|
Packit Service |
c5cf8c |
#elif defined(HAVE_WEAK_ATTRIBUTE)
|
|
Packit Service |
c5cf8c |
int MPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
|
|
Packit Service |
c5cf8c |
__attribute__ ((weak, alias("PMPI_Comm_compare")));
|
|
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_Comm_compare
|
|
Packit Service |
c5cf8c |
#define MPI_Comm_compare PMPI_Comm_compare
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#undef FUNCNAME
|
|
Packit Service |
c5cf8c |
#define FUNCNAME MPI_Comm_compare
|
|
Packit Service |
c5cf8c |
#undef FCNAME
|
|
Packit Service |
c5cf8c |
#define FCNAME "MPI_Comm_compare"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*@
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_compare - Compares two communicators
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Input Parameters:
|
|
Packit Service |
c5cf8c |
+ comm1 - comm1 (handle)
|
|
Packit Service |
c5cf8c |
- comm2 - comm2 (handle)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Output Parameters:
|
|
Packit Service |
c5cf8c |
. result - integer which is 'MPI_IDENT' if the contexts and groups are the
|
|
Packit Service |
c5cf8c |
same, 'MPI_CONGRUENT' if different contexts but identical groups, 'MPI_SIMILAR'
|
|
Packit Service |
c5cf8c |
if different contexts but similar groups, and 'MPI_UNEQUAL' otherwise
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Using 'MPI_COMM_NULL' with 'MPI_Comm_compare':
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
It is an error to use 'MPI_COMM_NULL' as one of the arguments to
|
|
Packit Service |
c5cf8c |
'MPI_Comm_compare'. The relevant sections of the MPI standard are
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
$(2.4.1 Opaque Objects)
|
|
Packit Service |
c5cf8c |
A null handle argument is an erroneous 'IN' argument in MPI calls, unless an
|
|
Packit Service |
c5cf8c |
exception is explicitly stated in the text that defines the function.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
$(5.4.1. Communicator Accessors)
|
|
Packit Service |
c5cf8c |
where there is no text in 'MPI_COMM_COMPARE' allowing a null handle.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
.N ThreadSafe
|
|
Packit Service |
c5cf8c |
(To perform the communicator comparisions, this routine may need to
|
|
Packit Service |
c5cf8c |
allocate some memory. Memory allocation is not interrupt-safe, and hence
|
|
Packit Service |
c5cf8c |
this routine is only thread-safe.)
|
|
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_ARG
|
|
Packit Service |
c5cf8c |
@*/
|
|
Packit Service |
c5cf8c |
int MPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int mpi_errno = MPI_SUCCESS;
|
|
Packit Service |
c5cf8c |
MPIR_Comm *comm_ptr1 = NULL;
|
|
Packit Service |
c5cf8c |
MPIR_Comm *comm_ptr2 = NULL;
|
|
Packit Service |
c5cf8c |
MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_COMM_COMPARE);
|
|
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_MPI_COMM_COMPARE);
|
|
Packit Service |
c5cf8c |
|
|
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(comm1, mpi_errno);
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_COMM(comm2, 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 |
/* Get handles to MPI objects. */
|
|
Packit Service |
c5cf8c |
MPIR_Comm_get_ptr(comm1, comm_ptr1);
|
|
Packit Service |
c5cf8c |
MPIR_Comm_get_ptr(comm2, comm_ptr2);
|
|
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 |
/* Validate comm_ptr */
|
|
Packit Service |
c5cf8c |
MPIR_Comm_valid_ptr(comm_ptr1, mpi_errno, TRUE);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
goto fn_fail;
|
|
Packit Service |
c5cf8c |
MPIR_Comm_valid_ptr(comm_ptr2, mpi_errno, TRUE);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
goto fn_fail;
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_ARGNULL(result, "result", 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 |
/* ... body of routine ... */
|
|
Packit Service |
c5cf8c |
if (comm_ptr1->comm_kind != comm_ptr2->comm_kind) {
|
|
Packit Service |
c5cf8c |
*result = MPI_UNEQUAL;
|
|
Packit Service |
c5cf8c |
} else if (comm1 == comm2) {
|
|
Packit Service |
c5cf8c |
*result = MPI_IDENT;
|
|
Packit Service |
c5cf8c |
} else if (comm_ptr1->comm_kind == MPIR_COMM_KIND__INTRACOMM) {
|
|
Packit Service |
c5cf8c |
MPIR_Group *group_ptr1, *group_ptr2;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Comm_group_impl(comm_ptr1, &group_ptr1);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Comm_group_impl(comm_ptr2, &group_ptr2);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Group_compare_impl(group_ptr1, group_ptr2, result);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
/* If the groups are the same but the contexts are different, then
|
|
Packit Service |
c5cf8c |
* the communicators are congruent */
|
|
Packit Service |
c5cf8c |
if (*result == MPI_IDENT)
|
|
Packit Service |
c5cf8c |
*result = MPI_CONGRUENT;
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Group_free_impl(group_ptr1);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Group_free_impl(group_ptr2);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
/* INTER_COMM */
|
|
Packit Service |
c5cf8c |
int lresult, rresult;
|
|
Packit Service |
c5cf8c |
MPIR_Group *group_ptr1, *group_ptr2;
|
|
Packit Service |
c5cf8c |
MPIR_Group *rgroup_ptr1, *rgroup_ptr2;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Get the groups and see what their relationship is */
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Comm_group_impl(comm_ptr1, &group_ptr1);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Comm_group_impl(comm_ptr2, &group_ptr2);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Group_compare_impl(group_ptr1, group_ptr2, &lresult);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Comm_remote_group_impl(comm_ptr1, &rgroup_ptr1);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Comm_remote_group_impl(comm_ptr2, &rgroup_ptr2);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Group_compare_impl(rgroup_ptr1, rgroup_ptr2, &rresult);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Choose the result that is "least" strong. This works
|
|
Packit Service |
c5cf8c |
* due to the ordering of result types in mpi.h */
|
|
Packit Service |
c5cf8c |
(*result) = (rresult > lresult) ? rresult : lresult;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* They can't be identical since they're not the same
|
|
Packit Service |
c5cf8c |
* handle, they are congruent instead */
|
|
Packit Service |
c5cf8c |
if ((*result) == MPI_IDENT)
|
|
Packit Service |
c5cf8c |
(*result) = MPI_CONGRUENT;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Free the groups */
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Group_free_impl(group_ptr1);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Group_free_impl(group_ptr2);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Group_free_impl(rgroup_ptr1);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Group_free_impl(rgroup_ptr2);
|
|
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_MPI_COMM_COMPARE);
|
|
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 |
/* --BEGIN ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
fn_fail:
|
|
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_comm_compare", "**mpi_comm_compare %C %C %p", comm1, comm2,
|
|
Packit Service |
c5cf8c |
result);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
/* Use whichever communicator is non-null if possible */
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Err_return_comm(comm_ptr1 ? comm_ptr1 : comm_ptr2, FCNAME, mpi_errno);
|
|
Packit Service |
c5cf8c |
goto fn_exit;
|
|
Packit Service |
c5cf8c |
/* --END ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
}
|