2004-02-05 04:52:56 +03:00
|
|
|
/*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "ompi_config.h"
|
2004-02-05 04:52:56 +03:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2004-06-29 04:02:25 +04:00
|
|
|
|
2004-02-05 04:52:56 +03:00
|
|
|
#include "mpi.h"
|
2004-03-26 23:02:42 +03:00
|
|
|
|
2004-03-17 21:45:16 +03:00
|
|
|
#include "communicator/communicator.h"
|
2004-06-29 04:02:25 +04:00
|
|
|
#include "util/bit_ops.h"
|
2004-03-26 23:02:42 +03:00
|
|
|
#include "include/constants.h"
|
2004-03-17 21:45:16 +03:00
|
|
|
#include "mca/pml/pml.h"
|
2004-05-08 03:15:10 +04:00
|
|
|
#include "mca/coll/coll.h"
|
|
|
|
#include "mca/coll/base/base.h"
|
2004-07-21 02:21:47 +04:00
|
|
|
#include "mca/topo/topo.h"
|
|
|
|
#include "mca/topo/base/base.h"
|
2004-07-08 18:48:34 +04:00
|
|
|
#include "mca/ns/base/base.h"
|
2004-08-14 05:56:05 +04:00
|
|
|
#include "mpi/runtime/params.h"
|
2004-02-05 04:52:56 +03:00
|
|
|
|
|
|
|
|
2004-03-31 20:59:46 +04:00
|
|
|
/*
|
|
|
|
** Table for Fortran <-> C communicator handle conversion
|
|
|
|
** Also used by P2P code to lookup communicator based
|
|
|
|
** on cid.
|
|
|
|
**
|
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_pointer_array_t ompi_mpi_communicators;
|
2004-05-21 23:36:19 +04:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_communicator_t ompi_mpi_comm_world;
|
|
|
|
ompi_communicator_t ompi_mpi_comm_self;
|
|
|
|
ompi_communicator_t ompi_mpi_comm_null;
|
2004-06-16 19:40:52 +04:00
|
|
|
ompi_communicator_t *ompi_mpi_comm_parent;
|
2004-02-05 04:52:56 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
static void ompi_comm_construct(ompi_communicator_t* comm);
|
|
|
|
static void ompi_comm_destruct(ompi_communicator_t* comm);
|
2004-02-05 04:52:56 +03:00
|
|
|
|
2004-06-16 19:40:52 +04:00
|
|
|
OBJ_CLASS_INSTANCE(ompi_communicator_t,ompi_object_t,ompi_comm_construct,ompi_comm_destruct);
|
2004-02-13 16:56:55 +03:00
|
|
|
|
2004-02-06 07:20:13 +03:00
|
|
|
|
2004-02-05 04:52:56 +03:00
|
|
|
/*
|
2004-06-16 19:40:52 +04:00
|
|
|
* Initialize comm world/self/null/parent.
|
2004-02-05 04:52:56 +03:00
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
int ompi_comm_init(void)
|
2004-02-05 04:52:56 +03:00
|
|
|
{
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_group_t *group;
|
2004-02-13 16:56:55 +03:00
|
|
|
size_t size;
|
|
|
|
|
2004-03-12 01:02:01 +03:00
|
|
|
/* Setup communicator array */
|
2004-06-07 19:33:53 +04:00
|
|
|
OBJ_CONSTRUCT(&ompi_mpi_communicators, ompi_pointer_array_t);
|
2004-03-26 23:02:42 +03:00
|
|
|
|
2004-03-12 01:02:01 +03:00
|
|
|
|
2004-02-13 16:56:55 +03:00
|
|
|
/* Setup MPI_COMM_WORLD */
|
2004-06-07 19:33:53 +04:00
|
|
|
OBJ_CONSTRUCT(&ompi_mpi_comm_world, ompi_communicator_t);
|
|
|
|
group = OBJ_NEW(ompi_group_t);
|
|
|
|
group->grp_proc_pointers = ompi_proc_world(&size);
|
2004-05-21 23:36:19 +04:00
|
|
|
group->grp_proc_count = size;
|
2004-06-15 04:09:40 +04:00
|
|
|
group->grp_flags |= OMPI_GROUP_INTRINSIC;
|
2004-09-10 02:57:53 +04:00
|
|
|
ompi_set_group_rank(group, ompi_proc_local());
|
2004-02-13 16:56:55 +03:00
|
|
|
OBJ_RETAIN(group); /* bump reference count for remote reference */
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_mpi_comm_world.c_contextid = 0;
|
|
|
|
ompi_mpi_comm_world.c_f_to_c_index = 0;
|
|
|
|
ompi_mpi_comm_world.c_my_rank = group->grp_my_rank;
|
|
|
|
ompi_mpi_comm_world.c_local_group = group;
|
|
|
|
ompi_mpi_comm_world.c_remote_group = group;
|
|
|
|
ompi_mpi_comm_world.c_cube_dim = ompi_cube_dim(size);
|
|
|
|
ompi_mpi_comm_world.error_handler = &ompi_mpi_errors_are_fatal;
|
|
|
|
OBJ_RETAIN( &ompi_mpi_errors_are_fatal );
|
|
|
|
mca_pml.pml_add_comm(&ompi_mpi_comm_world);
|
|
|
|
ompi_pointer_array_set_item (&ompi_mpi_communicators, 0, &ompi_mpi_comm_world);
|
|
|
|
|
|
|
|
strncpy (ompi_mpi_comm_world.c_name, "MPI_COMM_WORLD",
|
2004-03-26 23:02:42 +03:00
|
|
|
strlen("MPI_COMM_WORLD")+1 );
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_mpi_comm_world.c_flags |= OMPI_COMM_NAMEISSET;
|
2004-06-15 04:09:40 +04:00
|
|
|
ompi_mpi_comm_world.c_flags |= OMPI_COMM_INTRINSIC;
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_attr_hash_init(&ompi_mpi_comm_world.c_keyhash);
|
2004-05-08 03:15:10 +04:00
|
|
|
|
2004-02-13 16:56:55 +03:00
|
|
|
/* Setup MPI_COMM_SELF */
|
2004-06-07 19:33:53 +04:00
|
|
|
OBJ_CONSTRUCT(&ompi_mpi_comm_self, ompi_communicator_t);
|
|
|
|
group = OBJ_NEW(ompi_group_t);
|
|
|
|
group->grp_proc_pointers = ompi_proc_self(&size);
|
2004-05-21 23:36:19 +04:00
|
|
|
group->grp_my_rank = 0;
|
|
|
|
group->grp_proc_count = size;
|
2004-06-15 04:09:40 +04:00
|
|
|
group->grp_flags |= OMPI_GROUP_INTRINSIC;
|
2004-03-03 19:44:41 +03:00
|
|
|
OBJ_RETAIN(group); /* bump reference count for remote reference */
|
2004-02-13 16:56:55 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_mpi_comm_self.c_contextid = 1;
|
|
|
|
ompi_mpi_comm_self.c_f_to_c_index = 1;
|
|
|
|
ompi_mpi_comm_self.c_my_rank = group->grp_my_rank;
|
|
|
|
ompi_mpi_comm_self.c_local_group = group;
|
|
|
|
ompi_mpi_comm_self.c_remote_group = group;
|
|
|
|
ompi_mpi_comm_self.error_handler = &ompi_mpi_errors_are_fatal;
|
|
|
|
OBJ_RETAIN( &ompi_mpi_errors_are_fatal );
|
|
|
|
mca_pml.pml_add_comm(&ompi_mpi_comm_self);
|
|
|
|
ompi_pointer_array_set_item (&ompi_mpi_communicators, 1, &ompi_mpi_comm_self);
|
|
|
|
|
|
|
|
strncpy(ompi_mpi_comm_self.c_name,"MPI_COMM_SELF",strlen("MPI_COMM_SELF")+1);
|
|
|
|
ompi_mpi_comm_self.c_flags |= OMPI_COMM_NAMEISSET;
|
2004-06-15 04:09:40 +04:00
|
|
|
ompi_mpi_comm_self.c_flags |= OMPI_COMM_INTRINSIC;
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_attr_hash_init(&ompi_mpi_comm_self.c_keyhash);
|
2004-05-30 20:50:41 +04:00
|
|
|
|
2004-05-21 23:36:19 +04:00
|
|
|
/* Setup MPI_COMM_NULL */
|
2004-06-07 19:33:53 +04:00
|
|
|
OBJ_CONSTRUCT(&ompi_mpi_comm_null, ompi_communicator_t);
|
2004-06-15 04:09:40 +04:00
|
|
|
ompi_mpi_comm_null.c_local_group = &ompi_mpi_group_null;
|
|
|
|
ompi_mpi_comm_null.c_remote_group = &ompi_mpi_group_null;
|
|
|
|
OBJ_RETAIN(&ompi_mpi_group_null);
|
|
|
|
OBJ_RETAIN(&ompi_mpi_group_null);
|
2004-05-21 23:36:19 +04:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_mpi_comm_null.c_contextid = 2;
|
|
|
|
ompi_mpi_comm_null.c_f_to_c_index = 2;
|
|
|
|
ompi_mpi_comm_null.c_my_rank = MPI_PROC_NULL;
|
2004-06-15 04:09:40 +04:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_mpi_comm_null.error_handler = &ompi_mpi_errors_are_fatal;
|
|
|
|
OBJ_RETAIN( &ompi_mpi_errors_are_fatal );
|
|
|
|
ompi_pointer_array_set_item (&ompi_mpi_communicators, 2, &ompi_mpi_comm_null);
|
2004-05-21 23:36:19 +04:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
strncpy(ompi_mpi_comm_null.c_name,"MPI_COMM_NULL",strlen("MPI_COMM_NULL")+1);
|
|
|
|
ompi_mpi_comm_null.c_flags |= OMPI_COMM_NAMEISSET;
|
2004-06-15 04:09:40 +04:00
|
|
|
ompi_mpi_comm_null.c_flags |= OMPI_COMM_INTRINSIC;
|
2004-05-21 23:36:19 +04:00
|
|
|
|
2004-06-16 19:40:52 +04:00
|
|
|
/* Initialize the parent communicator to MPI_COMM_NULL */
|
|
|
|
ompi_mpi_comm_parent = &ompi_mpi_comm_null;
|
|
|
|
OBJ_RETAIN(&ompi_mpi_comm_null);
|
|
|
|
OBJ_RETAIN(&ompi_mpi_group_null);
|
|
|
|
OBJ_RETAIN(&ompi_mpi_group_null);
|
|
|
|
OBJ_RETAIN(&ompi_mpi_errors_are_fatal);
|
|
|
|
|
2004-09-21 22:39:06 +04:00
|
|
|
/* initialize the comm_reg stuff for multi-threaded comm_cid
|
|
|
|
allocation */
|
|
|
|
ompi_comm_reg_init();
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_SUCCESS;
|
2004-03-26 23:02:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_communicator_t *ompi_comm_allocate ( int local_size, int remote_size )
|
2004-03-26 23:02:42 +03:00
|
|
|
{
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_communicator_t *new_comm=NULL;
|
2004-03-26 23:02:42 +03:00
|
|
|
|
|
|
|
/* create new communicator element */
|
2004-06-07 19:33:53 +04:00
|
|
|
new_comm = OBJ_NEW(ompi_communicator_t);
|
|
|
|
new_comm->c_local_group = ompi_group_allocate ( local_size );
|
2004-05-21 23:36:19 +04:00
|
|
|
if ( 0 < remote_size ) {
|
2004-06-07 19:33:53 +04:00
|
|
|
new_comm->c_remote_group = ompi_group_allocate (remote_size);
|
|
|
|
new_comm->c_flags |= OMPI_COMM_INTER;
|
2004-03-26 23:02:42 +03:00
|
|
|
}
|
|
|
|
else {
|
2004-06-04 01:23:42 +04:00
|
|
|
/*
|
|
|
|
* simplifies some operations (e.g. p2p), if
|
|
|
|
* we can always use the remote group
|
2004-05-21 23:36:19 +04:00
|
|
|
*/
|
|
|
|
new_comm->c_remote_group = new_comm->c_local_group;
|
2004-07-16 00:55:15 +04:00
|
|
|
OBJ_RETAIN(new_comm->c_remote_group);
|
2004-03-26 23:02:42 +03:00
|
|
|
}
|
|
|
|
|
2004-05-21 23:36:19 +04:00
|
|
|
/* fill in the inscribing hyper-cube dimensions */
|
2004-06-07 19:33:53 +04:00
|
|
|
new_comm->c_cube_dim = ompi_cube_dim(local_size);
|
|
|
|
if ( OMPI_ERROR == new_comm->c_cube_dim ) {
|
2004-05-21 23:36:19 +04:00
|
|
|
OBJ_RELEASE(new_comm);
|
|
|
|
new_comm = NULL;
|
2004-03-26 23:02:42 +03:00
|
|
|
}
|
|
|
|
|
2004-05-21 23:36:19 +04:00
|
|
|
return new_comm;
|
2004-03-26 23:02:42 +03:00
|
|
|
}
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
int ompi_comm_finalize(void)
|
2004-03-26 23:02:42 +03:00
|
|
|
{
|
2004-08-13 22:55:07 +04:00
|
|
|
int max, i;
|
|
|
|
ompi_communicator_t *comm;
|
|
|
|
|
2004-06-15 04:09:40 +04:00
|
|
|
/* Destroy all predefined communicators */
|
|
|
|
|
|
|
|
ompi_mpi_comm_world.c_local_group->grp_flags = 0;
|
|
|
|
ompi_mpi_comm_world.c_flags = 0;
|
2004-06-07 19:33:53 +04:00
|
|
|
OBJ_DESTRUCT( &ompi_mpi_comm_world );
|
2004-06-15 04:09:40 +04:00
|
|
|
|
|
|
|
ompi_mpi_comm_self.c_local_group->grp_flags = 0;
|
|
|
|
ompi_mpi_comm_self.c_flags = 0;
|
2004-06-07 19:33:53 +04:00
|
|
|
OBJ_DESTRUCT( &ompi_mpi_comm_self );
|
2004-06-04 01:23:42 +04:00
|
|
|
|
2004-09-19 11:13:58 +04:00
|
|
|
if( ompi_mpi_comm_parent != &ompi_mpi_comm_null ) {
|
|
|
|
ompi_mpi_comm_parent->c_local_group->grp_flags = 0;
|
|
|
|
ompi_mpi_comm_parent->c_flags = 0;
|
|
|
|
OBJ_RETAIN (&ompi_mpi_comm_parent);
|
|
|
|
}
|
2004-09-13 19:14:09 +04:00
|
|
|
|
2004-08-13 22:55:07 +04:00
|
|
|
ompi_mpi_comm_null.c_local_group->grp_flags = 0;
|
|
|
|
ompi_mpi_comm_null.c_flags = 0;
|
|
|
|
OBJ_DESTRUCT( &ompi_mpi_comm_null );
|
|
|
|
|
|
|
|
/* Check whether we have some communicators left */
|
|
|
|
max = ompi_pointer_array_get_size(&ompi_mpi_communicators);
|
|
|
|
for ( i=3; i<max; i++ ) {
|
|
|
|
comm = ompi_pointer_array_get_item(&ompi_mpi_communicators, i);
|
|
|
|
if ( NULL != comm ) {
|
|
|
|
/* Communicator has not been freed before finalize */
|
|
|
|
OBJ_RELEASE(comm);
|
|
|
|
comm=ompi_pointer_array_get_item(&ompi_mpi_communicators, i);
|
|
|
|
if ( NULL != comm ) {
|
|
|
|
/* Still here ? */
|
|
|
|
if ( ompi_debug_show_handle_leaks && !(OMPI_COMM_IS_FREED(comm)) ){
|
|
|
|
ompi_output(0,"WARNING: MPI_Comm still allocated in MPI_Finalize\n");
|
|
|
|
ompi_comm_dump ( comm);
|
|
|
|
OBJ_RELEASE(comm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
OBJ_DESTRUCT (&ompi_mpi_communicators);
|
2004-06-04 01:23:42 +04:00
|
|
|
|
2004-09-21 22:39:06 +04:00
|
|
|
/* finalize the comm_reg stuff */
|
|
|
|
ompi_comm_reg_finalize();
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_SUCCESS;
|
2004-02-05 04:52:56 +03:00
|
|
|
}
|
2004-02-13 16:56:55 +03:00
|
|
|
|
2004-03-26 23:02:42 +03:00
|
|
|
/*
|
2004-05-21 23:36:19 +04:00
|
|
|
* For linking only. To be checked.
|
2004-03-26 23:02:42 +03:00
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
int ompi_comm_link_function(void)
|
2004-03-26 23:02:42 +03:00
|
|
|
{
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_SUCCESS;
|
2004-03-26 23:02:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
/********************************************************************************/
|
|
|
|
/********************************************************************************/
|
|
|
|
/* static functions */
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
static void ompi_comm_construct(ompi_communicator_t* comm)
|
2004-03-26 23:02:42 +03:00
|
|
|
{
|
2004-05-21 23:36:19 +04:00
|
|
|
comm->c_f_to_c_index = MPI_UNDEFINED;
|
2004-06-04 01:23:42 +04:00
|
|
|
comm->c_name[0] = '\0';
|
|
|
|
comm->c_contextid = MPI_UNDEFINED;
|
|
|
|
comm->c_flags = 0;
|
|
|
|
comm->c_my_rank = 0;
|
|
|
|
comm->c_cube_dim = 0;
|
2004-03-26 23:02:42 +03:00
|
|
|
comm->c_local_group = NULL;
|
|
|
|
comm->c_remote_group = NULL;
|
|
|
|
comm->error_handler = NULL;
|
|
|
|
comm->c_pml_comm = NULL;
|
2004-08-06 02:48:47 +04:00
|
|
|
comm->c_topo = NULL;
|
2004-04-20 03:13:01 +04:00
|
|
|
comm->c_topo_comm = NULL;
|
2004-08-06 02:48:47 +04:00
|
|
|
comm->c_topo_module = NULL;
|
|
|
|
|
|
|
|
#if OMPI_ENABLE_DEBUG
|
|
|
|
memset (&(comm->c_coll), 0, sizeof(mca_coll_base_module_1_0_0_t));
|
|
|
|
#endif
|
2004-03-26 23:02:42 +03:00
|
|
|
|
2004-08-02 04:24:22 +04:00
|
|
|
comm->c_coll_selected_module = NULL;
|
|
|
|
comm->c_coll_selected_data = NULL;
|
|
|
|
comm->c_coll_basic_module = NULL;
|
|
|
|
comm->c_coll_basic_data = NULL;
|
2004-06-29 04:02:25 +04:00
|
|
|
|
2004-09-06 16:06:27 +04:00
|
|
|
comm->errhandler_type = OMPI_ERRHANDLER_TYPE_COMM;
|
2004-03-26 23:02:42 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
static void ompi_comm_destruct(ompi_communicator_t* comm)
|
2004-03-26 23:02:42 +03:00
|
|
|
{
|
2004-06-29 04:02:25 +04:00
|
|
|
/* Release the collective module */
|
|
|
|
|
|
|
|
mca_coll_base_comm_unselect(comm);
|
|
|
|
|
|
|
|
/* Release topology information */
|
|
|
|
|
2004-07-21 02:21:47 +04:00
|
|
|
mca_topo_base_comm_unselect(comm);
|
2004-06-29 04:02:25 +04:00
|
|
|
|
2004-07-21 02:21:47 +04:00
|
|
|
/* Check if the communicator is a topology */
|
2004-06-04 01:23:42 +04:00
|
|
|
|
2004-07-21 02:21:47 +04:00
|
|
|
if (OMPI_COMM_IS_CART(comm) || OMPI_COMM_IS_GRAPH(comm)) {
|
|
|
|
|
|
|
|
/* check and free individual things */
|
|
|
|
|
|
|
|
if (NULL != comm->c_topo_comm) {
|
|
|
|
|
|
|
|
/* check for all pointers and free them */
|
|
|
|
|
|
|
|
if (NULL != comm->c_topo_comm->mtc_dims_or_index) {
|
|
|
|
free(comm->c_topo_comm->mtc_dims_or_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL != comm->c_topo_comm->mtc_dims_or_index) {
|
|
|
|
free(comm->c_topo_comm->mtc_periods_or_edges);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL != comm->c_topo_comm->mtc_dims_or_index) {
|
|
|
|
free(comm->c_topo_comm->mtc_coords);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(comm->c_topo_comm);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL != comm->c_remote_group) {
|
|
|
|
OBJ_RELEASE ( comm->c_remote_group );
|
|
|
|
}
|
2004-09-13 19:14:09 +04:00
|
|
|
if (NULL != comm->c_local_group) {
|
|
|
|
OBJ_RELEASE ( comm->c_local_group );
|
|
|
|
}
|
2004-08-10 02:06:07 +04:00
|
|
|
if (NULL != comm->error_handler) {
|
2004-07-21 02:21:47 +04:00
|
|
|
OBJ_RELEASE ( comm->error_handler );
|
|
|
|
}
|
2004-03-26 23:02:42 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
/* reset the ompi_comm_f_to_c_table entry */
|
2004-08-13 17:31:26 +04:00
|
|
|
if ( MPI_UNDEFINED != comm->c_f_to_c_index &&
|
|
|
|
NULL != ompi_pointer_array_get_item(&ompi_mpi_communicators,
|
|
|
|
comm->c_f_to_c_index )) {
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_pointer_array_set_item ( &ompi_mpi_communicators,
|
2004-07-16 00:55:15 +04:00
|
|
|
comm->c_f_to_c_index, NULL);
|
2004-03-31 20:59:46 +04:00
|
|
|
}
|
2004-05-21 23:36:19 +04:00
|
|
|
|
|
|
|
|
2004-03-26 23:02:42 +03:00
|
|
|
return;
|
|
|
|
}
|