2004-01-26 01:07:54 +03:00
|
|
|
/*
|
2004-11-22 04:38:40 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
|
|
|
* 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.
|
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
|
|
|
|
|
|
|
#include "mpi.h"
|
2004-03-17 21:45:16 +03:00
|
|
|
#include "mpi/c/bindings.h"
|
2004-05-21 23:32:18 +04:00
|
|
|
#include "mca/pml/pml.h"
|
2004-03-26 23:03:38 +03:00
|
|
|
#include "communicator/communicator.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
|
2004-04-20 22:50:43 +04:00
|
|
|
#include "mpi/c/profile/defines.h"
|
|
|
|
#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;
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_proc_t **rprocs=NULL;
|
2004-12-06 05:15:34 +03:00
|
|
|
int rc=0, rsize=0;
|
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
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
if ( MPI_COMM_NULL == local_comm || ompi_comm_invalid ( local_comm ) ||
|
|
|
|
( 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 ) {
|
2005-01-29 06:01:28 +03:00
|
|
|
if ( (MPI_COMM_NULL == bridge_comm) || ompi_comm_invalid ( bridge_comm ) ||
|
|
|
|
(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 */
|
2004-08-06 02:51:34 +04:00
|
|
|
rc =mca_pml.pml_irecv (&rsize, 1, MPI_INT, rleader, tag, bridge_comm,
|
2004-05-21 23:32:18 +04:00
|
|
|
&req );
|
|
|
|
if ( rc != MPI_SUCCESS ) {
|
|
|
|
goto err_exit;
|
|
|
|
}
|
2004-08-06 02:51:34 +04:00
|
|
|
rc = mca_pml.pml_send ( &local_size, 1, MPI_INT, rleader, tag,
|
2004-05-21 23:32:18 +04:00
|
|
|
MCA_PML_BASE_SEND_STANDARD, bridge_comm );
|
|
|
|
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,
|
2004-06-29 04:02:25 +04:00
|
|
|
local_comm );
|
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 ) {
|
|
|
|
rc = ompi_comm_overlapping_groups(local_comm->c_local_group->grp_proc_count,
|
|
|
|
local_comm->c_local_group->grp_proc_pointers,
|
|
|
|
rsize,
|
|
|
|
rprocs);
|
|
|
|
if ( OMPI_SUCCESS != rc ) {
|
|
|
|
goto err_exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-04 02:08:23 +04:00
|
|
|
newcomp = ompi_comm_allocate ( local_comm->c_local_group->grp_proc_count, rsize);
|
|
|
|
if ( NULL == newcomp ) {
|
|
|
|
rc = MPI_ERR_INTERN;
|
|
|
|
goto err_exit;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = ompi_comm_set ( newcomp, /* new comm */
|
|
|
|
local_comm, /* old comm */
|
|
|
|
local_comm->c_local_group->grp_proc_count, /* local_size */
|
|
|
|
local_comm->c_local_group->grp_proc_pointers, /* local_procs*/
|
|
|
|
rsize, /* remote_size */
|
|
|
|
rprocs, /* remote_procs */
|
|
|
|
NULL, /* attrs */
|
|
|
|
local_comm->error_handler, /* error handler*/
|
|
|
|
NULL /* topo mpodule */
|
|
|
|
);
|
|
|
|
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 */
|
|
|
|
NULL ); /* coll component */
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
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;
|
|
|
|
}
|