diff --git a/src/communicator/comm.c b/src/communicator/comm.c index a85e6f0773..79d28c91f5 100644 --- a/src/communicator/comm.c +++ b/src/communicator/comm.c @@ -51,20 +51,15 @@ static int ompi_comm_allgather_emulate_intra (void* inbuf, int incount, MPI_Data * This is the function setting all elements of a communicator. * All other routines are just used to determine these elements. */ -ompi_communicator_t * ompi_comm_set ( int mode, - ompi_communicator_t* oldcomm, - ompi_communicator_t* bridgecomm, - int local_size, - ompi_proc_t **local_procs, - int remote_size, - ompi_proc_t **remote_procs, - ompi_hash_table_t *attr, - ompi_errhandler_t *errh, - mca_base_module_t *collmodule, - mca_base_module_t *topomodule, - int local_leader, - int remote_leader - ) +ompi_communicator_t * ompi_comm_set ( ompi_communicator_t* oldcomm, + int local_size, + ompi_proc_t **local_procs, + int remote_size, + ompi_proc_t **remote_procs, + ompi_hash_table_t *attr, + ompi_errhandler_t *errh, + mca_base_module_t *collmodule, + mca_base_module_t *topomodule ) { ompi_communicator_t *newcomm; ompi_proc_t *my_gpointer; @@ -93,21 +88,6 @@ ompi_communicator_t * ompi_comm_set ( int mode, newcomm->c_flags |= OMPI_COMM_INTER; } - /* Determine context id. It is identical to f_2_c_handle */ -#ifdef HAVE_COLLECTIVES - newcomm->c_contextid = ompi_comm_nextcid ( oldcomm, - bridgecomm, - local_leader, - remote_leader, - mode ); -#else - /* just for now */ - newcomm->c_contextid = oldcomm->c_contextid + 10; - ompi_pointer_array_set_item ( &ompi_mpi_communicators, newcomm->c_contextid, - newcomm ); -#endif - newcomm->c_f_to_c_index = newcomm->c_contextid; - /* Set error handler */ newcomm->error_handler = errh; OBJ_RETAIN ( newcomm->error_handler ); @@ -257,26 +237,33 @@ int ompi_comm_create ( ompi_communicator_t *comm, ompi_group_t *group, mode = OMPI_COMM_INTRA_INTRA; } - newcomp = ompi_comm_set ( mode, /* mode */ - comm, /* old comm */ - NULL, /* bridge comm */ - group->grp_proc_count, /* local_size */ - group->grp_proc_pointers, /* local_procs*/ - rsize, /* remote_size */ - rprocs, /* remote_procs */ - NULL, /* attrs */ - comm->error_handler, /* error handler */ - NULL, /* coll module */ - NULL, /* topo module */ - MPI_UNDEFINED, /* local leader */ - MPI_UNDEFINED /* remote leader */ - ); + newcomp = ompi_comm_set ( comm, /* old comm */ + group->grp_proc_count, /* local_size */ + group->grp_proc_pointers, /* local_procs*/ + rsize, /* remote_size */ + rprocs, /* remote_procs */ + NULL, /* attrs */ + comm->error_handler, /* error handler */ + NULL, /* coll module */ + NULL /* topo module */ + ); - if ( newcomp == MPI_COMM_NULL ) { + if ( MPI_COMM_NULL == newcomp ) { rc = MPI_ERR_INTERN; goto exit; } + /* Determine context id. It is identical to f_2_c_handle */ + rc = ompi_comm_nextcid ( newcomp, /* new communicator */ + comm, /* old comm */ + NULL, /* bridge comm */ + MPI_UNDEFINED, /* local leader */ + MPI_UNDEFINED, /* remote_leader */ + mode ); /* mode */ + if ( OMPI_SUCCESS != rc ) { + goto exit; + } + /* Check whether we are part of the new comm. If not, we have to free the structure again. However, we could not avoid the comm_nextcid step, since @@ -463,21 +450,31 @@ int ompi_comm_split ( ompi_communicator_t* comm, int color, int key, /* Step 3: set up the communicator */ /* --------------------------------------------------------- */ /* Create the communicator finally */ - newcomp = ompi_comm_set ( mode, /* mode */ - comm, /* old comm */ - NULL, /* bridge comm */ - my_size, /* local_size */ - procs, /* local_procs*/ - my_rsize, /* remote_size */ - rprocs, /* remote_procs */ - NULL, /* attrs */ - comm->error_handler,/* error handler */ - NULL, /* coll module */ - NULL, /* topo module */ - MPI_UNDEFINED, /* local leader */ - MPI_UNDEFINED /* remote leader */ - ); - if ( MPI_COMM_NULL == newcomp ) rc = MPI_ERR_INTERN; + newcomp = ompi_comm_set ( comm, /* old comm */ + my_size, /* local_size */ + procs, /* local_procs*/ + my_rsize, /* remote_size */ + rprocs, /* remote_procs */ + NULL, /* attrs */ + comm->error_handler,/* error handler */ + NULL, /* coll module */ + NULL /* topo module */ + ); + if ( MPI_COMM_NULL == newcomp ) { + rc = MPI_ERR_INTERN; + goto exit; + } + + /* Determine context id. It is identical to f_2_c_handle */ + rc = ompi_comm_nextcid ( newcomp, /* new communicator */ + comm, /* old comm */ + NULL, /* bridge comm */ + MPI_UNDEFINED, /* local leader */ + MPI_UNDEFINED, /* remote_leader */ + mode ); /* mode */ + if ( OMPI_SUCCESS != rc ) { + goto exit; + } exit: if ( NULL != results ) { diff --git a/src/communicator/comm_cid.c b/src/communicator/comm_cid.c index 1a9ca673e9..ac2df55315 100644 --- a/src/communicator/comm_cid.c +++ b/src/communicator/comm_cid.c @@ -21,7 +21,23 @@ #define OMPI_COMM_CID_TAG 1011 #define OMPI_MAX_COMM 32768 +#ifndef HAVE_COLLECTIVES +int ompi_comm_nextcid ( ompi_communicator_t* newcomm, + ompi_communicator_t* comm, + ompi_communicator_t* bridgecomm, + int local_leader, + int remote_leader, + int mode ) +{ + /* set the according values to the newcomm */ + newcomm->c_contextid = comm->c_contextid + 10; + ompi_pointer_array_set_item (&ompi_mpi_communicators, + newcomm->c_contextid, + newcomm); + return ( MPI_SUCCESS ); +} +#else /** * These functions make sure, that we determine the global result over * an intra communicators (simple), an inter-communicator and a @@ -50,11 +66,12 @@ static int ompi_comm_allreduce_intra ( int *inbuf, int* outbuf, int count, int local_leader, int remote_ledaer ); -int ompi_comm_nextcid ( ompi_communicator_t* comm, - ompi_communicator_t* bridgecomm, - int local_leader, - int remote_leader, - int mode ) +int ompi_comm_nextcid ( ompi_communicator_t* newcomm, + ompi_communicator_t* comm, + ompi_communicator_t* bridgecomm, + int local_leader, + int remote_leader, + int mode ) { int nextlocal_cid; @@ -127,7 +144,11 @@ int ompi_comm_nextcid ( ompi_communicator_t* comm, } } - return (nextcid); + /* set the according values to the newcomm */ + newcomm->c_contextid = nextcid; + ompi_pointer_array_set_item (&ompi_mpi_communicators, nextcid, newcomm); + + return (MPI_SUCCESS); } /********************************************************************************/ @@ -353,4 +374,4 @@ static int ompi_comm_allreduce_emulate_inter (int *inbuf, int *outbuf, int count return (rc); } - +#endif diff --git a/src/communicator/comm_init.c b/src/communicator/comm_init.c index 9911b62dfb..7baa6f862d 100644 --- a/src/communicator/comm_init.c +++ b/src/communicator/comm_init.c @@ -25,15 +25,16 @@ ompi_pointer_array_t ompi_mpi_communicators; ompi_communicator_t ompi_mpi_comm_world; ompi_communicator_t ompi_mpi_comm_self; ompi_communicator_t ompi_mpi_comm_null; +ompi_communicator_t *ompi_mpi_comm_parent; static void ompi_comm_construct(ompi_communicator_t* comm); static void ompi_comm_destruct(ompi_communicator_t* comm); -OBJ_CLASS_INSTANCE(ompi_communicator_t, ompi_object_t,ompi_comm_construct, ompi_comm_destruct ); +OBJ_CLASS_INSTANCE(ompi_communicator_t,ompi_object_t,ompi_comm_construct,ompi_comm_destruct); /* - * Initialize comm world/self/null. + * Initialize comm world/self/null/parent. */ int ompi_comm_init(void) { @@ -143,6 +144,13 @@ int ompi_comm_init(void) ompi_mpi_comm_null.bcast_lin_reqs = NULL; ompi_mpi_comm_null.bcast_log_reqs = NULL; + /* 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); + return OMPI_SUCCESS; } diff --git a/src/communicator/communicator.h b/src/communicator/communicator.h index 20d4d29e5d..c23b953100 100644 --- a/src/communicator/communicator.h +++ b/src/communicator/communicator.h @@ -92,6 +92,7 @@ struct ompi_communicator_t { }; typedef struct ompi_communicator_t ompi_communicator_t; +extern ompi_communicator_t *ompi_mpi_comm_parent; /** @@ -225,7 +226,8 @@ extern "C" { /** * allocate new communicator ID - * @param comm: original comm + * @param newcomm: pointer to the new communicator + * @param oldcomm: original comm * @param bridgecomm: bridge comm for intercomm_create * @param mode: combination of input and output communicator * OMPI_COMM_INTRA_INTRA, OMPI_COMM_INTRA_INTER, @@ -233,12 +235,13 @@ extern "C" { * * This routine has to be thread safe in the final version. */ - int ompi_comm_nextcid ( ompi_communicator_t* comm, - ompi_communicator_t* bridgecomm, - int local_leader, - int remote_leader, - int mode); - + int ompi_comm_nextcid ( ompi_communicator_t* newcomm, + ompi_communicator_t* oldcomm, + ompi_communicator_t* bridgecomm, + int local_leader, + int remote_leader, + int mode); + /** * shut down the communicator infrastructure. @@ -249,19 +252,15 @@ extern "C" { * This is THE routine, where all the communicator stuff * is really set. */ - ompi_communicator_t* ompi_comm_set ( int mode, - ompi_communicator_t* oldcomm, - ompi_communicator_t* bridgecomm, - int local_size, - ompi_proc_t **local_procs, - int remote_size, - ompi_proc_t **remote_procs, - ompi_hash_table_t *attr, - ompi_errhandler_t *errh, - mca_base_module_t *collmodule, - mca_base_module_t *topomodule, - int local_leader, - int remote_leader); + ompi_communicator_t* ompi_comm_set ( ompi_communicator_t* oldcomm, + int local_size, + ompi_proc_t **local_procs, + int remote_size, + ompi_proc_t **remote_procs, + ompi_hash_table_t *attr, + ompi_errhandler_t *errh, + mca_base_module_t *collmodule, + mca_base_module_t *topomodule ); /** * This is a short-hand routine used in intercomm_create. * The routine makes sure, that all processes have afterwards