2004-01-26 01:07:54 +03:00
|
|
|
/*
|
2007-03-17 02:11:45 +03:00
|
|
|
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
|
2005-11-05 22:57:48 +03:00
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2008-11-05 00:58:06 +03:00
|
|
|
* Copyright (c) 2004-2008 The University of Tennessee and The University
|
2005-11-05 22:57:48 +03:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2008-02-12 11:46:27 +03:00
|
|
|
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
|
2004-11-28 23:09:25 +03:00
|
|
|
* 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 Cisco Systems, Inc. All rights reserved.
|
2009-05-27 19:21:07 +04:00
|
|
|
* Copyright (c) 2006-2009 University of Houston. All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-01-26 01:07:54 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "ompi_config.h"
|
2004-01-26 01:07:54 +03:00
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "ompi/mpi/c/bindings.h"
|
2009-04-29 05:32:14 +04:00
|
|
|
#include "ompi/runtime/params.h"
|
|
|
|
#include "ompi/errhandler/errhandler.h"
|
2005-09-12 13:17:44 +04:00
|
|
|
#include "ompi/mca/pml/pml.h"
|
|
|
|
#include "ompi/communicator/communicator.h"
|
|
|
|
#include "ompi/request/request.h"
|
2008-02-12 21:01:17 +03:00
|
|
|
#include "ompi/memchecker.h"
|
2004-01-26 01:07:54 +03:00
|
|
|
|
2009-05-07 00:11:28 +04:00
|
|
|
#if OPAL_HAVE_WEAK_SYMBOLS && OMPI_PROFILING_DEFINES
|
2004-01-26 01:07:54 +03:00
|
|
|
#pragma weak MPI_Intercomm_create = PMPI_Intercomm_create
|
|
|
|
#endif
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#if OMPI_PROFILING_DEFINES
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "ompi/mpi/c/profile/defines.h"
|
2004-04-20 22:50:43 +04:00
|
|
|
#endif
|
|
|
|
|
2004-07-30 06:58:53 +04:00
|
|
|
static const char FUNC_NAME[] = "MPI_Intercomm_create";
|
2004-06-23 00:21:35 +04:00
|
|
|
|
|
|
|
|
2004-01-26 01:07:54 +03:00
|
|
|
int MPI_Intercomm_create(MPI_Comm local_comm, int local_leader,
|
|
|
|
MPI_Comm bridge_comm, int remote_leader,
|
2004-05-21 23:32:18 +04:00
|
|
|
int tag, MPI_Comm *newintercomm)
|
|
|
|
{
|
2004-12-06 05:15:34 +03:00
|
|
|
int local_size=0, local_rank=0;
|
|
|
|
int lleader=0, rleader=0;
|
|
|
|
ompi_communicator_t *newcomp=NULL;
|
2005-09-12 13:17:44 +04:00
|
|
|
struct ompi_proc_t **rprocs=NULL;
|
2004-12-06 05:15:34 +03:00
|
|
|
int rc=0, rsize=0;
|
2007-08-04 04:41:26 +04:00
|
|
|
ompi_proc_t **proc_list=NULL;
|
2007-08-07 19:13:46 +04:00
|
|
|
int j;
|
2007-08-04 04:41:26 +04:00
|
|
|
ompi_group_t *new_group_pointer;
|
2004-03-26 23:03:38 +03:00
|
|
|
|
2008-02-12 11:46:27 +03:00
|
|
|
MEMCHECKER(
|
|
|
|
memchecker_comm(local_comm);
|
|
|
|
memchecker_comm(bridge_comm);
|
|
|
|
);
|
2007-03-17 02:11:45 +03:00
|
|
|
|
2004-03-26 23:03:38 +03:00
|
|
|
if ( MPI_PARAM_CHECK ) {
|
2004-06-23 00:21:35 +04:00
|
|
|
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
|
2004-03-26 23:03:38 +03:00
|
|
|
|
2006-05-18 22:05:46 +04:00
|
|
|
if ( ompi_comm_invalid ( local_comm ) ||
|
2004-06-07 19:33:53 +04:00
|
|
|
( local_comm->c_flags & OMPI_COMM_INTER ) )
|
|
|
|
return OMPI_ERRHANDLER_INVOKE ( MPI_COMM_WORLD, MPI_ERR_COMM,
|
2004-06-23 00:21:35 +04:00
|
|
|
FUNC_NAME);
|
2004-03-26 23:03:38 +03:00
|
|
|
|
|
|
|
if ( NULL == newintercomm )
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE ( local_comm, MPI_ERR_ARG,
|
2004-06-23 00:21:35 +04:00
|
|
|
FUNC_NAME);
|
2004-03-26 23:03:38 +03:00
|
|
|
|
2004-08-04 02:08:23 +04:00
|
|
|
/* if ( tag < 0 || tag > MPI_TAG_UB )
|
|
|
|
return OMPI_ERRHANDLER_INVOKE ( local_comm, MPI_ERR_ARG,
|
|
|
|
FUNC_NAME);
|
|
|
|
*/
|
2004-03-26 23:03:38 +03:00
|
|
|
}
|
2008-02-20 01:15:52 +03:00
|
|
|
|
|
|
|
OPAL_CR_ENTER_LIBRARY();
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
local_size = ompi_comm_size ( local_comm );
|
|
|
|
local_rank = ompi_comm_rank ( local_comm );
|
2004-08-04 02:08:23 +04:00
|
|
|
lleader = local_leader;
|
|
|
|
rleader = remote_leader;
|
2004-03-26 23:03:38 +03:00
|
|
|
|
|
|
|
if ( MPI_PARAM_CHECK ) {
|
2005-01-29 06:01:28 +03:00
|
|
|
if ( (0 > local_leader) || (local_leader >= local_size) )
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE ( local_comm, MPI_ERR_ARG,
|
2004-06-23 00:21:35 +04:00
|
|
|
FUNC_NAME);
|
2004-03-26 23:03:38 +03:00
|
|
|
|
|
|
|
/* remember that the remote_leader and bridge_comm arguments
|
|
|
|
just have to be valid at the local_leader */
|
|
|
|
if ( local_rank == local_leader ) {
|
2006-05-18 22:05:46 +04:00
|
|
|
if ( ompi_comm_invalid ( bridge_comm ) ||
|
2005-01-29 06:01:28 +03:00
|
|
|
(bridge_comm->c_flags & OMPI_COMM_INTER) ) {
|
2008-02-20 01:15:52 +03:00
|
|
|
OPAL_CR_EXIT_LIBRARY();
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE ( local_comm, MPI_ERR_COMM,
|
2004-06-23 00:21:35 +04:00
|
|
|
FUNC_NAME);
|
2004-05-21 23:32:18 +04:00
|
|
|
}
|
2005-01-29 06:32:15 +03:00
|
|
|
if ( (remote_leader < 0) || (remote_leader >= ompi_comm_size(bridge_comm))) {
|
2008-02-20 01:15:52 +03:00
|
|
|
OPAL_CR_EXIT_LIBRARY();
|
2005-01-29 06:32:15 +03:00
|
|
|
return OMPI_ERRHANDLER_INVOKE ( local_comm, MPI_ERR_ARG,
|
|
|
|
FUNC_NAME);
|
|
|
|
}
|
2004-03-26 23:03:38 +03:00
|
|
|
} /* if ( local_rank == local_leader ) */
|
|
|
|
}
|
|
|
|
|
2004-05-21 23:32:18 +04:00
|
|
|
if ( local_rank == local_leader ) {
|
|
|
|
MPI_Request req;
|
|
|
|
|
2004-08-04 02:08:23 +04:00
|
|
|
/* local leader exchange group sizes lists */
|
2005-04-13 07:19:48 +04:00
|
|
|
rc = MCA_PML_CALL(irecv(&rsize, 1, MPI_INT, rleader, tag, bridge_comm,
|
|
|
|
&req));
|
2004-05-21 23:32:18 +04:00
|
|
|
if ( rc != MPI_SUCCESS ) {
|
|
|
|
goto err_exit;
|
|
|
|
}
|
2005-04-13 07:19:48 +04:00
|
|
|
rc = MCA_PML_CALL(send (&local_size, 1, MPI_INT, rleader, tag,
|
|
|
|
MCA_PML_BASE_SEND_STANDARD, bridge_comm));
|
2004-05-21 23:32:18 +04:00
|
|
|
if ( rc != MPI_SUCCESS ) {
|
|
|
|
goto err_exit;
|
|
|
|
}
|
2004-10-12 19:50:01 +04:00
|
|
|
rc = ompi_request_wait_all ( 1, &req, MPI_STATUS_IGNORE);
|
2004-05-21 23:32:18 +04:00
|
|
|
if ( rc != MPI_SUCCESS ) {
|
|
|
|
goto err_exit;
|
|
|
|
}
|
|
|
|
}
|
2004-08-04 02:08:23 +04:00
|
|
|
|
|
|
|
/* bcast size and list of remote processes to all processes in local_comm */
|
2004-08-06 02:51:34 +04:00
|
|
|
rc = local_comm->c_coll.coll_bcast ( &rsize, 1, MPI_INT, lleader,
|
2007-08-19 07:37:49 +04:00
|
|
|
local_comm,
|
|
|
|
local_comm->c_coll.coll_bcast_module);
|
2004-05-21 23:32:18 +04:00
|
|
|
if ( rc != MPI_SUCCESS ) {
|
|
|
|
goto err_exit;
|
|
|
|
}
|
|
|
|
|
2004-08-06 02:51:34 +04:00
|
|
|
rprocs = ompi_comm_get_rprocs ( local_comm, bridge_comm, lleader,
|
2004-05-21 23:32:18 +04:00
|
|
|
remote_leader, tag, rsize );
|
2004-08-04 02:08:23 +04:00
|
|
|
if ( NULL == rprocs ) {
|
|
|
|
goto err_exit;
|
|
|
|
}
|
|
|
|
|
2005-02-09 18:43:17 +03:00
|
|
|
if ( MPI_PARAM_CHECK ) {
|
2007-08-04 04:41:26 +04:00
|
|
|
if(OMPI_GROUP_IS_DENSE(local_comm->c_local_group)) {
|
2007-09-13 18:00:59 +04:00
|
|
|
rc = ompi_comm_overlapping_groups(local_comm->c_local_group->grp_proc_count,
|
|
|
|
local_comm->c_local_group->grp_proc_pointers,
|
|
|
|
rsize,
|
|
|
|
rprocs);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
proc_list = (ompi_proc_t **) calloc (local_comm->c_local_group->grp_proc_count,
|
|
|
|
sizeof (ompi_proc_t *));
|
|
|
|
for(j=0 ; j<local_comm->c_local_group->grp_proc_count ; j++) {
|
|
|
|
proc_list[j] = ompi_group_peer_lookup(local_comm->c_local_group,j);
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
2007-09-13 18:00:59 +04:00
|
|
|
rc = ompi_comm_overlapping_groups(local_comm->c_local_group->grp_proc_count,
|
|
|
|
proc_list,
|
|
|
|
rsize,
|
|
|
|
rprocs);
|
|
|
|
}
|
|
|
|
if ( OMPI_SUCCESS != rc ) {
|
|
|
|
goto err_exit;
|
|
|
|
}
|
2005-02-09 18:43:17 +03:00
|
|
|
}
|
2007-08-04 04:41:26 +04:00
|
|
|
new_group_pointer=ompi_group_allocate(rsize);
|
|
|
|
if( NULL == new_group_pointer ) {
|
2008-02-20 01:15:52 +03:00
|
|
|
OPAL_CR_EXIT_LIBRARY();
|
|
|
|
return MPI_ERR_GROUP;
|
2007-08-04 04:41:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* put group elements in the list */
|
|
|
|
for (j = 0; j < rsize; j++) {
|
|
|
|
new_group_pointer->grp_proc_pointers[j] = rprocs[j];
|
|
|
|
}
|
|
|
|
|
|
|
|
ompi_group_increment_proc_count(new_group_pointer);
|
|
|
|
|
|
|
|
rc = ompi_comm_set ( &newcomp, /* new comm */
|
|
|
|
local_comm, /* old comm */
|
|
|
|
local_comm->c_local_group->grp_proc_count, /* local_size */
|
|
|
|
NULL, /* local_procs*/
|
|
|
|
rsize, /* remote_size */
|
|
|
|
NULL, /* remote_procs */
|
|
|
|
NULL, /* attrs */
|
|
|
|
local_comm->error_handler, /* error handler*/
|
|
|
|
NULL, /* topo mpodule */
|
2007-09-13 18:00:59 +04:00
|
|
|
local_comm->c_local_group, /* local group */
|
|
|
|
new_group_pointer /* remote group */
|
2007-08-04 04:41:26 +04:00
|
|
|
);
|
2005-02-09 18:43:17 +03:00
|
|
|
|
2004-08-04 02:08:23 +04:00
|
|
|
if ( NULL == newcomp ) {
|
|
|
|
rc = MPI_ERR_INTERN;
|
|
|
|
goto err_exit;
|
2004-05-21 23:32:18 +04:00
|
|
|
}
|
2007-08-04 04:41:26 +04:00
|
|
|
if ( MPI_SUCCESS != rc ) {
|
|
|
|
goto err_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
ompi_group_decrement_proc_count (new_group_pointer);
|
|
|
|
OBJ_RELEASE(new_group_pointer);
|
|
|
|
new_group_pointer = MPI_GROUP_NULL;
|
2004-05-21 23:32:18 +04:00
|
|
|
|
2004-06-16 19:41:36 +04:00
|
|
|
/* Determine context id. It is identical to f_2_c_handle */
|
2004-06-17 02:44:56 +04:00
|
|
|
rc = ompi_comm_nextcid ( newcomp, /* new comm */
|
|
|
|
local_comm, /* old comm */
|
|
|
|
bridge_comm, /* bridge comm */
|
2004-08-04 02:08:23 +04:00
|
|
|
&lleader, /* local leader */
|
|
|
|
&rleader, /* remote_leader */
|
2004-08-05 20:32:13 +04:00
|
|
|
OMPI_COMM_CID_INTRA_BRIDGE, /* mode */
|
|
|
|
-1 ); /* send_first */
|
|
|
|
|
2004-08-04 02:08:23 +04:00
|
|
|
if ( MPI_SUCCESS != rc ) {
|
|
|
|
goto err_exit;
|
|
|
|
}
|
|
|
|
|
2004-08-05 20:32:13 +04:00
|
|
|
/* activate comm and init coll-module */
|
so here is what happens:
in the v1.2 series the cid's could never go above the max. allowed for a
particular pml. Because of that, pml_add_comm never checked for the cid, and
in fact pml_add_comm was called in comm_set, which is *before* we knew the
cid.
in the v1.3 series (and trunk) we check now the cid to detect overflow, and
because of that pml_add_comm has been moved *after* the cid allocation
routine, namely into the comm_activate routine.
in the v1.2 series, the comm_activate contained a synchronization step of the
old communicator in order to prevent incoming fragments on the new
communicator, with the main problem being that the allreduce in the
communicator allocation finished at different times on different processes,
and thus, this scenario could and did really occur.
in the v1.3 series, the comm_activate does not contain the synchronization
step anymore, since we introduced the new queue for fragments with unknown
cid. The problem is however, that whether a fragment is known or not is
decided by using ompi_comm_lookup(), which will return something useful as
soon as the cid allocation finished, even before pml_add_comm has been
called. So there is a small time gap where we will not post a message into
queue for unknown cid's, but we can also not look up the process structure
belonging to the rank in that comm ( that is in pml_ob1_match_recv_frag or
something like that).
The current fix reintroduces the synchronization step in comm_activate, and
ensures that no fragment can be received for a new communicator before the
synchronization occurs , and thus comm_nextcid() and pml_add_comm has been
called. It seems to be the safest and easiest way for now. Welcome back, v1.2.
This commit was SVN r21970.
2009-09-17 18:37:02 +04:00
|
|
|
rc = ompi_comm_activate ( &newcomp,
|
|
|
|
local_comm, /* old comm */
|
|
|
|
bridge_comm, /* bridge comm */
|
|
|
|
&lleader, /* local leader */
|
|
|
|
&rleader, /* remote_leader */
|
|
|
|
OMPI_COMM_CID_INTRA_BRIDGE, /* mode */
|
|
|
|
-1 ); /* send_first */
|
2004-08-05 20:32:13 +04:00
|
|
|
if ( MPI_SUCCESS != rc ) {
|
|
|
|
goto err_exit;
|
|
|
|
}
|
2008-11-05 00:58:06 +03:00
|
|
|
|
2004-05-21 23:32:18 +04:00
|
|
|
err_exit:
|
2008-02-20 01:15:52 +03:00
|
|
|
OPAL_CR_EXIT_LIBRARY();
|
|
|
|
|
2004-08-06 02:51:34 +04:00
|
|
|
if ( NULL != rprocs ) {
|
2004-05-21 23:32:18 +04:00
|
|
|
free ( rprocs );
|
|
|
|
}
|
2007-08-04 04:41:26 +04:00
|
|
|
if ( NULL != proc_list ) {
|
|
|
|
free ( proc_list );
|
|
|
|
}
|
2004-06-16 19:41:36 +04:00
|
|
|
if ( OMPI_SUCCESS != rc ) {
|
|
|
|
*newintercomm = MPI_COMM_NULL;
|
|
|
|
return OMPI_ERRHANDLER_INVOKE(local_comm, MPI_ERR_INTERN,
|
2004-06-23 00:21:35 +04:00
|
|
|
FUNC_NAME);
|
2004-06-16 19:41:36 +04:00
|
|
|
}
|
2004-05-21 23:32:18 +04:00
|
|
|
|
|
|
|
*newintercomm = newcomp;
|
2004-01-26 01:07:54 +03:00
|
|
|
return MPI_SUCCESS;
|
|
|
|
}
|
2008-11-05 00:58:06 +03:00
|
|
|
|