2004-01-21 03:05:46 +03:00
|
|
|
/*
|
2007-03-17 02:11:45 +03:00
|
|
|
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
|
2005-11-05 22:57:48 +03:00
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2007-03-16 16:09:49 +03:00
|
|
|
* Copyright (c) 2007 Cisco, Inc. All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-10-15 23:31:47 +04:00
|
|
|
* $HEADER$
|
2004-01-21 03:05:46 +03:00
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "ompi_config.h"
|
2004-01-21 03:05:46 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "ompi/mpi/c/bindings.h"
|
2004-01-21 03:05:46 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#if OMPI_HAVE_WEAK_SYMBOLS && OMPI_PROFILING_DEFINES
|
2004-01-21 03:05:46 +03:00
|
|
|
#pragma weak MPI_Comm_compare = PMPI_Comm_compare
|
|
|
|
#endif
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#if OMPI_PROFILING_DEFINES
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "ompi/mpi/c/profile/defines.h"
|
2004-04-20 22:50:43 +04:00
|
|
|
#endif
|
|
|
|
|
2004-07-30 06:58:53 +04:00
|
|
|
static const char FUNC_NAME[] = "MPI_Comm_compare";
|
2004-06-23 00:21:35 +04:00
|
|
|
|
|
|
|
|
2004-01-21 03:05:46 +03:00
|
|
|
int MPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result) {
|
2004-03-26 23:03:38 +03:00
|
|
|
|
|
|
|
/* local variables */
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_communicator_t *comp1, *comp2;
|
2004-10-22 20:06:05 +04:00
|
|
|
ompi_group_t *group1, *group2;
|
2004-03-26 23:03:38 +03:00
|
|
|
int size1, size2, rsize1, rsize2;
|
2004-09-21 14:41:50 +04:00
|
|
|
int lresult, rresult=MPI_CONGRUENT;
|
2004-10-22 20:06:05 +04:00
|
|
|
int sameranks=1;
|
|
|
|
int sameorder=1;
|
2004-03-26 23:03:38 +03:00
|
|
|
int i, j;
|
|
|
|
int found = 0;
|
2004-10-22 20:06:05 +04:00
|
|
|
|
2007-03-17 02:11:45 +03:00
|
|
|
OPAL_CR_TEST_CHECKPOINT_READY();
|
|
|
|
|
2004-03-26 23:03:38 +03:00
|
|
|
if ( MPI_PARAM_CHECK ) {
|
2004-06-23 00:21:35 +04:00
|
|
|
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
|
2004-03-26 23:03:38 +03:00
|
|
|
|
2007-03-16 16:09:49 +03:00
|
|
|
if (ompi_comm_invalid(comm1) || ompi_comm_invalid(comm2)) {
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM,
|
2004-06-23 00:21:35 +04:00
|
|
|
FUNC_NAME);
|
2007-03-16 16:09:49 +03:00
|
|
|
}
|
2004-03-26 23:03:38 +03:00
|
|
|
|
2007-03-16 16:09:49 +03:00
|
|
|
if ( NULL == result ) {
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(comm1, MPI_ERR_ARG,
|
2004-06-23 00:21:35 +04:00
|
|
|
FUNC_NAME);
|
2007-03-16 16:09:49 +03:00
|
|
|
}
|
2004-03-26 23:03:38 +03:00
|
|
|
}
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
comp1 = (ompi_communicator_t *) comm1;
|
|
|
|
comp2 = (ompi_communicator_t *) comm2;
|
2004-03-26 23:03:38 +03:00
|
|
|
|
2004-07-16 00:55:50 +04:00
|
|
|
if ( comp1->c_contextid == comp2->c_contextid ) {
|
|
|
|
*result = MPI_IDENT;
|
|
|
|
return MPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2004-09-16 14:08:40 +04:00
|
|
|
if ( MPI_COMM_NULL == comm1 || MPI_COMM_NULL == comm2 ) {
|
|
|
|
*result = MPI_UNEQUAL;
|
|
|
|
return MPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2004-03-26 23:03:38 +03:00
|
|
|
/* compare sizes of local and remote groups */
|
2004-06-07 19:33:53 +04:00
|
|
|
size1 = ompi_comm_size (comp1);
|
2004-09-16 14:08:40 +04:00
|
|
|
size2 = ompi_comm_size (comp2);
|
2004-06-07 19:33:53 +04:00
|
|
|
rsize1 = ompi_comm_remote_size (comp1);
|
2004-09-16 14:08:40 +04:00
|
|
|
rsize2 = ompi_comm_remote_size (comp2);
|
2004-03-26 23:03:38 +03:00
|
|
|
|
|
|
|
if ( size1 != size2 || rsize1 != rsize2 ) {
|
|
|
|
*result = MPI_UNEQUAL;
|
|
|
|
return MPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compare local groups */
|
|
|
|
/* we need to check whether the communicators contain
|
|
|
|
the same processes and in the same order */
|
2004-10-22 20:06:05 +04:00
|
|
|
group1 = (ompi_group_t *)comp1->c_local_group;
|
|
|
|
group2 = (ompi_group_t *)comp2->c_local_group;
|
2004-03-26 23:03:38 +03:00
|
|
|
for ( i = 0; i < size1; i++ ) {
|
2004-10-22 20:06:05 +04:00
|
|
|
if ( group1->grp_proc_pointers[i] != group2->grp_proc_pointers[i]) {
|
2004-03-26 23:03:38 +03:00
|
|
|
sameorder = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i = 0; i < size1; i++ ) {
|
|
|
|
found = 0;
|
|
|
|
for ( j = 0; j < size2; j++ ) {
|
2004-10-22 20:06:05 +04:00
|
|
|
if ( group1->grp_proc_pointers[i] == group2->grp_proc_pointers[j]) {
|
2004-03-26 23:03:38 +03:00
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !found ) {
|
|
|
|
sameranks = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( sameranks && sameorder )
|
|
|
|
lresult = MPI_CONGRUENT;
|
2004-07-16 00:55:50 +04:00
|
|
|
else if ( sameranks && !sameorder )
|
|
|
|
lresult = MPI_SIMILAR;
|
2004-03-26 23:03:38 +03:00
|
|
|
else
|
|
|
|
lresult = MPI_UNEQUAL;
|
|
|
|
|
|
|
|
|
|
|
|
if ( rsize1 > 0 ) {
|
|
|
|
/* Compare remote groups for inter-communicators */
|
|
|
|
/* we need to check whether the communicators contain
|
|
|
|
the same processes and in the same order */
|
|
|
|
sameranks = sameorder = 1;
|
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
group1 = (ompi_group_t *)comp1->c_remote_group;
|
|
|
|
group2 = (ompi_group_t *)comp2->c_remote_group;
|
2004-03-26 23:03:38 +03:00
|
|
|
for ( i = 0; i < rsize1; i++ ) {
|
2004-10-22 20:06:05 +04:00
|
|
|
if ( group1->grp_proc_pointers[i] != group2->grp_proc_pointers[i]) {
|
2004-03-26 23:03:38 +03:00
|
|
|
sameorder = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-21 14:31:26 +04:00
|
|
|
for ( i = 0; i < rsize1; i++ ) {
|
2004-03-26 23:03:38 +03:00
|
|
|
found = 0;
|
2004-09-21 14:31:26 +04:00
|
|
|
for ( j = 0; j < rsize2; j++ ) {
|
2004-10-22 20:06:05 +04:00
|
|
|
if ( group1->grp_proc_pointers[i] == group2->grp_proc_pointers[j]) {
|
2004-03-26 23:03:38 +03:00
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !found ) {
|
|
|
|
sameranks = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( sameranks && sameorder )
|
|
|
|
rresult = MPI_CONGRUENT;
|
2004-09-21 14:31:26 +04:00
|
|
|
else if ( sameranks && !sameorder )
|
|
|
|
rresult = MPI_SIMILAR;
|
2004-03-26 23:03:38 +03:00
|
|
|
else
|
|
|
|
rresult = MPI_UNEQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* determine final results */
|
2004-09-21 14:31:26 +04:00
|
|
|
if ( MPI_CONGRUENT == rresult ) {
|
2004-03-26 23:03:38 +03:00
|
|
|
*result = lresult;
|
|
|
|
}
|
2004-09-21 14:31:26 +04:00
|
|
|
else if ( MPI_SIMILAR == rresult ) {
|
|
|
|
if ( MPI_SIMILAR == lresult || MPI_CONGRUENT == lresult ) {
|
2004-03-26 23:03:38 +03:00
|
|
|
*result = MPI_SIMILAR;
|
2004-09-21 14:31:26 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
*result = MPI_UNEQUAL;
|
2004-03-26 23:03:38 +03:00
|
|
|
}
|
|
|
|
else if ( MPI_UNEQUAL == rresult )
|
|
|
|
*result = MPI_UNEQUAL;
|
|
|
|
|
2004-01-21 03:05:46 +03:00
|
|
|
return MPI_SUCCESS;
|
|
|
|
}
|