2004-01-21 03:05:46 +03:00
|
|
|
/*
|
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>
|
|
|
|
|
|
|
|
#include "mpi.h"
|
2004-03-17 21:45:16 +03:00
|
|
|
#include "mpi/c/bindings.h"
|
2004-03-26 23:03:38 +03:00
|
|
|
#include "communicator/communicator.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
|
2004-04-20 22:50:43 +04:00
|
|
|
#include "mpi/c/profile/defines.h"
|
|
|
|
#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;
|
|
|
|
ompi_group_t *grp1, *grp2;
|
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-03-26 23:03:38 +03:00
|
|
|
int sameranks = 1;
|
|
|
|
int sameorder = 1;
|
|
|
|
int i, j;
|
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
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
|
|
|
|
2004-09-16 14:08:40 +04:00
|
|
|
if ( NULL == comm1 || NULL == 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);
|
2004-03-26 23:03:38 +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);
|
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-06-07 19:33:53 +04:00
|
|
|
grp1 = (ompi_group_t *)comp1->c_local_group;
|
|
|
|
grp2 = (ompi_group_t *)comp2->c_local_group;
|
2004-03-26 23:03:38 +03:00
|
|
|
for ( i = 0; i < size1; i++ ) {
|
|
|
|
if ( grp1->grp_proc_pointers[i] != grp2->grp_proc_pointers[i]) {
|
|
|
|
sameorder = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i = 0; i < size1; i++ ) {
|
|
|
|
found = 0;
|
|
|
|
for ( j = 0; j < size2; j++ ) {
|
|
|
|
if ( grp1->grp_proc_pointers[i] == grp2->grp_proc_pointers[j]) {
|
|
|
|
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-06-07 19:33:53 +04:00
|
|
|
grp1 = (ompi_group_t *)comp1->c_remote_group;
|
|
|
|
grp2 = (ompi_group_t *)comp2->c_remote_group;
|
2004-03-26 23:03:38 +03:00
|
|
|
for ( i = 0; i < rsize1; i++ ) {
|
|
|
|
if ( grp1->grp_proc_pointers[i] != grp2->grp_proc_pointers[i]) {
|
|
|
|
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-03-26 23:03:38 +03:00
|
|
|
if ( grp1->grp_proc_pointers[i] == grp2->grp_proc_pointers[j]) {
|
|
|
|
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;
|
|
|
|
}
|