1
1

move the implementation of the group creation functions into according back-end

functions. 

This commit was SVN r9281.
Этот коммит содержится в:
Mohamad Chaarawi 2006-03-14 21:01:46 +00:00
родитель 7ecc505f5c
Коммит c5a8870f6b
7 изменённых файлов: 146 добавлений и 694 удалений

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

@ -9,6 +9,7 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2006 University of Houston. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -37,111 +38,18 @@ static const char FUNC_NAME[] = "MPI_Group_difference";
int MPI_Group_difference(MPI_Group group1, MPI_Group group2,
MPI_Group *new_group) {
int err;
/* local varibles */
int new_group_size, proc1, proc2, found_in_group2, cnt;
int my_group_rank;
ompi_group_t *group1_pointer, *group2_pointer, *new_group_pointer;
ompi_proc_t *proc1_pointer, *proc2_pointer, *my_proc_pointer = NULL;
/* error checking */
if( MPI_PARAM_CHECK ) {
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
/* error checking */
if( MPI_PARAM_CHECK ) {
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
if( (MPI_GROUP_NULL == group1) || (MPI_GROUP_NULL == group2) ||
(NULL == group1) || (NULL == group2) ) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
FUNC_NAME);
}
}
group1_pointer=(ompi_group_t *)group1;
group2_pointer=(ompi_group_t *)group2;
/*
* form union
*/
/* get new group size */
new_group_size=0;
/* loop over group1 members */
for( proc1=0; proc1 < group1_pointer->grp_proc_count; proc1++ ) {
proc1_pointer=group1_pointer->grp_proc_pointers[proc1];
/* check to see if this proc is in group2 */
found_in_group2=0;
for( proc2=0 ; proc2 < group2_pointer->grp_proc_count ; proc2++ ) {
proc2_pointer=group2_pointer->grp_proc_pointers[proc2];
if( proc1_pointer == proc2_pointer ) {
found_in_group2=true;
break;
}
} /* end proc1 loop */
if(found_in_group2)
continue;
new_group_size++;
} /* end proc loop */
if ( 0 == new_group_size ) {
*new_group = MPI_GROUP_EMPTY;
OBJ_RETAIN(MPI_GROUP_EMPTY);
return MPI_SUCCESS;
}
/* allocate a new ompi_group_t structure */
new_group_pointer=ompi_group_allocate(new_group_size);
if( NULL == new_group_pointer ) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
"MPI_Group_difference - II");
}
/* fill in group list */
cnt=0;
/* loop over group1 members */
for( proc1=0; proc1 < group1_pointer->grp_proc_count; proc1++ ) {
proc1_pointer=group1_pointer->grp_proc_pointers[proc1];
/* check to see if this proc is in group2 */
found_in_group2=0;
for( proc2=0 ; proc2 < group2_pointer->grp_proc_count ; proc2++ ) {
proc2_pointer=group2_pointer->grp_proc_pointers[proc2];
if( proc1_pointer == proc2_pointer ) {
found_in_group2=true;
break;
}
} /* end proc1 loop */
if(found_in_group2)
continue;
new_group_pointer->grp_proc_pointers[cnt] =
group1_pointer->grp_proc_pointers[proc1];
cnt++;
} /* end proc loop */
/* increment proc reference counters */
ompi_group_increment_proc_count(new_group_pointer);
/* find my rank */
my_group_rank=group1_pointer->grp_my_rank;
if ( MPI_UNDEFINED != my_group_rank ) {
my_proc_pointer=group1_pointer->grp_proc_pointers[my_group_rank];
}
else {
my_group_rank=group2_pointer->grp_my_rank;
if ( MPI_UNDEFINED != my_group_rank ) {
my_proc_pointer=group2_pointer->grp_proc_pointers[my_group_rank];
}
}
if ( MPI_UNDEFINED == my_group_rank ) {
new_group_pointer->grp_my_rank = MPI_UNDEFINED;
}
else {
ompi_set_group_rank(new_group_pointer,my_proc_pointer);
}
*new_group = (MPI_Group)new_group_pointer;
return MPI_SUCCESS;
if( (MPI_GROUP_NULL == group1) || (MPI_GROUP_NULL == group2) ||
(NULL == group1) || (NULL == group2) ) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
FUNC_NAME);
}
}
err = ompi_group_difference ( group1, group2, new_group );
OMPI_ERRHANDLER_RETURN(err, MPI_COMM_WORLD, err, FUNC_NAME );
}

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

