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.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* 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 University of Houston. All rights reserved.
|
|
|
|
* Copyright (c) 2006-2007 Cisco Systems, Inc. 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"
|
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 11:46:27 +03:00
|
|
|
#include "ompi/include/ompi/memchecker.h"
|
2004-01-26 01:07:54 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#if OMPI_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
|
|
|
OPAL_CR_TEST_CHECKPOINT_READY();
|
|
|
|
|
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
|
|
|
}
|
2004-05-21 23:32:18 +04:00
|
|
|
|
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) ) {
|
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))) {
|
|
|
|
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 ) {
|
|
|
|
return MPI_ERR_GROUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
rc = ompi_comm_activate ( newcomp, /* new comm */
|
|
|
|
local_comm, /* old comm */
|
|
|
|
bridge_comm, /* bridge comm */
|
|
|
|
&lleader, /* local leader */
|
|
|
|
&rleader, /* remote_leader */
|
|
|
|
OMPI_COMM_CID_INTRA_BRIDGE, /* mode */
|
|
|
|
-1, /* send_first */
|
2007-09-13 18:00:59 +04:00
|
|
|
0); /* sync_flag */
|
2004-08-05 20:32:13 +04:00
|
|
|
|
|
|
|
if ( MPI_SUCCESS != rc ) {
|
|
|
|
goto err_exit;
|
|
|
|
}
|
2004-08-04 02:08:23 +04:00
|
|
|
|
2004-05-21 23:32:18 +04:00
|
|
|
err_exit:
|
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;
|
|
|
|
}
|