2013-09-27 01:56:20 +04:00
|
|
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
|
2015-06-24 06:59:57 +03:00
|
|
|
/*
|
2007-08-04 04:41:26 +04:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2015-06-24 06:59:57 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
2007-08-04 04:41:26 +04:00
|
|
|
* University of Stuttgart. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2006-2007 University of Houston. All rights reserved.
|
2009-01-11 05:30:00 +03:00
|
|
|
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
|
2015-06-23 17:45:22 +03:00
|
|
|
* Copyright (c) 2013-2015 Los Alamos National Security, LLC. All rights
|
2013-09-27 01:56:20 +04:00
|
|
|
* reserved.
|
2007-08-04 04:41:26 +04:00
|
|
|
* $COPYRIGHT$
|
2013-09-27 01:56:20 +04:00
|
|
|
*
|
2007-08-04 04:41:26 +04:00
|
|
|
* Additional copyrights may follow
|
2013-09-27 01:56:20 +04:00
|
|
|
*
|
2007-08-04 04:41:26 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ompi_config.h"
|
|
|
|
#include "ompi/group/group.h"
|
|
|
|
#include "ompi/constants.h"
|
|
|
|
#include "ompi/proc/proc.h"
|
|
|
|
#include "mpi.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
2015-06-23 17:45:22 +03:00
|
|
|
static struct ompi_proc_t *ompi_group_dense_lookup_raw (ompi_group_t *group, const int peer_id)
|
|
|
|
{
|
|
|
|
if (OPAL_UNLIKELY((intptr_t) group->grp_proc_pointers[peer_id] < 0)) {
|
|
|
|
ompi_proc_t *proc =
|
|
|
|
(ompi_proc_t *) ompi_proc_lookup (ompi_proc_sentinel_to_name ((intptr_t) group->grp_proc_pointers[peer_id]));
|
|
|
|
if (NULL != proc) {
|
|
|
|
/* replace sentinel value with an actual ompi_proc_t */
|
|
|
|
group->grp_proc_pointers[peer_id] = proc;
|
|
|
|
/* retain the proc */
|
|
|
|
OBJ_RETAIN(group->grp_proc_pointers[peer_id]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return group->grp_proc_pointers[peer_id];
|
|
|
|
}
|
|
|
|
|
|
|
|
ompi_proc_t *ompi_group_get_proc_ptr_raw (ompi_group_t *group, int rank)
|
|
|
|
{
|
|
|
|
#if OMPI_GROUP_SPARSE
|
|
|
|
do {
|
|
|
|
if (OMPI_GROUP_IS_DENSE(group)) {
|
|
|
|
return ompi_group_dense_lookup_raw (group, peer_id);
|
|
|
|
}
|
|
|
|
int ranks1 = rank;
|
|
|
|
ompi_group_translate_ranks (group, 1, &ranks1, group->grp_parent_group_ptr, &rank);
|
|
|
|
group = group->grp_parent_group_ptr;
|
|
|
|
} while (1);
|
|
|
|
#else
|
|
|
|
return ompi_group_dense_lookup_raw (group, rank);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-09-27 01:56:20 +04:00
|
|
|
int ompi_group_calc_plist ( int n , const int *ranks ) {
|
2007-08-04 04:41:26 +04:00
|
|
|
return sizeof(char *) * n ;
|
|
|
|
}
|
|
|
|
|
2013-09-27 01:56:20 +04:00
|
|
|
int ompi_group_incl_plist(ompi_group_t* group, int n, const int *ranks,
|
|
|
|
ompi_group_t **new_group)
|
2007-08-04 04:41:26 +04:00
|
|
|
{
|
|
|
|
/* local variables */
|
2015-06-23 17:45:22 +03:00
|
|
|
int my_group_rank;
|
2007-08-04 04:41:26 +04:00
|
|
|
ompi_group_t *group_pointer, *new_group_pointer;
|
|
|
|
ompi_proc_t *my_proc_pointer;
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2007-08-04 04:41:26 +04:00
|
|
|
group_pointer = (ompi_group_t *)group;
|
|
|
|
|
|
|
|
if ( 0 == n ) {
|
2010-10-04 18:54:58 +04:00
|
|
|
*new_group = MPI_GROUP_EMPTY;
|
|
|
|
OBJ_RETAIN(MPI_GROUP_EMPTY);
|
|
|
|
return OMPI_SUCCESS;
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get new group struct */
|
|
|
|
new_group_pointer=ompi_group_allocate(n);
|
|
|
|
if( NULL == new_group_pointer ) {
|
2010-10-04 18:54:58 +04:00
|
|
|
return MPI_ERR_GROUP;
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* put group elements in the list */
|
2015-06-23 17:45:22 +03:00
|
|
|
for (int proc = 0; proc < n; proc++) {
|
2015-06-24 06:59:57 +03:00
|
|
|
new_group_pointer->grp_proc_pointers[proc] =
|
2015-06-23 17:45:22 +03:00
|
|
|
ompi_group_get_proc_ptr_raw (group_pointer, ranks[proc]);
|
2007-08-04 04:41:26 +04:00
|
|
|
} /* 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;
|
2007-08-16 21:01:01 +04:00
|
|
|
if (MPI_UNDEFINED != my_group_rank) {
|
|
|
|
my_proc_pointer=ompi_group_peer_lookup (group_pointer,my_group_rank);
|
|
|
|
ompi_set_group_rank(new_group_pointer,my_proc_pointer);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
new_group_pointer->grp_my_rank = MPI_UNDEFINED;
|
|
|
|
}
|
2007-08-04 04:41:26 +04:00
|
|
|
|
|
|
|
*new_group = (MPI_Group)new_group_pointer;
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-06-24 06:59:57 +03:00
|
|
|
/*
|
|
|
|
* Group Union has to use the dense format since we don't support
|
2007-08-04 04:41:26 +04:00
|
|
|
* two parent groups in the group structure and maintain functions
|
|
|
|
*/
|
2015-06-24 06:59:57 +03:00
|
|
|
int ompi_group_union (ompi_group_t* group1, ompi_group_t* group2,
|
|
|
|
ompi_group_t **new_group)
|
2007-08-04 04:41:26 +04:00
|
|
|
{
|
|
|
|
/* local variables */
|
2015-06-23 17:45:22 +03:00
|
|
|
int new_group_size, my_group_rank, cnt;
|
|
|
|
ompi_group_t *new_group_pointer;
|
2007-08-04 04:41:26 +04:00
|
|
|
ompi_proc_t *proc1_pointer, *proc2_pointer, *my_proc_pointer = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* form union
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* get new group size */
|
2015-06-23 17:45:22 +03:00
|
|
|
new_group_size = group1->grp_proc_count;
|
2007-08-04 04:41:26 +04:00
|
|
|
|
|
|
|
/* check group2 elements to see if they need to be included in the list */
|
2015-06-23 17:45:22 +03:00
|
|
|
for (int proc2 = 0; proc2 < group2->grp_proc_count; ++proc2) {
|
|
|
|
bool found_in_group = false;
|
|
|
|
|
|
|
|
proc2_pointer = ompi_group_get_proc_ptr_raw (group2, proc2);
|
2007-08-04 04:41:26 +04:00
|
|
|
|
|
|
|
/* check to see if this proc2 is alread in the group */
|
2015-06-23 17:45:22 +03:00
|
|
|
for (int proc1 = 0; proc1 < group1->grp_proc_count; ++proc1) {
|
|
|
|
proc1_pointer = ompi_group_get_proc_ptr_raw (group1, proc1);
|
2007-08-04 04:41:26 +04:00
|
|
|
|
|
|
|
if (proc1_pointer == proc2_pointer) {
|
|
|
|
/* proc2 is in group1 - don't double count */
|
2015-06-23 17:45:22 +03:00
|
|
|
found_in_group = true;
|
2007-08-04 04:41:26 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} /* end proc1 loop */
|
|
|
|
|
2010-10-04 18:54:58 +04:00
|
|
|
if (found_in_group) {
|
2007-08-04 04:41:26 +04:00
|
|
|
continue;
|
2010-10-04 18:54:58 +04:00
|
|
|
}
|
2007-08-04 04:41:26 +04:00
|
|
|
|
|
|
|
new_group_size++;
|
|
|
|
} /* end proc loop */
|
|
|
|
|
|
|
|
if ( 0 == new_group_size ) {
|
2010-10-04 18:54:58 +04:00
|
|
|
*new_group = MPI_GROUP_EMPTY;
|
|
|
|
OBJ_RETAIN(MPI_GROUP_EMPTY);
|
|
|
|
return MPI_SUCCESS;
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get new group struct */
|
|
|
|
new_group_pointer = ompi_group_allocate(new_group_size);
|
|
|
|
if (NULL == new_group_pointer) {
|
|
|
|
return MPI_ERR_GROUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill in the new group list */
|
|
|
|
|
|
|
|
/* put group1 elements in the list */
|
2015-06-23 17:45:22 +03:00
|
|
|
for (int proc1 = 0; proc1 < group1->grp_proc_count; ++proc1) {
|
2015-06-24 06:59:57 +03:00
|
|
|
new_group_pointer->grp_proc_pointers[proc1] =
|
2015-06-23 17:45:22 +03:00
|
|
|
ompi_group_get_proc_ptr_raw (group1, proc1);
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
2015-06-23 17:45:22 +03:00
|
|
|
cnt = group1->grp_proc_count;
|
2007-08-04 04:41:26 +04:00
|
|
|
|
|
|
|
/* check group2 elements to see if they need to be included in the list */
|
2015-06-23 17:45:22 +03:00
|
|
|
for (int proc2 = 0; proc2 < group2->grp_proc_count; ++proc2) {
|
|
|
|
bool found_in_group = false;
|
|
|
|
|
|
|
|
proc2_pointer = ompi_group_get_proc_ptr_raw (group2, proc2);
|
2007-08-04 04:41:26 +04:00
|
|
|
|
|
|
|
/* check to see if this proc2 is alread in the group */
|
2015-06-23 17:45:22 +03:00
|
|
|
for (int proc1 = 0; proc1 < group1->grp_proc_count; ++proc1) {
|
|
|
|
proc1_pointer = ompi_group_get_proc_ptr_raw (group1, proc1);
|
2007-08-04 04:41:26 +04:00
|
|
|
|
|
|
|
if (proc1_pointer == proc2_pointer) {
|
|
|
|
/* proc2 is in group1 - don't double count */
|
2015-06-23 17:45:22 +03:00
|
|
|
found_in_group = true;
|
2007-08-04 04:41:26 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} /* end proc1 loop */
|
|
|
|
|
2010-10-04 18:54:58 +04:00
|
|
|
if (found_in_group) {
|
2007-08-04 04:41:26 +04:00
|
|
|
continue;
|
2010-10-04 18:54:58 +04:00
|
|
|
}
|
2007-08-04 04:41:26 +04:00
|
|
|
|
2015-06-23 17:45:22 +03:00
|
|
|
new_group_pointer->grp_proc_pointers[cnt++] = proc2_pointer;
|
2007-08-04 04:41:26 +04:00
|
|
|
} /* end proc loop */
|
|
|
|
|
|
|
|
/* increment proc reference counters */
|
|
|
|
ompi_group_increment_proc_count(new_group_pointer);
|
|
|
|
|
|
|
|
/* find my rank */
|
2015-06-23 17:45:22 +03:00
|
|
|
my_group_rank = group1->grp_my_rank;
|
2007-08-04 04:41:26 +04:00
|
|
|
if (MPI_UNDEFINED == my_group_rank) {
|
2015-06-23 17:45:22 +03:00
|
|
|
my_group_rank = group2->grp_my_rank;
|
2010-10-04 18:54:58 +04:00
|
|
|
if ( MPI_UNDEFINED != my_group_rank) {
|
2015-06-23 17:45:22 +03:00
|
|
|
my_proc_pointer = ompi_group_peer_lookup(group2,my_group_rank);
|
2010-10-04 18:54:58 +04:00
|
|
|
}
|
2007-08-04 04:41:26 +04:00
|
|
|
} else {
|
2015-06-23 17:45:22 +03:00
|
|
|
my_proc_pointer = ompi_group_peer_lookup(group1,my_group_rank);
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( MPI_UNDEFINED == my_group_rank ) {
|
2010-10-04 18:54:58 +04:00
|
|
|
new_group_pointer->grp_my_rank = MPI_UNDEFINED;
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
|
|
|
else {
|
2010-10-04 18:54:58 +04:00
|
|
|
ompi_set_group_rank(new_group_pointer, my_proc_pointer);
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
*new_group = (MPI_Group) new_group_pointer;
|
|
|
|
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-06-24 06:59:57 +03:00
|
|
|
/*
|
|
|
|
* Group Difference has to use the dense format since we don't support
|
2007-08-04 04:41:26 +04:00
|
|
|
* two parent groups in the group structure and maintain functions
|
|
|
|
*/
|
|
|
|
int ompi_group_difference(ompi_group_t* group1, ompi_group_t* group2,
|
2010-10-04 18:54:58 +04:00
|
|
|
ompi_group_t **new_group) {
|
2007-08-04 04:41:26 +04:00
|
|
|
|
|
|
|
/* local varibles */
|
2015-06-23 17:45:22 +03:00
|
|
|
int new_group_size, my_group_rank;
|
|
|
|
ompi_group_t *new_group_pointer;
|
2007-08-04 04:41:26 +04:00
|
|
|
ompi_proc_t *proc1_pointer, *proc2_pointer, *my_proc_pointer = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* form union
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* get new group size */
|
2015-06-23 17:45:22 +03:00
|
|
|
new_group_size = group1->grp_proc_count;
|
2007-08-04 04:41:26 +04:00
|
|
|
|
|
|
|
/* loop over group1 members */
|
2015-06-23 17:45:22 +03:00
|
|
|
for (int proc1 = 0 ; proc1 < group1->grp_proc_count ; ++proc1) {
|
|
|
|
proc1_pointer = ompi_group_get_proc_ptr_raw (group1, proc1);
|
|
|
|
|
2007-08-04 04:41:26 +04:00
|
|
|
/* check to see if this proc is in group2 */
|
2015-06-23 17:45:22 +03:00
|
|
|
for (int proc2 = 0 ; proc2 < group2->grp_proc_count ; ++proc2) {
|
|
|
|
proc2_pointer = ompi_group_get_proc_ptr_raw (group2, proc2);
|
2007-08-04 04:41:26 +04:00
|
|
|
if( proc1_pointer == proc2_pointer ) {
|
2015-06-23 17:45:22 +03:00
|
|
|
--new_group_size;
|
2007-08-04 04:41:26 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} /* end proc1 loop */
|
|
|
|
} /* end proc loop */
|
|
|
|
|
|
|
|
if ( 0 == new_group_size ) {
|
2010-10-04 18:54:58 +04:00
|
|
|
*new_group = MPI_GROUP_EMPTY;
|
|
|
|
OBJ_RETAIN(MPI_GROUP_EMPTY);
|
|
|
|
return MPI_SUCCESS;
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate a new ompi_group_t structure */
|
|
|
|
new_group_pointer=ompi_group_allocate(new_group_size);
|
|
|
|
if( NULL == new_group_pointer ) {
|
2010-10-04 18:54:58 +04:00
|
|
|
return MPI_ERR_GROUP;
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fill in group list */
|
|
|
|
/* loop over group1 members */
|
2015-06-23 17:45:22 +03:00
|
|
|
for (int proc1 = 0, cnt = 0 ; proc1 < group1->grp_proc_count ; ++proc1) {
|
|
|
|
bool found_in_group2 = false;
|
|
|
|
|
|
|
|
proc1_pointer = ompi_group_get_proc_ptr_raw (group1, proc1);
|
2007-08-04 04:41:26 +04:00
|
|
|
/* check to see if this proc is in group2 */
|
2015-06-23 17:45:22 +03:00
|
|
|
for (int proc2 = 0 ; proc2 < group2->grp_proc_count ; ++proc2) {
|
|
|
|
proc2_pointer = ompi_group_get_proc_ptr_raw (group2, proc2);
|
2007-08-04 04:41:26 +04:00
|
|
|
if( proc1_pointer == proc2_pointer ) {
|
2015-06-23 17:45:22 +03:00
|
|
|
found_in_group2 = true;
|
2007-08-04 04:41:26 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} /* end proc1 loop */
|
2015-06-23 17:45:22 +03:00
|
|
|
|
|
|
|
if (found_in_group2) {
|
2007-08-04 04:41:26 +04:00
|
|
|
continue;
|
2010-10-04 18:54:58 +04:00
|
|
|
}
|
2007-08-04 04:41:26 +04:00
|
|
|
|
2015-06-23 17:45:22 +03:00
|
|
|
new_group_pointer->grp_proc_pointers[cnt++] = proc1_pointer;
|
2007-08-04 04:41:26 +04:00
|
|
|
} /* end proc loop */
|
|
|
|
|
|
|
|
/* increment proc reference counters */
|
|
|
|
ompi_group_increment_proc_count(new_group_pointer);
|
|
|
|
|
|
|
|
/* find my rank */
|
2015-06-23 17:45:22 +03:00
|
|
|
my_group_rank=group1->grp_my_rank;
|
2007-08-04 04:41:26 +04:00
|
|
|
if ( MPI_UNDEFINED != my_group_rank ) {
|
2015-06-23 17:45:22 +03:00
|
|
|
my_proc_pointer = ompi_group_peer_lookup(group1,my_group_rank);
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
|
|
|
else {
|
2015-06-23 17:45:22 +03:00
|
|
|
my_group_rank=group2->grp_my_rank;
|
2010-10-04 18:54:58 +04:00
|
|
|
if ( MPI_UNDEFINED != my_group_rank ) {
|
2015-06-23 17:45:22 +03:00
|
|
|
my_proc_pointer = ompi_group_peer_lookup(group2,my_group_rank);
|
2010-10-04 18:54:58 +04:00
|
|
|
}
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( MPI_UNDEFINED == my_group_rank ) {
|
2010-10-04 18:54:58 +04:00
|
|
|
new_group_pointer->grp_my_rank = MPI_UNDEFINED;
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
|
|
|
else {
|
2010-10-04 18:54:58 +04:00
|
|
|
ompi_set_group_rank(new_group_pointer,my_proc_pointer);
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
*new_group = (MPI_Group)new_group_pointer;
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|