2004-01-26 01:07:54 +03:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* 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.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* 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.
|
2006-05-18 22:05:46 +04:00
|
|
|
* Copyright (c) 2006 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-11-05 10:52:30 +03:00
|
|
|
#include <string.h>
|
2005-09-12 13:17:44 +04: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/communicator/communicator.h"
|
|
|
|
#include "ompi/proc/proc.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
|
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-05-21 23:32:18 +04:00
|
|
|
#define INTERCOMM_MERGE_TAG 1010
|
2004-03-26 23:03:38 +03:00
|
|
|
|
2004-07-30 06:58:53 +04:00
|
|
|
static const char FUNC_NAME[] = "MPI_Intercomm_merge";
|
2004-06-23 00:21:35 +04:00
|
|
|
|
|
|
|
|
2004-05-21 23:32:18 +04:00
|
|
|
int MPI_Intercomm_merge(MPI_Comm intercomm, int high,
|
|
|
|
MPI_Comm *newcomm)
|
|
|
|
{
|
2004-08-04 23:48:03 +04:00
|
|
|
ompi_communicator_t *newcomp=MPI_COMM_NULL;
|
2004-06-07 19:33:53 +04:00
|
|
|
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-08-04 02:08:23 +04:00
|
|
|
int thigh = high;
|
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 ( intercomm ) ||
|
2004-06-07 19:33:53 +04:00
|
|
|
!( intercomm->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 == newcomm )
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE ( intercomm, MPI_ERR_ARG,
|
2004-06-23 00:21:35 +04:00
|
|
|
FUNC_NAME);
|
2004-03-26 23:03:38 +03:00
|
|
|
}
|
|
|
|
|
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-08-04 23:48:03 +04:00
|
|
|
rc = MPI_ERR_INTERN;
|
|
|
|
goto exit;
|
2004-05-21 23:32:18 +04:00
|
|
|
}
|
|
|
|
|
2004-08-04 02:08:23 +04:00
|
|
|
first = ompi_comm_determine_first ( intercomm, thigh );
|
2004-08-04 23:48:03 +04:00
|
|
|
if ( MPI_UNDEFINED == first ) {
|
|
|
|
rc = MPI_ERR_INTERN;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
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-08-04 02:08:23 +04:00
|
|
|
|
|
|
|
newcomp = ompi_comm_allocate ( total_size, 0 );
|
|
|
|
if ( NULL == newcomp ) {
|
|
|
|
rc = MPI_ERR_INTERN;
|
|
|
|
goto 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 */
|
|
|
|
intercomm, /* old comm */
|
|
|
|
NULL, /* bridge comm */
|
|
|
|
NULL, /* local leader */
|
|
|
|
NULL, /* remote_leader */
|
2004-08-05 20:32:13 +04:00
|
|
|
OMPI_COMM_CID_INTER, /* mode */
|
|
|
|
-1 ); /* send_first */
|
2004-06-16 19:41:36 +04:00
|
|
|
if ( OMPI_SUCCESS != rc ) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2004-08-04 02:08:23 +04:00
|
|
|
rc = ompi_comm_set ( newcomp, /* new comm */
|
|
|
|
intercomm, /* old comm */
|
|
|
|
total_size, /* local_size */
|
|
|
|
procs, /* local_procs*/
|
|
|
|
0, /* remote_size */
|
|
|
|
NULL, /* remote_procs */
|
|
|
|
NULL, /* attrs */
|
|
|
|
intercomm->error_handler, /* error handler*/
|
|
|
|
NULL /* topo mpodule */
|
|
|
|
);
|
|
|
|
if ( MPI_SUCCESS != rc ) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2004-08-05 20:32:13 +04:00
|
|
|
|
|
|
|
/* activate communicator and init coll-module */
|
|
|
|
rc = ompi_comm_activate ( newcomp, /* new comm */
|
|
|
|
intercomm, /* old comm */
|
|
|
|
NULL, /* bridge comm */
|
|
|
|
NULL, /* local leader */
|
|
|
|
NULL, /* remote_leader */
|
|
|
|
OMPI_COMM_CID_INTER, /* mode */
|
|
|
|
-1, /* send_first */
|
|
|
|
NULL ); /* coll module */
|
|
|
|
if ( OMPI_SUCCESS != rc ) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2004-08-04 02:08:23 +04:00
|
|
|
|
|
|
|
|
2004-06-16 19:41:36 +04:00
|
|
|
exit:
|
2004-05-21 23:32:18 +04:00
|
|
|
if ( NULL != procs ) {
|
|
|
|
free ( procs );
|
|
|
|
}
|
2004-08-04 02:08:23 +04:00
|
|
|
if ( MPI_SUCCESS != rc ) {
|
2004-08-04 23:48:03 +04:00
|
|
|
if ( MPI_COMM_NULL != newcomp ) {
|
|
|
|
OBJ_RELEASE(newcomp);
|
|
|
|
}
|
2004-06-16 19:41:36 +04:00
|
|
|
*newcomm = MPI_COMM_NULL;
|
2004-08-04 02:08:23 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(intercomm, rc, FUNC_NAME);
|
2004-06-16 19:41:36 +04:00
|
|
|
}
|
2004-05-21 23:32:18 +04:00
|
|
|
|
|
|
|
*newcomm = newcomp;
|
2004-01-26 01:07:54 +03:00
|
|
|
return MPI_SUCCESS;
|
|
|
|
}
|