@ -9,6 +9,7 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2006 University of Houston. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -36,16 +37,14 @@ static const char FUNC_NAME[] = "MPI_Group_excl";
int MPI_Group_excl(MPI_Group group, int n, int *ranks,
MPI_Group *new_group) {
MPI_Group *new_group)
{
/* local variables */
int return_value,proc,i_excl,found,excl_proc,cnt,my_group_rank;
ompi_group_t *group_pointer, *new_group_pointer;
ompi_proc_t *my_proc_pointer;
return_value = MPI_SUCCESS;
ompi_group_t *group_pointer;
group_pointer = (ompi_group_t *)group;
int i, err, group_size;
group_size = ompi_group_size ( group_pointer);
if( MPI_PARAM_CHECK ) {
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
@ -57,66 +56,29 @@ int MPI_Group_excl(MPI_Group group, int n, int *ranks,
}
/* check that new group is no larger than old group */
if ( n > group_pointer->grp_proc_count) {
if ( n > group_size) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
FUNC_NAME);
}
} /* end if( MPI_CHECK_ARGS) */
/* check to see if procs are within range */
for( i=0 ; i < n ; i++ ) {
if( ( 0 > ranks[i] ) || (ranks[i] >= group_size)){
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME );
}
}
if ( n == group_pointer->grp_proc_count ) {
} /* end if( MPI_CHECK_ARGS) */
if ( n == group_size ) {
*new_group = MPI_GROUP_EMPTY;
OBJ_RETAIN(MPI_GROUP_EMPTY);
return MPI_SUCCESS;
}
/*
* pull out elements
*/
err = ompi_group_excl ( group, n, ranks, new_group );
OMPI_ERRHANDLER_RETURN(err, MPI_COMM_WORLD, err, FUNC_NAME );
/* get new group struct */
new_group_pointer=ompi_group_allocate(group_pointer->grp_proc_count-n);
if( NULL == new_group_pointer ) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
FUNC_NAME);
}
/* put group elements in the list */
cnt=0;
for (proc = 0; proc < group_pointer->grp_proc_count; proc++) {
found=0;
/* check to see if this proc is in the exclusion list */
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 OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
if(excl_proc == proc ){
found=1;
break;
}
} /* end i_excl loop */
if( !found ) {
new_group_pointer->grp_proc_pointers[cnt] =
group_pointer->grp_proc_pointers[proc];
cnt++;
}
} /* end proc loop */
/* increment proc reference counters */
ompi_group_increment_proc_count(new_group_pointer);
/* find my rank */
my_group_rank=group_pointer->grp_my_rank;
my_proc_pointer=group_pointer->grp_proc_pointers[my_group_rank];
ompi_set_group_rank(new_group_pointer,my_proc_pointer);
*new_group = (MPI_Group)new_group_pointer;
return MPI_SUCCESS;
}

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

