diff --git a/ompi/group/group.c b/ompi/group/group.c index 6b52d0d3ae..53ab156ca2 100644 --- a/ompi/group/group.c +++ b/ompi/group/group.c @@ -11,6 +11,7 @@ * All rights reserved. * Copyright (c) 2006-2007 University of Houston. All rights reserved. * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2012 Oak Ridge National Labs. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -506,3 +507,73 @@ int ompi_group_intersection(ompi_group_t* group1,ompi_group_t* group2, return result; } + +int ompi_group_compare(ompi_group_t *group1, + ompi_group_t *group2, + int *result) +{ + int return_value = OMPI_SUCCESS; + int proc1, proc2, match; + bool similar, identical; + ompi_group_t *group1_pointer, *group2_pointer; + ompi_proc_t *proc1_pointer, *proc2_pointer; + + /* check for same groups */ + if( group1 == group2 ) { + *result=MPI_IDENT; + return return_value; + } + + /* check to see if either is MPI_GROUP_NULL or MPI_GROUP_EMPTY */ + if( ( MPI_GROUP_EMPTY == group1 ) || ( MPI_GROUP_EMPTY == group2 ) ) { + *result=MPI_UNEQUAL; + return return_value; + } + + /* get group pointers */ + group1_pointer = (ompi_group_t *)group1; + group2_pointer = (ompi_group_t *)group2; + + /* compare sizes */ + if( group1_pointer->grp_proc_count != group2_pointer->grp_proc_count ) { + /* if not same size - return */ + *result=MPI_UNEQUAL; + return return_value; + } + + /* check for similarity */ + /* loop over group1 processes */ + similar=true; + identical=true; + for(proc1=0 ; proc1 < group1_pointer->grp_proc_count ; proc1++ ) { + proc1_pointer= ompi_group_peer_lookup(group1_pointer,proc1); + /* loop over group2 processes to find "match" */ + match=-1; + for(proc2=0 ; proc2 < group2_pointer->grp_proc_count ; proc2++ ) { + proc2_pointer=ompi_group_peer_lookup(group2_pointer,proc2); + if( proc1_pointer == proc2_pointer ) { + if(proc1 != proc2 ) { + identical=false; + } + match=proc2; + break; + } + } /* end proc2 loop */ + if( match== -1 ) { + similar=false; + identical=false; + break; + } + } /* end proc1 loop */ + + /* set comparison result */ + if( identical ) { + *result=MPI_IDENT; + } else if( similar ) { + *result=MPI_SIMILAR; + } else { + *result=MPI_UNEQUAL; + } + + return return_value; +} diff --git a/ompi/group/group.h b/ompi/group/group.h index c1409a193f..6dc0a353bf 100644 --- a/ompi/group/group.h +++ b/ompi/group/group.h @@ -13,6 +13,7 @@ * Copyright (c) 2006-2007 University of Houston. All rights reserved. * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2012 Oak Ridge National Labs. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -233,6 +234,12 @@ OMPI_DECLSPEC int ompi_group_translate_ranks ( ompi_group_t *group1, ompi_group_t *group2, int *ranks2); +/** + * Abstracting MPI_Group_compare to an ompi function for internal use + */ +OMPI_DECLSPEC int ompi_group_compare(ompi_group_t *group1, + ompi_group_t *group2, + int *result); /** * Abstracting MPI_Group_free, since it is required by some internal functions... diff --git a/ompi/group/group_init.c b/ompi/group/group_init.c index 851342056e..ec6bc1706c 100644 --- a/ompi/group/group_init.c +++ b/ompi/group/group_init.c @@ -13,6 +13,7 @@ * Copyright (c) 2006-2007 University of Houston. All rights reserved. * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2012 Oak Ridge National Labs. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -321,7 +322,7 @@ int ompi_group_init(void) ompi_mpi_group_null.group.grp_flags |= OMPI_GROUP_DENSE; ompi_mpi_group_null.group.grp_flags |= OMPI_GROUP_INTRINSIC; - /* add MPI_GROUP_EMPTRY to table */ + /* add MPI_GROUP_EMPTY to table */ OBJ_CONSTRUCT(&ompi_mpi_group_empty, ompi_group_t); ompi_mpi_group_empty.group.grp_proc_count = 0; ompi_mpi_group_empty.group.grp_my_rank = MPI_UNDEFINED; diff --git a/ompi/mpi/c/group_compare.c b/ompi/mpi/c/group_compare.c index 124c05737f..164b4d5a0b 100644 --- a/ompi/mpi/c/group_compare.c +++ b/ompi/mpi/c/group_compare.c @@ -11,6 +11,7 @@ * All rights reserved. * Copyright (c) 2006 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2009 University of Houston. All rights reserved. + * Copyright (c) 2012 Oak Ridge National Labs. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -39,17 +40,7 @@ static const char FUNC_NAME[] = "MPI_Group_compare"; int MPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result) { - - /* local variables */ - int return_value, proc1, proc2, match; - bool similar, identical; - ompi_group_t *group1_pointer, *group2_pointer; - ompi_proc_t *proc1_pointer, *proc2_pointer; - - OPAL_CR_NOOP_PROGRESS(); - - /* initialization */ - return_value=MPI_SUCCESS; + int return_value = MPI_SUCCESS; /* check for errors */ if( MPI_PARAM_CHECK ) { @@ -65,62 +56,9 @@ int MPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result) { } } - /* check for same groups */ - if( group1 == group2 ) { - *result=MPI_IDENT; - return return_value; - } + OPAL_CR_NOOP_PROGRESS(); - /* check to see if either is MPI_GROUP_NULL or MPI_GROUP_EMPTY */ - if( ( MPI_GROUP_EMPTY == group1 ) || ( MPI_GROUP_EMPTY == group2 ) ) { - *result=MPI_UNEQUAL; - return return_value; - } - - /* get group pointers */ - group1_pointer = (ompi_group_t *)group1; - group2_pointer = (ompi_group_t *)group2; - - /* compare sizes */ - if( group1_pointer->grp_proc_count != group2_pointer->grp_proc_count ) { - /* if not same size - return */ - *result=MPI_UNEQUAL; - return return_value; - } - - /* check for similarity */ - /* loop over group1 processes */ - similar=true; - identical=true; - for(proc1=0 ; proc1 < group1_pointer->grp_proc_count ; proc1++ ) { - proc1_pointer= ompi_group_peer_lookup(group1_pointer,proc1); - /* loop over group2 processes to find "match" */ - match=-1; - for(proc2=0 ; proc2 < group2_pointer->grp_proc_count ; proc2++ ) { - proc2_pointer=ompi_group_peer_lookup(group2_pointer,proc2); - if( proc1_pointer == proc2_pointer ) { - if(proc1 != proc2 ) { - identical=false; - } - match=proc2; - break; - } - } /* end proc2 loop */ - if( match== -1 ) { - similar=false; - identical=false; - break; - } - } /* end proc1 loop */ - - /* set comparison result */ - if( identical ) { - *result=MPI_IDENT; - } else if( similar ) { - *result=MPI_SIMILAR; - } else { - *result=MPI_UNEQUAL; - } + return_value = ompi_group_compare((ompi_group_t *)group1, (ompi_group_t *)group2, result); return return_value; }