From a7dc6bc3384a34bdcd438a09c7814a9fc8a1471e Mon Sep 17 00:00:00 2001 From: Rich Graham Date: Mon, 15 Mar 2004 22:14:08 +0000 Subject: [PATCH] add error checking. Fix reference counts for procs in new groups. remove special treatment for creating new empty groups (i.e. they are no longer mapped to group_empty. Implement group_free. This commit was SVN r856. --- src/mpi/group/group.h | 5 ++ src/mpi/group/mpi_group_init.c | 54 ++++++++++++++------- src/mpi/interface/c/group_compare.c | 11 ++++- src/mpi/interface/c/group_free.c | 23 ++++++++- src/mpi/interface/c/group_rank.c | 9 ++++ src/mpi/interface/c/group_size.c | 8 +++ src/mpi/interface/c/group_translate_ranks.c | 4 +- src/mpi/interface/c/group_union.c | 28 ++++------- 8 files changed, 103 insertions(+), 39 deletions(-) diff --git a/src/mpi/group/group.h b/src/mpi/group/group.h index f39781845b..e52ea0312d 100644 --- a/src/mpi/group/group.h +++ b/src/mpi/group/group.h @@ -50,6 +50,11 @@ extern lam_pointer_array_t *lam_group_f_to_c_table; */ lam_group_t *group_allocate(int group_size); +/* + * increment the reference count of the proc structures + */ +void lam_group_increment_proc_count(lam_group_t *group); + /** * Initialize LAM group infrastructure * diff --git a/src/mpi/group/mpi_group_init.c b/src/mpi/group/mpi_group_init.c index b174793e1e..75ccffe923 100644 --- a/src/mpi/group/mpi_group_init.c +++ b/src/mpi/group/mpi_group_init.c @@ -58,37 +58,58 @@ lam_group_t *group_allocate(int group_size) /* create new group group element */ new_group=OBJ_NEW(lam_group_t); + if( -1 == new_group->grp_f_to_c_index){ + OBJ_RELEASE(new_group); + new_group=NULL; + } if( new_group ) { /* allocate array of (lam_proc_t *)'s, one for each * process in the group */ new_group->grp_proc_pointers= malloc(sizeof(lam_proc_t *)*group_size); - if( new_group->grp_proc_pointers ) { - /* grp_proc_pointers allocated */ - new_group->grp_proc_count=group_size; - /* assign entry in fortran <-> c translation array */ - ret_val=lam_pointer_array_add(lam_group_f_to_c_table,new_group); - if( -1 == ret_val ){ - OBJ_RELEASE(new_group); + if( 0 < group_size ) { + /* non-empty group */ + if( !new_group->grp_proc_pointers ) { + /* grp_proc_pointers allocation failed */ + free(new_group); new_group=NULL; } - new_group->grp_f_to_c_index=ret_val; - } else { - /* grp_proc_pointers allocation failed */ - free(new_group); - new_group=NULL; } + + /* set the group size */ + new_group->grp_proc_count=group_size; } /* return */ return new_group; } +/* + * increment the reference count of the proc structures + */ +void lam_group_increment_proc_count(lam_group_t *group) { + /* local variable */ + int proc; + + for(proc=0 ; proc < group->grp_proc_count ; proc++ ) { + OBJ_RETAIN(group->grp_proc_pointers[proc]); + } + + /* return */ + return; +} + /** * group constructor */ -void lam_group_construct(lam_group_t *new_group){ +void lam_group_construct(lam_group_t *new_group) +{ + int ret_val; + + /* assign entry in fortran <-> c translation array */ + ret_val=lam_pointer_array_add(lam_group_f_to_c_table,new_group); + new_group->grp_f_to_c_index=ret_val; /* return */ return; @@ -97,8 +118,8 @@ void lam_group_construct(lam_group_t *new_group){ /** * group destructor */ -void lam_group_destruct(lam_group_t *group){ - +void lam_group_destruct(lam_group_t *group) +{ /* release thegrp_proc_pointers memory */ if( NULL != group->grp_proc_pointers ) free(group->grp_proc_pointers); @@ -123,6 +144,7 @@ int lam_group_init(void) { /* local variables */ int return_value,ret_val; + lam_group_t *new_group_pointer; return_value=LAM_SUCCESS; @@ -154,8 +176,6 @@ int lam_group_init(void) }; lam_mpi_group_empty.grp_f_to_c_index=ret_val; - /* contruct group for MPI_COMM_WORLD */ - /* return */ return return_value; } diff --git a/src/mpi/interface/c/group_compare.c b/src/mpi/interface/c/group_compare.c index a5b68cb5a1..63b12779e6 100644 --- a/src/mpi/interface/c/group_compare.c +++ b/src/mpi/interface/c/group_compare.c @@ -19,9 +19,17 @@ int MPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result) { lam_group_t *group1_pointer, *group2_pointer; lam_proc_t *proc1_pointer, *proc2_pointer; + /* initialization */ return_value=MPI_SUCCESS; + /* check for errors */ + if( MPI_PARAM_CHECK ) { + if( ( MPI_GROUP_NULL == group1 ) || ( MPI_GROUP_NULL == group2 ) ){ + return MPI_ERR_GROUP; + } + } + /* check for same groups */ if( group1 == group2 ) { *result=MPI_IDENT; @@ -29,8 +37,7 @@ int MPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result) { } /* check to see if either is MPI_GROUP_NULL or MPI_GROUP_EMPTY */ - if( ( MPI_GROUP_NULL == group1 ) || ( MPI_GROUP_EMPTY == group1 ) || - ( MPI_GROUP_NULL == group2 ) || ( MPI_GROUP_EMPTY == group2 ) ) { + if( ( MPI_GROUP_EMPTY == group1 ) || ( MPI_GROUP_EMPTY == group2 ) ) { *result=MPI_UNEQUAL; return return_value; } diff --git a/src/mpi/interface/c/group_free.c b/src/mpi/interface/c/group_free.c index b3b53babfa..f57a0884d5 100644 --- a/src/mpi/interface/c/group_free.c +++ b/src/mpi/interface/c/group_free.c @@ -6,11 +6,32 @@ #include "mpi.h" #include "mpi/interface/c/bindings.h" +#include "mpi/group/group.h" #if LAM_HAVE_WEAK_SYMBOLS && LAM_PROFILING_DEFINES #pragma weak MPI_Group_free = PMPI_Group_free #endif -int MPI_Group_free(MPI_Group *group) { +int MPI_Group_free(MPI_Group *group) +{ + /* local variables */ + int proc; + lam_group_t *l_group; + + /* check to make sure we don't free GROUP_EMPTY or GROUP_NULL */ + if( MPI_PARAM_CHECK ) { + if( (MPI_GROUP_NULL == group) || (MPI_GROUP_EMPTY == group ) ) { + return MPI_ERR_GROUP; + } + } + + l_group=(lam_group_t *)group; + + /* decrement proc reference count */ + for(proc=0 ; proc < l_group->grp_proc_count ; proc++ ) { + OBJ_RELEASE(l_group->grp_proc_pointers[proc]); + } + + OBJ_RELEASE(group); return MPI_SUCCESS; } diff --git a/src/mpi/interface/c/group_rank.c b/src/mpi/interface/c/group_rank.c index e64f7272e9..030100da25 100644 --- a/src/mpi/interface/c/group_rank.c +++ b/src/mpi/interface/c/group_rank.c @@ -13,6 +13,15 @@ #endif int MPI_Group_rank(MPI_Group group, int *rank) { + + /* error checking */ + if( MPI_PARAM_CHECK ) { + if( MPI_GROUP_NULL == group ){ + return MPI_ERR_GROUP; + } + } + *rank=lam_group_rank((lam_group_t *)group); + return MPI_SUCCESS; } diff --git a/src/mpi/interface/c/group_size.c b/src/mpi/interface/c/group_size.c index 53fefb13ee..51796d69ae 100644 --- a/src/mpi/interface/c/group_size.c +++ b/src/mpi/interface/c/group_size.c @@ -13,6 +13,14 @@ #endif int MPI_Group_size(MPI_Group group, int *size) { + + /* error checking */ + if( MPI_PARAM_CHECK ) { + if( MPI_GROUP_NULL == group ) { + return MPI_ERR_GROUP; + } + } + *size=lam_group_size((lam_group_t *)group); return MPI_SUCCESS; } diff --git a/src/mpi/interface/c/group_translate_ranks.c b/src/mpi/interface/c/group_translate_ranks.c index 527c8257ed..92e8d16f54 100644 --- a/src/mpi/interface/c/group_translate_ranks.c +++ b/src/mpi/interface/c/group_translate_ranks.c @@ -24,10 +24,12 @@ int MPI_Group_translate_ranks(MPI_Group group1, int n_ranks, int *ranks1, /* check for errors */ if( MPI_PARAM_CHECK ) { + if( (MPI_GROUP_NULL == group1) || (MPI_GROUP_NULL == group2 ) ) { + return MPI_ERR_GROUP; + } if( n_ranks > group1_pointer->grp_proc_count ){ return MPI_ERR_GROUP; } - } /* loop over all ranks */ diff --git a/src/mpi/interface/c/group_union.c b/src/mpi/interface/c/group_union.c index d58311c518..882331c9ae 100644 --- a/src/mpi/interface/c/group_union.c +++ b/src/mpi/interface/c/group_union.c @@ -20,28 +20,17 @@ int MPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group *new_group) lam_group_t *group1_pointer, *group2_pointer, *new_group_pointer; lam_proc_t *proc1_pointer, *proc2_pointer, *my_proc_pointer; + /* check for errors */ + if( MPI_PARAM_CHECK ) { + if( ( MPI_GROUP_NULL == group1 ) || ( MPI_GROUP_NULL == group2 ) ){ + return MPI_ERR_GROUP; + } + } + return_value=MPI_SUCCESS; group1_pointer= (lam_group_t *) group1; group2_pointer= (lam_group_t *) group2; - /* check to see if one of the groups is the empty group */ - if ((MPI_GROUP_EMPTY == group1) && (MPI_GROUP_EMPTY == group2)) { - /* both group1 and group2 are MPI_GROUP_EMPTY */ - *new_group = MPI_GROUP_EMPTY; - return return_value; - } else if ( MPI_GROUP_EMPTY == group1 ) { - /* group1 is MPI_GROUP_EMPTY */ - *new_group = group2; - /* increment group count */ - OBJ_RETAIN(group2_pointer); - return return_value; - } else if ( MPI_GROUP_EMPTY == group2 ) { - /* group2 is MPI_GROUP_EMPTY */ - *new_group = group1; - /* increment group count */ - OBJ_RETAIN(group1_pointer); - return return_value; - } /* * form union */ @@ -108,6 +97,9 @@ int MPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group *new_group) cnt++; } /* end proc loop */ + /* increment proc reference counters */ + lam_group_increment_proc_count(new_group_pointer); + /* find my rank */ my_group_rank=group1_pointer->grp_my_rank; my_proc_pointer=group1_pointer->grp_proc_pointers[my_group_rank];