@ -9,6 +9,7 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2006 University of Houston. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -37,67 +38,42 @@ static const char FUNC_NAME[] = "MPI_Group_incl";
int MPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group *new_group)
{
/* local variables */
int proc,my_group_rank;
ompi_group_t *group_pointer, *new_group_pointer;
ompi_proc_t *my_proc_pointer;
int i, group_size, err;
ompi_group_t *group_pointer;
group_pointer = (ompi_group_t *)group;
group_pointer = (ompi_group_t *)group;
group_size = ompi_group_size ( group_pointer );
if( MPI_PARAM_CHECK ) {
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
if( MPI_PARAM_CHECK ) {
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
/* verify that group is valid group */
if ( (MPI_GROUP_NULL == group) || ( NULL == group)
|| NULL == ranks ) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
/* verify that group is valid group */
if ( (MPI_GROUP_NULL == group) || ( NULL == group)
|| NULL == ranks ) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
FUNC_NAME);
}
/* check that new group is no larger than old group */
if ( n > group_pointer->grp_proc_count) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
} /* end if( MPI_CHECK_ARGS) */
if ( 0 == n ) {
*new_group = MPI_GROUP_EMPTY;
OBJ_RETAIN(MPI_GROUP_EMPTY);
return MPI_SUCCESS;
}
/* get new group struct */
new_group_pointer=ompi_group_allocate(n);
if( NULL == new_group_pointer ) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
/* check that new group is no larger than old group */
if ( n > group_size ) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
/* put group elements in the list */
for (proc = 0; proc < n; proc++) {
if ((ranks[proc] < 0) ||
(ranks[proc] >= group_pointer->grp_proc_count)){
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
for (i = 0; i < n; i++) {
if ((ranks[i] < 0) || (ranks[i] >= group_size)){
return OMPI_ERRHANDLER_INVOKE (MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
}
} /* end if( MPI_CHECK_ARGS) */
new_group_pointer->grp_proc_pointers[proc] =
group_pointer->grp_proc_pointers[ranks[proc]];
if ( 0 == n ) {
*new_group = MPI_GROUP_EMPTY;
OBJ_RETAIN(MPI_GROUP_EMPTY);
return MPI_SUCCESS;
}
} /* end proc loop */
/* increment proc reference counters */
ompi_group_increment_proc_count(new_group_pointer);
/* find my rank */
my_group_rank=group_pointer->grp_my_rank;
my_proc_pointer=group_pointer->grp_proc_pointers[my_group_rank];
ompi_set_group_rank(new_group_pointer,my_proc_pointer);
*new_group = (MPI_Group)new_group_pointer;
return MPI_SUCCESS;
err = ompi_group_incl(group,n,ranks,new_group);
OMPI_ERRHANDLER_RETURN(err, MPI_COMM_WORLD,err,FUNC_NAME);
}

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

@ -9,6 +9,7 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2006 University of Houston. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -38,99 +39,19 @@ static const char FUNC_NAME[] = "MPI_Group_intersection";
int MPI_Group_intersection(MPI_Group group1, MPI_Group group2,
MPI_Group *new_group)
{
/* local variables */
int my_group_rank;
int group_size,proc1,proc2,cnt;
ompi_group_t *group1_pointer, *group2_pointer, *new_group_pointer;
ompi_proc_t *proc1_pointer, *proc2_pointer, *my_proc_pointer = NULL;
int err;
if ( MPI_PARAM_CHECK ) {
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
if ( MPI_PARAM_CHECK ) {
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
/* verify that groups are valid */
if ( (MPI_GROUP_NULL == group1) || (MPI_GROUP_NULL == group2) ||
( NULL == group1) || (NULL == group2) ) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
FUNC_NAME);
}
}
/* verify that groups are valid */
if ( (MPI_GROUP_NULL == group1) || (MPI_GROUP_NULL == group2) ||
( NULL == group1) || (NULL == group2) ) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
FUNC_NAME);
}
}
group1_pointer=(ompi_group_t *)group1;
group2_pointer=(ompi_group_t *)group2;
/*
* form intersection
*/
/* figure out how large the intersection is */
group_size = 0;
/* loop over group1 members */
for (proc1 = 0; proc1 < group1_pointer->grp_proc_count; proc1++) {
proc1_pointer=group1_pointer->grp_proc_pointers[proc1];
/* check to see if this proc is in group2 */
for (proc2 = 0; proc2 < group2_pointer->grp_proc_count; proc2++) {
proc2_pointer=group2_pointer->grp_proc_pointers[proc2];
if( proc1_pointer == proc2_pointer ) {
group_size++;
break;
}
} /* end proc2 loop */
} /* end proc1 loop */
if ( 0 == group_size ) {
*new_group = MPI_GROUP_EMPTY;
OBJ_RETAIN(MPI_GROUP_EMPTY);
return MPI_SUCCESS;
}
/* fill in new group */
new_group_pointer=ompi_group_allocate(group_size);
if( NULL == new_group_pointer ) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
FUNC_NAME);
}
cnt = 0;
/* loop over group1 members */
for (proc1 = 0; proc1 < group1_pointer->grp_proc_count; proc1++) {
proc1_pointer=group1_pointer->grp_proc_pointers[proc1];
/* check to see if this proc is in group2 */
for (proc2 = 0; proc2 < group2_pointer->grp_proc_count; proc2++) {
proc2_pointer=group2_pointer->grp_proc_pointers[proc2];
if( proc1_pointer == proc2_pointer ) {
new_group_pointer->grp_proc_pointers[cnt]=proc1_pointer;
cnt++;
break;
}
} /* end proc2 loop */
} /* end proc1 loop */
/* increment proc reference counters */
ompi_group_increment_proc_count(new_group_pointer);
/* find my rank */
my_group_rank=group1_pointer->grp_my_rank;
if ( MPI_UNDEFINED != my_group_rank ) {
my_proc_pointer=group1_pointer->grp_proc_pointers[my_group_rank];
}
else {
my_group_rank=group2_pointer->grp_my_rank;
if ( MPI_UNDEFINED != my_group_rank ) {
my_proc_pointer=group2_pointer->grp_proc_pointers[my_group_rank];
}
}
if ( MPI_UNDEFINED == my_group_rank ) {
new_group_pointer->grp_my_rank = MPI_UNDEFINED;
}
else {
ompi_set_group_rank(new_group_pointer,my_proc_pointer);
}
*new_group = (MPI_Group)new_group_pointer;
return MPI_SUCCESS;
err = ompi_group_intersection ( group1, group2, new_group );
OMPI_ERRHANDLER_RETURN(err, MPI_COMM_WORLD, err, FUNC_NAME );
}

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

