1
1

fix some bugs in group_incl, implement group_excl.

This commit was SVN r794.
Этот коммит содержится в:
Rich Graham 2004-02-13 22:18:38 +00:00
родитель 81a3c13279
Коммит 577e22bad2
3 изменённых файлов: 119 добавлений и 9 удалений

Просмотреть файл

@ -46,9 +46,10 @@ lam_group_t *group_allocate(int group_size)
/* assign entry in fortran <-> c translation array */ /* assign entry in fortran <-> c translation array */
ret_val=lam_pointer_array_add(lam_group_f_to_c_table,new_group); ret_val=lam_pointer_array_add(lam_group_f_to_c_table,new_group);
if( -1 == ret_val ){ if( -1 == ret_val ){
free(new_group); OBJ_RELEASE(new_group);
new_group=NULL; new_group=NULL;
} }
new_group->grp_f_to_c_index=ret_val;
} else { } else {
/* grp_proc_pointers allocation failed */ /* grp_proc_pointers allocation failed */
free(new_group); free(new_group);
@ -74,6 +75,20 @@ void lam_group_construct(lam_group_t *new_group){
*/ */
void lam_group_destruct(lam_group_t *group){ void lam_group_destruct(lam_group_t *group){
int return_value;
/* release thegrp_proc_pointers memory */
if( NULL != group->grp_proc_pointers )
free(group->grp_proc_pointers);
/* reset the lam_group_f_to_c_table entry - make sure that the
* entry is in the table */
if( NULL!= lam_pointer_array_get_item(lam_group_f_to_c_table,
group->grp_f_to_c_index) ) {
lam_pointer_array_set_item(lam_group_f_to_c_table,
group->grp_f_to_c_index, NULL);
}
/* return */ /* return */
return; return;
} }
@ -82,14 +97,14 @@ void lam_group_destruct(lam_group_t *group){
* Initialize LAM group infrastructure * Initialize LAM group infrastructure
*/ */
int lam_group_init() int lam_group_init(void)
{ {
/* local variables */ /* local variables */
int return_value=LAM_SUCCESS; int return_value=LAM_SUCCESS;
/* initialize lam_group_f_to_c_table */ /* initialize lam_group_f_to_c_table */
lam_group_f_to_c_table=OBJ_NEW(lam_pointer_array_t); lam_group_f_to_c_table=OBJ_NEW(lam_pointer_array_t);
if( (-1) == lam_group_f_to_c_table ) if( NULL == lam_group_f_to_c_table )
return_value=LAM_ERROR; return_value=LAM_ERROR;
/* return */ /* return */
@ -99,7 +114,7 @@ int lam_group_init()
/** /**
* Clean up group infrastructure * Clean up group infrastructure
*/ */
int lam_group_finalize(){ int lam_group_finalize(void){
/* local variables */ /* local variables */
int return_value=LAM_SUCCESS; int return_value=LAM_SUCCESS;

Просмотреть файл

@ -6,12 +6,105 @@
#include "mpi.h" #include "mpi.h"
#include "mpi/interface/c/bindings.h" #include "mpi/interface/c/bindings.h"
#include "mpi/group/group.h"
#if LAM_HAVE_WEAK_SYMBOLS && LAM_PROFILING_DEFINES #if LAM_HAVE_WEAK_SYMBOLS && LAM_PROFILING_DEFINES
#pragma weak MPI_Group_excl = PMPI_Group_excl #pragma weak MPI_Group_excl = PMPI_Group_excl
#endif #endif
int MPI_Group_excl(MPI_Group group, int n, int *ranks, int MPI_Group_excl(MPI_Group group, int n, int *ranks,
MPI_Group *newgroup) { MPI_Group *new_group) {
/* local variables */
int return_value,proc,i_excl,found,excl_proc,cnt;
lam_group_t *group_pointer, *new_group_pointer;
return_value = MPI_SUCCESS;
group_pointer = (lam_group_t *)group;
if( MPI_PARAM_CHECK ) {
/* including anything of the empty group is still the empty group */
if ((group == MPI_GROUP_EMPTY) || (n == 0) ) {
*new_group = MPI_GROUP_EMPTY;
return return_value;
}
/* verify that group is valid group */
if ( NULL == group || NULL == ranks ) {
return MPI_ERR_GROUP;
}
/* check that new group is no larger than old group */
if ( n > group_pointer->grp_proc_count) {
return MPI_ERR_RANK;
}
} /* end if( MPI_CHECK_ARGS) */
// special case: nRanks == 0
// return the current group after incrementing the reference count
if ( n == 0) {
*new_group=group_pointer;
OBJ_RETAIN(group_pointer);
return MPI_SUCCESS;
} else if ( n == group_pointer->grp_proc_count) {
/* special case: nRanks == groupSize
* return the empty group -->
* all ranks must be distinct according to standard
*/
*new_group=MPI_GROUP_EMPTY;
return MPI_SUCCESS;
}
/*
* pull out elements
*/
/* get new group struct */
new_group_pointer=group_allocate(group_pointer->grp_proc_count-n);
if( NULL == new_group_pointer ) {
return MPI_ERR_GROUP;
}
/* put group elements in the list */
cnt=0;
for (proc = 0; proc < n; proc++) {
found=0;
for( i_excl=0 ; i_excl < n ; i_excl ) {
excl_proc=ranks[i_excl];
/* check to see if this proc is within range */
if( ( 0 > excl_proc ) ||
(excl_proc >= group_pointer->grp_proc_count)){
return MPI_ERR_RANK;
}
if(excl_proc == proc ){
found=1;
break;
}
} /* end i_excl loop */
if( !found ) {
new_group_pointer->grp_proc_pointers[cnt] = proc;
cnt++;
}
} /* end proc loop */
/* find my rank */
new_group_pointer->grp_my_rank = MPI_PROC_NULL;
if( MPI_PROC_NULL != group_pointer->grp_my_rank) {
for ( proc=0 ; proc < group_pointer->grp_proc_count-n ; proc++ ){
if( new_group_pointer->grp_proc_pointers[proc] ==
group_pointer->grp_proc_pointers
[group_pointer->grp_my_rank]){
new_group_pointer->grp_my_rank = proc;
}
}
}
*new_group = (MPI_Group)new_group_pointer;
return MPI_SUCCESS; return MPI_SUCCESS;
} }

Просмотреть файл

@ -15,7 +15,7 @@
int MPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group *new_group) int MPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group *new_group)
{ {
/* local variables */ /* local variables */
int return_value,proc,cnt; int return_value,proc;
lam_group_t *group_pointer, *new_group_pointer; lam_group_t *group_pointer, *new_group_pointer;
return_value = MPI_SUCCESS; return_value = MPI_SUCCESS;
@ -23,18 +23,18 @@ int MPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group *new_group)
if( MPI_PARAM_CHECK ) { if( MPI_PARAM_CHECK ) {
/* including anything of the empty group is still the empty group */ /* including anything of the empty group is still the empty group */
if ((group == MPI_GROUP_EMPTY) || (ranks == 0)) { if ((group == MPI_GROUP_EMPTY) || (n == 0)) {
*new_group = MPI_GROUP_EMPTY; *new_group = MPI_GROUP_EMPTY;
return return_value; return return_value;
} }
/* verify that group is valid group */ /* verify that group is valid group */
if ( NULL == group ) { if ( NULL == group || NULL == ranks ) {
return MPI_ERR_GROUP; return MPI_ERR_GROUP;
} }
/* check that new group is no larger than old group */ /* check that new group is no larger than old group */
if (ranks > group_pointer->grp_proc_count) { if ( n > group_pointer->grp_proc_count) {
return MPI_ERR_RANK; return MPI_ERR_RANK;
} }
@ -71,5 +71,7 @@ int MPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group *new_group)
} }
} }
*new_group = (MPI_Group)new_group_pointer;
return MPI_SUCCESS; return MPI_SUCCESS;
} }