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-03-26 23:03:38 +03:00
|
|
|
#include "runtime/runtime.h"
|
|
|
|
#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_merge = PMPI_Intercomm_merge
|
|
|
|
#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-05-21 23:32:18 +04:00
|
|
|
#define INTERCOMM_MERGE_TAG 1010
|
2004-03-26 23:03:38 +03:00
|
|
|
|
2004-05-21 23:32:18 +04:00
|
|
|
int MPI_Intercomm_merge(MPI_Comm intercomm, int high,
|
|
|
|
MPI_Comm *newcomm)
|
|
|
|
{
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_communicator_t *newcomp;
|
|
|
|
ompi_proc_t **procs=NULL;
|
2004-05-21 23:32:18 +04:00
|
|
|
int local_size, remote_size;
|
|
|
|
int local_rank;
|
|
|
|
int first;
|
|
|
|
int total_size;
|
2004-06-16 19:41:36 +04:00
|
|
|
int rc=MPI_SUCCESS;
|
2004-03-26 23:03:38 +03:00
|
|
|
|
|
|
|
if ( MPI_PARAM_CHECK ) {
|
2004-06-18 23:02:52 +04:00
|
|
|
OMPI_ERR_INIT_FINALIZE;
|
2004-03-26 23:03:38 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
if ( MPI_COMM_NULL == intercomm || ompi_comm_invalid ( intercomm ) ||
|
|
|
|
!( intercomm->c_flags & OMPI_COMM_INTER ) )
|
|
|
|
return OMPI_ERRHANDLER_INVOKE ( MPI_COMM_WORLD, MPI_ERR_COMM,
|
2004-03-26 23:03:38 +03:00
|
|
|
"MPI_Intercomm_merge");
|
|
|
|
|
|
|
|
if ( NULL == newcomm )
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE ( intercomm, MPI_ERR_ARG,
|
2004-03-26 23:03:38 +03:00
|
|
|
"MPI_Intercomm_merge");
|
|
|
|
}
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
local_size = ompi_comm_size ( intercomm );
|
|
|
|
local_rank = ompi_comm_rank ( intercomm );
|
|
|
|
remote_size = ompi_comm_remote_size ( intercomm );
|
2004-05-21 23:32:18 +04:00
|
|
|
total_size = local_size + remote_size;
|
2004-06-07 19:33:53 +04:00
|
|
|
procs = (ompi_proc_t **) malloc ( total_size * sizeof(ompi_proc_t *));
|
2004-05-21 23:32:18 +04:00
|
|
|
if ( NULL == procs ) {
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(intercomm,MPI_ERR_INTERN, "MPI_Intercomm_merge");
|
2004-05-21 23:32:18 +04:00
|
|
|
}
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
first = ompi_comm_determine_first ( intercomm, high );
|
2004-05-21 23:32:18 +04:00
|
|
|
if ( first ) {
|
|
|
|
memcpy ( procs, intercomm->c_local_group->grp_proc_pointers,
|
2004-06-07 19:33:53 +04:00
|
|
|
local_size * sizeof(ompi_proc_t *));
|
2004-05-21 23:32:18 +04:00
|
|
|
memcpy ( &procs[local_size], intercomm->c_remote_group->grp_proc_pointers,
|
2004-06-07 19:33:53 +04:00
|
|
|
remote_size * sizeof(ompi_proc_t *));
|
2004-05-21 23:32:18 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
memcpy ( procs, intercomm->c_remote_group->grp_proc_pointers,
|
2004-06-07 19:33:53 +04:00
|
|
|
remote_size * sizeof(ompi_proc_t *));
|
2004-05-21 23:32:18 +04:00
|
|
|
memcpy ( &procs[remote_size], intercomm->c_local_group->grp_proc_pointers,
|
2004-06-07 19:33:53 +04:00
|
|
|
local_size * sizeof(ompi_proc_t *));
|
2004-05-21 23:32:18 +04:00
|
|
|
}
|
|
|
|
|
2004-06-16 19:41:36 +04:00
|
|
|
newcomp = ompi_comm_set ( intercomm, /* old comm */
|
|
|
|
total_size, /* local_size */
|
|
|
|
procs, /* local_procs*/
|
|
|
|
0, /* remote_size */
|
|
|
|
NULL, /* remote_procs */
|
|
|
|
NULL, /* attrs */
|
|
|
|
intercomm->error_handler, /* error handler*/
|
|
|
|
NULL, /* coll module */
|
|
|
|
NULL /* topo mpodule */
|
|
|
|
);
|
2004-05-21 23:32:18 +04:00
|
|
|
|
|
|
|
if ( newcomp == MPI_COMM_NULL ) {
|
2004-06-16 19:41:36 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE (intercomm, MPI_ERR_INTERN,
|
|
|
|
"MPI_Intercomm_merge");
|
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 */
|
|
|
|
intercomm, /* old comm */
|
|
|
|
NULL, /* bridge comm */
|
|
|
|
NULL, /* local leader */
|
|
|
|
NULL, /* remote_leader */
|
|
|
|
OMPI_COMM_CID_INTER); /* mode */
|
2004-06-16 19:41:36 +04:00
|
|
|
if ( OMPI_SUCCESS != rc ) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
2004-05-21 23:32:18 +04:00
|
|
|
if ( NULL != procs ) {
|
|
|
|
free ( procs );
|
|
|
|
}
|
2004-06-16 19:41:36 +04:00
|
|
|
if ( OMPI_SUCCESS != rc ) {
|
|
|
|
*newcomm = MPI_COMM_NULL;
|
|
|
|
return OMPI_ERRHANDLER_INVOKE(intercomm, MPI_ERR_INTERN,
|
|
|
|
"MPI_Intercom_merge");
|
|
|
|
}
|
2004-05-21 23:32:18 +04:00
|
|
|
|
|
|
|
*newcomm = newcomp;
|
2004-01-26 01:07:54 +03:00
|
|
|
return MPI_SUCCESS;
|
|
|
|
}
|