@ -9,6 +9,7 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2006 University of Houston. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -38,150 +39,43 @@ static const char FUNC_NAME[] = "MPI_Group_range_excl";
int MPI_Group_range_excl(MPI_Group group, int n_triplets, int ranges[][3],
MPI_Group *new_group)
{
/* local variables */
int new_group_size, proc, first_rank, last_rank;
int stride, triplet, index, *elements_int_list, my_group_rank;
ompi_group_t *group_pointer, *new_group_pointer;
ompi_proc_t *my_proc_pointer;
int err, i, group_size;
group_pointer=(ompi_group_t *)group;
group_size = ompi_group_size ( group );
/* can't act on NULL group */
if( MPI_PARAM_CHECK ) {
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
if ( (MPI_GROUP_NULL == group) || (NULL == group) ) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
FUNC_NAME);
}
if ( (MPI_GROUP_NULL == group) || (NULL == group) ) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
FUNC_NAME);
}
for (i = 0; i < n_triplets; i++) {
if ((0 > ranges[i][0]) || (ranges[i][0] > group_size )) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
if ((0 > ranges[i][1]) || (ranges[i][1] > group_size )) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
if (ranges[i][2] == 0) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
if ( (ranges[i][0] < ranges[i][1]) && ( ranges[i][2] < 0)) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
if ( (ranges[i][0] > ranges[i][1]) && (ranges[i][2] > 0)) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
}
}
/*
* pull out elements
*/
elements_int_list = (int *)
malloc(sizeof(int) * group_pointer->grp_proc_count);
if (NULL == elements_int_list) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_OTHER,
FUNC_NAME);
}
for (proc = 0; proc < group_pointer->grp_proc_count; proc++) {
elements_int_list[proc] = -1;
}
/* loop over triplet */
new_group_size = 0;
for (triplet = 0; triplet < n_triplets; triplet++) {
first_rank = ranges[triplet][0];
last_rank = ranges[triplet][1];
stride = ranges[triplet][2];
/* check for error conditions */
if ((0 > first_rank) || (first_rank > group_pointer->grp_proc_count)) {
free(elements_int_list);
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
if ((0 > last_rank) || (last_rank > group_pointer->grp_proc_count)) {
free(elements_int_list);
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
if (stride == 0) {
free(elements_int_list);
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
if (first_rank < last_rank) {
if (stride < 0) {
free(elements_int_list);
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
/* positive stride */
for (index = first_rank; index <= last_rank; index += stride) {
/* make sure rank has not already been selected */
if (elements_int_list[index] != -1) {
free(elements_int_list);
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
elements_int_list[index] = new_group_size;
new_group_size++;
}
} else if (first_rank > last_rank) {
if (stride > 0) {
free(elements_int_list);
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
/* negative stride */
for (index = first_rank; index >= last_rank; index += stride) {
/* make sure rank has not already been selected */
if (elements_int_list[index] != -1) {
free(elements_int_list);
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
elements_int_list[index] = new_group_size;
new_group_size++;
}
} else {
/* first_rank == last_rank */
index = first_rank;
if (elements_int_list[index] != -1) {
free(elements_int_list);
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
elements_int_list[index] = new_group_size;
new_group_size++;
}
} /* end triplet loop */
/* we have counted the procs to exclude from the list */
new_group_size=group_pointer->grp_proc_count-new_group_size;
if ( 0 == new_group_size ) {
*new_group = MPI_GROUP_EMPTY;
OBJ_RETAIN(MPI_GROUP_EMPTY);
return MPI_SUCCESS;
}
/* allocate a new ompi_group_t structure */
new_group_pointer=ompi_group_allocate(new_group_size);
if( NULL == new_group_pointer ) {
free(elements_int_list);
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
FUNC_NAME);
}
/* fill in group list */
index=0;
for (proc = 0; proc < group_pointer->grp_proc_count; proc++) {
/* if value == -1, include in the list */
if (0 > elements_int_list[proc] ) {
new_group_pointer->grp_proc_pointers[index] =
group_pointer->grp_proc_pointers[proc];
index++;
}
} /* end of proc loop */
/* increment proc reference counters */
ompi_group_increment_proc_count(new_group_pointer);
free(elements_int_list);
/* find my rank */
my_group_rank=group_pointer->grp_my_rank;
my_proc_pointer=group_pointer->grp_proc_pointers[my_group_rank];
ompi_set_group_rank(new_group_pointer,my_proc_pointer);
*new_group = (MPI_Group)new_group_pointer;
return MPI_SUCCESS;
err = ompi_group_range_excl(group,n_triplets,ranges,new_group);
OMPI_ERRHANDLER_RETURN(err, MPI_COMM_WORLD,err,FUNC_NAME);
}

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

@ -9,6 +9,7 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2006 University of Houston. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -38,150 +39,43 @@ static const char FUNC_NAME[] = "MPI_Group_range_incl";
int MPI_Group_range_incl(MPI_Group group, int n_triplets, int ranges[][3],
MPI_Group *new_group)
{
/* local variables */
int new_group_size, proc, first_rank, last_rank;
int stride, triplet, index, *elements_int_list, my_group_rank;
ompi_group_t *group_pointer, *new_group_pointer;
ompi_proc_t *my_proc_pointer;
group_pointer=(ompi_group_t *)group;
int err, i;
int group_size;
group_size = ompi_group_size ( group);
/* can't act on NULL group */
if( MPI_PARAM_CHECK ) {
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
if ( (MPI_GROUP_NULL == group) || (NULL == group) ) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
FUNC_NAME);
}
if ( (MPI_GROUP_NULL == group) || (NULL == group) ) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
FUNC_NAME);
}
for ( i=0; i < n_triplets; i++) {
if(( 0 > ranges[i][0] ) || (ranges[i][0] > group_size )) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
if((0 > ranges[i][1]) || (ranges[i][1] > group_size)) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
if (ranges[i][2] == 0) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
if ( (ranges[i][0] < ranges[i][1]) && (ranges[i][2] < 0)) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
if ( (ranges[i][0] > ranges[i][1]) && (ranges[i][2] > 0) ){
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
}
}
/*
* pull out elements
*/
elements_int_list =
(int *) malloc(sizeof(int) * group_pointer->grp_proc_count);
if (NULL == elements_int_list) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_OTHER,
FUNC_NAME);
}
for (proc = 0; proc < group_pointer->grp_proc_count; proc++) {
elements_int_list[proc] = -1;
}
/* loop over triplet */
new_group_size = 0;
for (triplet = 0; triplet < n_triplets; triplet++)
{
first_rank = ranges[triplet][0];
last_rank = ranges[triplet][1];
stride = ranges[triplet][2];
if(( 0 > first_rank ) || (first_rank > group_pointer->grp_proc_count)) {
free(elements_int_list);
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
FUNC_NAME);
}
if((0 > last_rank) || (last_rank > group_pointer->grp_proc_count)) {
free(elements_int_list);
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
"MPI_Group_range_incl - IV");
}
if (stride == 0) {
free(elements_int_list);
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
"MPI_Group_range_incl - V");
}
if (first_rank < last_rank) {
if (stride < 0) {
free(elements_int_list);
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
"MPI_Group_range_incl - VI");
}
/* positive stride */
index = first_rank;
while (index <= last_rank) {
/* make sure rank has not already been selected */
if (elements_int_list[index] != -1) {
free(elements_int_list);
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
"MPI_Group_range_incl - VII");
}
elements_int_list[index] = new_group_size;
index += stride;
new_group_size++;
} /* end while loop */
} else if (first_rank > last_rank) {
if (stride > 0){
free(elements_int_list);
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
"MPI_Group_range_incl - VIII");
}
/* negative stride */
index = first_rank;
while (index >= last_rank) {
/* make sure rank has not already been selected */
if (elements_int_list[index] != -1) {
free(elements_int_list);
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
"MPI_Group_range_incl - IX");
}
elements_int_list[index] = new_group_size;
index += stride;
new_group_size++;
} /* end while loop */
} else { /* first_rank == last_rank */
index = first_rank;
if (elements_int_list[index] != -1) {
free(elements_int_list);
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
"MPI_Group_range_incl - X");
}
elements_int_list[index] = new_group_size;
new_group_size++;
}
}
if ( 0 == new_group_size ) {
*new_group = MPI_GROUP_EMPTY;
OBJ_RETAIN(MPI_GROUP_EMPTY);
return MPI_SUCCESS;
}
/* allocate a new ompi_group_t structure */
new_group_pointer=ompi_group_allocate(new_group_size);
if( NULL == new_group_pointer ) {
free(elements_int_list);
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
"MPI_Group_range_incl - X");
}
/* fill in group list */
for (proc = 0; proc < group_pointer->grp_proc_count; proc++) {
/* if value >= 0, include in the list */
if (0 <= elements_int_list[proc] ) {
new_group_pointer->grp_proc_pointers[elements_int_list[proc]] =
group_pointer->grp_proc_pointers[proc];
}
} /* end of proc loop */
/* increment proc reference counters */
ompi_group_increment_proc_count(new_group_pointer);
free(elements_int_list);
/* find my rank */
my_group_rank=group_pointer->grp_my_rank;
my_proc_pointer=group_pointer->grp_proc_pointers[my_group_rank];
ompi_set_group_rank(new_group_pointer,my_proc_pointer);
*new_group = (MPI_Group)new_group_pointer;
return MPI_SUCCESS;
err = ompi_group_range_incl ( group, n_triplets, ranges, new_group );
OMPI_ERRHANDLER_RETURN(err, MPI_COMM_WORLD, err, FUNC_NAME );
}

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

