2004-01-25 04:51:49 +03:00
|
|
|
/*
|
|
|
|
* $HEADERS$
|
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "ompi_config.h"
|
2004-01-25 04:51:49 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "mpi.h"
|
2004-03-17 21:45:16 +03:00
|
|
|
#include "mpi/c/bindings.h"
|
|
|
|
#include "group/group.h"
|
2004-03-23 00:42:12 +03:00
|
|
|
#include "errhandler/errhandler.h"
|
|
|
|
#include "communicator/communicator.h"
|
2004-01-25 04:51:49 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#if OMPI_HAVE_WEAK_SYMBOLS && OMPI_PROFILING_DEFINES
|
2004-01-25 04:51:49 +03:00
|
|
|
#pragma weak MPI_Group_union = PMPI_Group_union
|
|
|
|
#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_Group_union";
|
2004-06-23 00:21:35 +04:00
|
|
|
|
|
|
|
|
2004-02-27 22:22:14 +03:00
|
|
|
int MPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group *new_group)
|
|
|
|
{
|
|
|
|
/* local variables */
|
2004-03-23 00:42:12 +03:00
|
|
|
int new_group_size, proc1, proc2, found_in_group;
|
2004-02-27 22:22:14 +03:00
|
|
|
int my_group_rank, cnt;
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_group_t *group1_pointer, *group2_pointer, *new_group_pointer;
|
|
|
|
ompi_proc_t *proc1_pointer, *proc2_pointer, *my_proc_pointer;
|
2004-02-27 22:22:14 +03:00
|
|
|
|
2004-03-16 01:14:08 +03:00
|
|
|
/* check for errors */
|
2004-03-18 17:17:23 +03:00
|
|
|
if (MPI_PARAM_CHECK) {
|
2004-06-23 00:21:35 +04:00
|
|
|
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
|
2004-06-18 23:02:52 +04:00
|
|
|
|
2004-03-23 00:42:12 +03:00
|
|
|
if ((MPI_GROUP_NULL == group1) || (MPI_GROUP_NULL == group2) ||
|
|
|
|
(NULL == group1) || (NULL == group2) ) {
|
|
|
|
return
|
2004-06-07 19:33:53 +04:00
|
|
|
OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
|
2004-06-23 00:21:35 +04:00
|
|
|
FUNC_NAME);
|
2004-03-16 01:14:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
group1_pointer = (ompi_group_t *) group1;
|
|
|
|
group2_pointer = (ompi_group_t *) group2;
|
2004-02-27 22:22:14 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* form union
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* get new group size */
|
2004-03-18 17:17:23 +03:00
|
|
|
new_group_size = group1_pointer->grp_proc_count;
|
2004-02-27 22:22:14 +03:00
|
|
|
|
|
|
|
/* check group2 elements to see if they need to be included in the list */
|
|
|
|
for (proc2 = 0; proc2 < group2_pointer->grp_proc_count; proc2++) {
|
2004-03-18 17:17:23 +03:00
|
|
|
proc2_pointer = group2_pointer->grp_proc_pointers[proc2];
|
2004-02-27 22:22:14 +03:00
|
|
|
|
|
|
|
/* 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++) {
|
2004-03-18 17:17:23 +03:00
|
|
|
proc1_pointer = group1_pointer->grp_proc_pointers[proc1];
|
2004-06-15 04:06:33 +04:00
|
|
|
if (proc1_pointer == proc2_pointer) {
|
2004-02-27 22:22:14 +03:00
|
|
|
/* 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 */
|
|
|
|
|
|
|
|
/* get new group struct */
|
2004-06-07 19:33:53 +04:00
|
|
|
new_group_pointer = ompi_group_allocate(new_group_size);
|
2004-03-18 17:17:23 +03:00
|
|
|
if (NULL == new_group_pointer) {
|
2004-03-23 00:42:12 +03:00
|
|
|
return
|
2004-06-07 19:33:53 +04:00
|
|
|
OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
|
2004-06-23 00:21:35 +04:00
|
|
|
FUNC_NAME);
|
2004-02-27 22:22:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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];
|
|
|
|
}
|
2004-03-18 17:17:23 +03:00
|
|
|
cnt = group1_pointer->grp_proc_count;
|
2004-02-27 22:22:14 +03:00
|
|
|
|
|
|
|
/* check group2 elements to see if they need to be included in the list */
|
|
|
|
for (proc2 = 0; proc2 < group2_pointer->grp_proc_count; proc2++) {
|
2004-03-18 17:17:23 +03:00
|
|
|
proc2_pointer = group2_pointer->grp_proc_pointers[proc2];
|
2004-02-27 22:22:14 +03:00
|
|
|
|
|
|
|
/* 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++) {
|
2004-03-18 17:17:23 +03:00
|
|
|
proc1_pointer = group1_pointer->grp_proc_pointers[proc1];
|
2004-06-15 04:06:33 +04:00
|
|
|
if (proc1_pointer == proc2_pointer) {
|
2004-02-27 22:22:14 +03:00
|
|
|
/* 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 */
|
|
|
|
|
2004-03-16 01:14:08 +03:00
|
|
|
/* increment proc reference counters */
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_group_increment_proc_count(new_group_pointer);
|
2004-03-16 01:14:08 +03:00
|
|
|
|
2004-02-27 22:22:14 +03:00
|
|
|
/* find my rank */
|
2004-03-18 17:17:23 +03:00
|
|
|
my_group_rank = group1_pointer->grp_my_rank;
|
2004-06-15 04:06:33 +04:00
|
|
|
if (MPI_UNDEFINED == my_group_rank) {
|
2004-03-18 17:17:23 +03:00
|
|
|
my_group_rank = group2_pointer->grp_my_rank;
|
|
|
|
my_proc_pointer = group2_pointer->grp_proc_pointers[my_group_rank];
|
|
|
|
} else {
|
|
|
|
my_proc_pointer = group1_pointer->grp_proc_pointers[my_group_rank];
|
2004-02-27 22:22:14 +03:00
|
|
|
}
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_set_group_rank(new_group_pointer, my_proc_pointer);
|
2004-03-18 17:17:23 +03:00
|
|
|
|
|
|
|
*new_group = (MPI_Group) new_group_pointer;
|
2004-02-27 22:22:14 +03:00
|
|
|
|
|
|
|
/* return */
|
2004-03-23 00:42:12 +03:00
|
|
|
return MPI_SUCCESS;
|
2004-01-25 04:51:49 +03:00
|
|
|
}
|