2007-12-21 09:02:00 +03:00
|
|
|
/* -*- Mode: C; c-basic-offset:4 ; -*- */
|
2004-02-13 05:20:43 +03:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2007-12-21 09:02:00 +03:00
|
|
|
* Copyright (c) 2004-2007 The University of Tennessee and The University
|
2005-11-05 22:57:48 +03:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2007-08-04 04:41:26 +04:00
|
|
|
* 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.
|
2009-02-24 20:17:33 +03:00
|
|
|
* Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-02-13 05:20:43 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2004-10-20 05:03:09 +04:00
|
|
|
#include "ompi_config.h"
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "ompi/group/group.h"
|
|
|
|
#include "ompi/constants.h"
|
2004-03-15 05:25:49 +03:00
|
|
|
#include "mpi.h"
|
2004-02-13 05:20:43 +03:00
|
|
|
|
|
|
|
/* define class information */
|
2004-06-07 19:33:53 +04:00
|
|
|
static void ompi_group_construct(ompi_group_t *);
|
|
|
|
static void ompi_group_destruct(ompi_group_t *);
|
2004-02-13 05:20:43 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
OBJ_CLASS_INSTANCE(ompi_group_t,
|
2005-07-03 20:06:07 +04:00
|
|
|
opal_object_t,
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_group_construct,
|
|
|
|
ompi_group_destruct);
|
2004-02-13 05:20:43 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Table for Fortran <-> C group handle conversion
|
|
|
|
*/
|
2007-12-21 09:02:00 +03:00
|
|
|
opal_pointer_array_t ompi_group_f_to_c_table;
|
2004-02-13 05:20:43 +03:00
|
|
|
|
2004-03-15 05:25:49 +03:00
|
|
|
/*
|
2004-06-15 04:08:57 +04:00
|
|
|
* Predefined group objects
|
2004-03-15 05:25:49 +03:00
|
|
|
*/
|
2009-02-24 20:17:33 +03:00
|
|
|
ompi_predefined_group_t ompi_mpi_group_empty;
|
|
|
|
ompi_predefined_group_t ompi_mpi_group_null;
|
2004-03-15 05:25:49 +03:00
|
|
|
|
2004-04-14 03:42:31 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a new group structure
|
2004-02-13 05:20:43 +03:00
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_group_t *ompi_group_allocate(int group_size)
|
2004-02-13 05:20:43 +03:00
|
|
|
{
|
|
|
|
/* local variables */
|
2006-03-09 21:18:24 +03:00
|
|
|
ompi_group_t * new_group = NULL;
|
|
|
|
|
|
|
|
assert (group_size >= 0);
|
2004-02-13 05:20:43 +03:00
|
|
|
|
|
|
|
/* create new group group element */
|
2004-06-07 19:33:53 +04:00
|
|
|
new_group = OBJ_NEW(ompi_group_t);
|
2006-03-09 21:18:24 +03:00
|
|
|
|
|
|
|
if (NULL == new_group)
|
|
|
|
goto error_exit;
|
|
|
|
|
|
|
|
if (OMPI_ERROR == new_group->grp_f_to_c_index) {
|
|
|
|
OBJ_RELEASE (new_group);
|
|
|
|
new_group = NULL;
|
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate array of (ompi_proc_t *)'s, one for each
|
|
|
|
* process in the group.
|
|
|
|
*/
|
|
|
|
new_group->grp_proc_pointers = (struct ompi_proc_t **)
|
|
|
|
malloc(sizeof(struct ompi_proc_t *) * group_size);
|
|
|
|
|
|
|
|
if (NULL == new_group->grp_proc_pointers) {
|
|
|
|
/* grp_proc_pointers allocation failed */
|
|
|
|
OBJ_RELEASE (new_group);
|
|
|
|
new_group = NULL;
|
|
|
|
goto error_exit;
|
2004-03-19 17:15:16 +03:00
|
|
|
}
|
|
|
|
|
2006-03-09 21:18:24 +03:00
|
|
|
/* set the group size */
|
|
|
|
new_group->grp_proc_count = group_size;
|
|
|
|
|
|
|
|
/* initialize our rank to MPI_UNDEFINED */
|
2007-08-04 04:41:26 +04:00
|
|
|
new_group->grp_my_rank = MPI_UNDEFINED;
|
|
|
|
OMPI_GROUP_SET_DENSE(new_group);
|
|
|
|
|
|
|
|
error_exit:
|
|
|
|
/* return */
|
|
|
|
return new_group;
|
|
|
|
}
|
|
|
|
|
|
|
|
ompi_group_t *ompi_group_allocate_sporadic(int group_size)
|
|
|
|
{
|
|
|
|
/* local variables */
|
|
|
|
ompi_group_t *new_group = NULL;
|
|
|
|
|
|
|
|
assert (group_size >= 0);
|
|
|
|
|
|
|
|
/* create new group group element */
|
|
|
|
new_group = OBJ_NEW(ompi_group_t);
|
2008-08-06 19:46:09 +04:00
|
|
|
if( NULL == new_group) {
|
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
if (OMPI_ERROR == new_group->grp_f_to_c_index) {
|
|
|
|
OBJ_RELEASE(new_group);
|
|
|
|
new_group = NULL;
|
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
/* allocate array of (grp_sporadic_list )'s */
|
|
|
|
if (0 < group_size) {
|
|
|
|
new_group->sparse_data.grp_sporadic.grp_sporadic_list =
|
|
|
|
(struct ompi_group_sporadic_list_t *)malloc
|
|
|
|
(sizeof(struct ompi_group_sporadic_list_t ) * group_size);
|
|
|
|
|
|
|
|
/* non-empty group */
|
|
|
|
if ( NULL == new_group->sparse_data.grp_sporadic.grp_sporadic_list) {
|
|
|
|
/* sporadic list allocation failed */
|
|
|
|
OBJ_RELEASE (new_group);
|
2007-08-04 04:41:26 +04:00
|
|
|
new_group = NULL;
|
2008-08-06 19:46:09 +04:00
|
|
|
goto error_exit;
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
|
|
|
}
|
2008-08-06 19:46:09 +04:00
|
|
|
|
|
|
|
/* set the group size */
|
|
|
|
new_group->grp_proc_count = group_size; /* actually it's the number of
|
|
|
|
elements in the sporadic list*/
|
|
|
|
|
|
|
|
/* initialize our rank to MPI_UNDEFINED */
|
|
|
|
new_group->grp_my_rank = MPI_UNDEFINED;
|
2007-08-04 04:41:26 +04:00
|
|
|
new_group->grp_proc_pointers = NULL;
|
|
|
|
OMPI_GROUP_SET_SPORADIC(new_group);
|
|
|
|
|
|
|
|
error_exit:
|
|
|
|
return new_group;
|
|
|
|
}
|
2008-08-06 19:50:54 +04:00
|
|
|
|
|
|
|
ompi_group_t *ompi_group_allocate_strided(void)
|
|
|
|
{
|
2007-08-04 04:41:26 +04:00
|
|
|
ompi_group_t *new_group = NULL;
|
2006-03-09 21:18:24 +03:00
|
|
|
|
2007-08-04 04:41:26 +04:00
|
|
|
/* create new group group element */
|
|
|
|
new_group = OBJ_NEW(ompi_group_t);
|
2008-08-06 19:50:54 +04:00
|
|
|
if( NULL == new_group ) {
|
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
if (OMPI_ERROR == new_group->grp_f_to_c_index) {
|
|
|
|
OBJ_RELEASE(new_group);
|
|
|
|
new_group = NULL;
|
|
|
|
goto error_exit;
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
2008-08-06 19:50:54 +04:00
|
|
|
/* initialize our rank to MPI_UNDEFINED */
|
|
|
|
new_group->grp_my_rank = MPI_UNDEFINED;
|
2007-08-04 04:41:26 +04:00
|
|
|
new_group->grp_proc_pointers = NULL;
|
|
|
|
OMPI_GROUP_SET_STRIDED(new_group);
|
|
|
|
new_group->sparse_data.grp_strided.grp_strided_stride = -1;
|
|
|
|
new_group->sparse_data.grp_strided.grp_strided_offset = -1;
|
|
|
|
new_group->sparse_data.grp_strided.grp_strided_last_element = -1;
|
2006-03-09 21:18:24 +03:00
|
|
|
error_exit:
|
2004-02-13 05:20:43 +03:00
|
|
|
/* return */
|
|
|
|
return new_group;
|
|
|
|
}
|
2007-08-04 04:41:26 +04:00
|
|
|
ompi_group_t *ompi_group_allocate_bmap(int orig_group_size , int group_size)
|
|
|
|
{
|
|
|
|
ompi_group_t *new_group = NULL;
|
2004-02-13 05:20:43 +03:00
|
|
|
|
2007-08-04 04:41:26 +04:00
|
|
|
assert (group_size >= 0);
|
|
|
|
|
|
|
|
/* create new group group element */
|
|
|
|
new_group = OBJ_NEW(ompi_group_t);
|
2008-08-06 19:50:54 +04:00
|
|
|
if( NULL == new_group) {
|
|
|
|
goto error_exit;
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
2008-08-06 19:50:54 +04:00
|
|
|
if (OMPI_ERROR == new_group->grp_f_to_c_index) {
|
|
|
|
OBJ_RELEASE(new_group);
|
|
|
|
new_group = NULL;
|
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
/* allocate the unsigned char list */
|
|
|
|
new_group->sparse_data.grp_bitmap.grp_bitmap_array = (unsigned char *)malloc
|
|
|
|
(sizeof(unsigned char) * ompi_group_div_ceil(orig_group_size,BSIZE));
|
|
|
|
|
|
|
|
new_group->sparse_data.grp_bitmap.grp_bitmap_array_len =
|
|
|
|
ompi_group_div_ceil(orig_group_size,BSIZE);
|
|
|
|
|
|
|
|
new_group->grp_proc_count = group_size;
|
|
|
|
|
|
|
|
/* initialize our rank to MPI_UNDEFINED */
|
|
|
|
new_group->grp_my_rank = MPI_UNDEFINED;
|
2007-08-04 04:41:26 +04:00
|
|
|
new_group->grp_proc_pointers = NULL;
|
|
|
|
OMPI_GROUP_SET_BITMAP(new_group);
|
|
|
|
|
|
|
|
error_exit:
|
|
|
|
/* return */
|
|
|
|
return new_group;
|
|
|
|
}
|
2004-04-14 03:42:31 +04:00
|
|
|
|
2004-03-16 01:14:08 +03:00
|
|
|
/*
|
|
|
|
* increment the reference count of the proc structures
|
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
void ompi_group_increment_proc_count(ompi_group_t *group)
|
2004-04-14 03:42:31 +04:00
|
|
|
{
|
2004-03-16 01:14:08 +03:00
|
|
|
int proc;
|
2007-08-04 04:41:26 +04:00
|
|
|
ompi_proc_t * proc_pointer;
|
2004-04-14 03:42:31 +04:00
|
|
|
for (proc = 0; proc < group->grp_proc_count; proc++) {
|
2007-08-04 04:41:26 +04:00
|
|
|
proc_pointer = ompi_group_peer_lookup(group,proc);
|
|
|
|
OBJ_RETAIN(proc_pointer);
|
2004-03-16 01:14:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-12-02 16:28:10 +03:00
|
|
|
/*
|
|
|
|
* decrement the reference count of the proc structures
|
|
|
|
*/
|
2007-08-04 04:41:26 +04:00
|
|
|
|
2004-12-02 16:28:10 +03:00
|
|
|
void ompi_group_decrement_proc_count(ompi_group_t *group)
|
|
|
|
{
|
|
|
|
int proc;
|
2007-08-04 04:41:26 +04:00
|
|
|
ompi_proc_t * proc_pointer;
|
2004-12-02 16:28:10 +03:00
|
|
|
for (proc = 0; proc < group->grp_proc_count; proc++) {
|
2007-08-04 04:41:26 +04:00
|
|
|
proc_pointer = ompi_group_peer_lookup(group,proc);
|
|
|
|
OBJ_RELEASE(proc_pointer);
|
2004-12-02 16:28:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-04-14 03:42:31 +04:00
|
|
|
/*
|
2004-02-13 05:20:43 +03:00
|
|
|
* group constructor
|
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
static void ompi_group_construct(ompi_group_t *new_group)
|
2004-03-16 01:14:08 +03:00
|
|
|
{
|
|
|
|
int ret_val;
|
|
|
|
|
2004-12-08 01:35:10 +03:00
|
|
|
/* Note that we do *NOT* increase the refcount on all the included
|
|
|
|
procs here because that is handled at a different level (e.g.,
|
|
|
|
the proc counts are not decreased during the desstructor,
|
|
|
|
either). */
|
|
|
|
|
2004-03-16 01:14:08 +03:00
|
|
|
/* assign entry in fortran <-> c translation array */
|
2007-12-21 09:02:00 +03:00
|
|
|
ret_val = opal_pointer_array_add(&ompi_group_f_to_c_table, new_group);
|
2004-04-14 03:42:31 +04:00
|
|
|
new_group->grp_f_to_c_index = ret_val;
|
2004-06-15 04:08:57 +04:00
|
|
|
new_group->grp_flags = 0;
|
2004-02-13 05:20:43 +03:00
|
|
|
|
2007-08-04 04:41:26 +04:00
|
|
|
/* default the sparse values for groups */
|
|
|
|
new_group->grp_parent_group_ptr = NULL;
|
|
|
|
|
2004-02-13 05:20:43 +03:00
|
|
|
/* return */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-04-14 03:42:31 +04:00
|
|
|
|
|
|
|
/*
|
2004-02-13 05:20:43 +03:00
|
|
|
* group destructor
|
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
static void ompi_group_destruct(ompi_group_t *group)
|
2004-03-16 01:14:08 +03:00
|
|
|
{
|
2004-12-08 01:35:10 +03:00
|
|
|
/* Note that we do *NOT* decrease the refcount on all the included
|
|
|
|
procs here because that is handled at a different level (e.g.,
|
|
|
|
the proc counts are not increased during the constructor,
|
|
|
|
either). */
|
|
|
|
|
2004-02-14 01:18:38 +03:00
|
|
|
/* release thegrp_proc_pointers memory */
|
2007-08-04 04:41:26 +04:00
|
|
|
if (NULL != group->grp_proc_pointers) {
|
2004-02-14 01:18:38 +03:00
|
|
|
free(group->grp_proc_pointers);
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (OMPI_GROUP_IS_SPORADIC(group)) {
|
|
|
|
if (NULL != group->sparse_data.grp_sporadic.grp_sporadic_list) {
|
|
|
|
free(group->sparse_data.grp_sporadic.grp_sporadic_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OMPI_GROUP_IS_BITMAP(group)) {
|
|
|
|
if (NULL != group->sparse_data.grp_bitmap.grp_bitmap_array) {
|
|
|
|
free(group->sparse_data.grp_bitmap.grp_bitmap_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL != group->grp_parent_group_ptr){
|
|
|
|
ompi_group_decrement_proc_count(group->grp_parent_group_ptr);
|
|
|
|
OBJ_RELEASE(group->grp_parent_group_ptr);
|
|
|
|
}
|
2004-02-14 01:18:38 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
/* reset the ompi_group_f_to_c_table entry - make sure that the
|
2004-02-14 01:18:38 +03:00
|
|
|
* entry is in the table */
|
2007-12-21 09:02:00 +03:00
|
|
|
if (NULL != opal_pointer_array_get_item(&ompi_group_f_to_c_table,
|
2004-04-14 03:42:31 +04:00
|
|
|
group->grp_f_to_c_index)) {
|
2007-12-21 09:02:00 +03:00
|
|
|
opal_pointer_array_set_item(&ompi_group_f_to_c_table,
|
2004-04-14 03:42:31 +04:00
|
|
|
group->grp_f_to_c_index, NULL);
|
2004-02-14 01:18:38 +03:00
|
|
|
}
|
|
|
|
|
2004-02-13 05:20:43 +03:00
|
|
|
/* return */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-04-14 03:42:31 +04:00
|
|
|
|
|
|
|
/*
|
2004-06-07 19:33:53 +04:00
|
|
|
* Initialize OMPI group infrastructure
|
2004-02-13 05:20:43 +03:00
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
int ompi_group_init(void)
|
2004-02-13 05:20:43 +03:00
|
|
|
{
|
2004-06-07 19:33:53 +04:00
|
|
|
/* initialize ompi_group_f_to_c_table */
|
2007-12-21 09:02:00 +03:00
|
|
|
OBJ_CONSTRUCT( &ompi_group_f_to_c_table, opal_pointer_array_t);
|
|
|
|
if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_group_f_to_c_table, 0,
|
|
|
|
OMPI_FORTRAN_HANDLE_MAX, 64) ) {
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
2004-06-15 04:08:57 +04:00
|
|
|
|
2004-03-15 05:25:49 +03:00
|
|
|
/* add MPI_GROUP_NULL to table */
|
2004-06-15 04:08:57 +04:00
|
|
|
OBJ_CONSTRUCT(&ompi_mpi_group_null, ompi_group_t);
|
2009-02-24 20:17:33 +03:00
|
|
|
ompi_mpi_group_null.group.grp_proc_count = 0;
|
|
|
|
ompi_mpi_group_null.group.grp_my_rank = MPI_PROC_NULL;
|
|
|
|
ompi_mpi_group_null.group.grp_proc_pointers = NULL;
|
|
|
|
ompi_mpi_group_null.group.grp_flags |= OMPI_GROUP_DENSE;
|
|
|
|
ompi_mpi_group_null.group.grp_flags |= OMPI_GROUP_INTRINSIC;
|
2007-08-04 04:41:26 +04:00
|
|
|
|
2004-06-15 04:08:57 +04:00
|
|
|
/* add MPI_GROUP_EMPTRY to table */
|
|
|
|
OBJ_CONSTRUCT(&ompi_mpi_group_empty, ompi_group_t);
|
2009-02-24 20:17:33 +03:00
|
|
|
ompi_mpi_group_empty.group.grp_proc_count = 0;
|
|
|
|
ompi_mpi_group_empty.group.grp_my_rank = MPI_UNDEFINED;
|
|
|
|
ompi_mpi_group_empty.group.grp_proc_pointers = NULL;
|
|
|
|
ompi_mpi_group_empty.group.grp_flags |= OMPI_GROUP_DENSE;
|
|
|
|
ompi_mpi_group_empty.group.grp_flags |= OMPI_GROUP_INTRINSIC;
|
2007-08-04 04:41:26 +04:00
|
|
|
|
2004-06-15 04:08:57 +04:00
|
|
|
return OMPI_SUCCESS;
|
2004-02-13 05:20:43 +03:00
|
|
|
}
|
2004-02-13 19:23:29 +03:00
|
|
|
|
2004-04-14 03:42:31 +04:00
|
|
|
|
|
|
|
/*
|
2004-02-13 19:23:29 +03:00
|
|
|
* Clean up group infrastructure
|
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
int ompi_group_finalize(void)
|
2004-04-14 03:42:31 +04:00
|
|
|
{
|
2009-02-24 20:17:33 +03:00
|
|
|
ompi_mpi_group_null.group.grp_flags = 0;
|
2004-06-15 04:08:57 +04:00
|
|
|
OBJ_DESTRUCT(&ompi_mpi_group_null);
|
2004-03-15 05:25:49 +03:00
|
|
|
|
2009-02-24 20:17:33 +03:00
|
|
|
ompi_mpi_group_null.group.grp_flags = 0;
|
2004-06-15 04:08:57 +04:00
|
|
|
OBJ_DESTRUCT(&ompi_mpi_group_empty);
|
2004-02-13 19:23:29 +03:00
|
|
|
|
2007-12-21 09:02:00 +03:00
|
|
|
OBJ_DESTRUCT(&ompi_group_f_to_c_table);
|
2004-06-15 04:08:57 +04:00
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
2004-03-26 08:00:29 +03:00
|
|
|
}
|
2007-08-04 04:41:26 +04:00
|
|
|
|
|
|
|
/* LocalWords: grp
|
|
|
|
*/
|