@ -9,6 +9,7 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2006 University of Houston. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -37,11 +38,7 @@ static const char FUNC_NAME[] = "MPI_Group_union";
int MPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group *new_group)
{
/* local variables */
int new_group_size, proc1, proc2, found_in_group;
int my_group_rank, cnt;
ompi_group_t *group1_pointer, *group2_pointer, *new_group_pointer;
ompi_proc_t *proc1_pointer, *proc2_pointer, *my_proc_pointer = NULL;
int err;
/* check for errors */
if (MPI_PARAM_CHECK) {
@ -55,106 +52,6 @@ int MPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group *new_group)
}
}
group1_pointer = (ompi_group_t *) group1;
group2_pointer = (ompi_group_t *) group2;
/*
* form union
*/
/* get new group size */
new_group_size = group1_pointer->grp_proc_count;
/* check group2 elements to see if they need to be included in the list */
for (proc2 = 0; proc2 < group2_pointer->grp_proc_count; proc2++) {
proc2_pointer = group2_pointer->grp_proc_pointers[proc2];
/* check to see if this proc2 is alread in the group */
found_in_group = 0;
for (proc1 = 0; proc1 < group1_pointer->grp_proc_count; proc1++) {
proc1_pointer = group1_pointer->grp_proc_pointers[proc1];
if (proc1_pointer == proc2_pointer) {
/* proc2 is in group1 - don't double count */
found_in_group = 1;
break;
}
} /* end proc1 loop */
if (found_in_group)
continue;
new_group_size++;
} /* end proc loop */
if ( 0 == new_group_size ) {
*new_group = MPI_GROUP_EMPTY;
OBJ_RETAIN(MPI_GROUP_EMPTY);
return MPI_SUCCESS;
}
/* get new group struct */
new_group_pointer = ompi_group_allocate(new_group_size);
if (NULL == new_group_pointer) {
return
OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
FUNC_NAME);
}
/* fill in the new group list */
/* put group1 elements in the list */
for (proc1 = 0; proc1 < group1_pointer->grp_proc_count; proc1++) {
new_group_pointer->grp_proc_pointers[proc1] =
group1_pointer->grp_proc_pointers[proc1];
}
cnt = group1_pointer->grp_proc_count;
/* check group2 elements to see if they need to be included in the list */
for (proc2 = 0; proc2 < group2_pointer->grp_proc_count; proc2++) {
proc2_pointer = group2_pointer->grp_proc_pointers[proc2];
/* check to see if this proc2 is alread in the group */
found_in_group = 0;
for (proc1 = 0; proc1 < group1_pointer->grp_proc_count; proc1++) {
proc1_pointer = group1_pointer->grp_proc_pointers[proc1];
if (proc1_pointer == proc2_pointer) {
/* proc2 is in group1 - don't double count */
found_in_group = 1;
break;
}
} /* end proc1 loop */
if (found_in_group)
continue;
new_group_pointer->grp_proc_pointers[cnt] =
group2_pointer->grp_proc_pointers[proc2];
cnt++;
} /* end proc loop */
/* increment proc reference counters */
ompi_group_increment_proc_count(new_group_pointer);
/* find my rank */
my_group_rank = group1_pointer->grp_my_rank;
if (MPI_UNDEFINED == my_group_rank) {
my_group_rank = group2_pointer->grp_my_rank;
if ( MPI_UNDEFINED != my_group_rank) {
my_proc_pointer = group2_pointer->grp_proc_pointers[my_group_rank];
}
} else {
my_proc_pointer = group1_pointer->grp_proc_pointers[my_group_rank];
}
if ( MPI_UNDEFINED == my_group_rank ) {
new_group_pointer->grp_my_rank = MPI_UNDEFINED;
}
else {
ompi_set_group_rank(new_group_pointer, my_proc_pointer);
}
*new_group = (MPI_Group) new_group_pointer;
/* return */
return MPI_SUCCESS;
err = ompi_group_union ( group1, group2, new_group );
OMPI_ERRHANDLER_RETURN(err, MPI_COMM_WORLD, err, FUNC_NAME );
}