root/ompi/mpi/c/intercomm_merge.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. MPI_Intercomm_merge

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2013 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2006-2012 Cisco Systems, Inc.  All rights reserved.
  14  * Copyright (c) 2006-2009 University of Houston.  All rights reserved.
  15  * Copyright (c) 2012-2013 Inria.  All rights reserved.
  16  * Copyright (c) 2015      Research Organization for Information Science
  17  *                         and Technology (RIST). All rights reserved.
  18  * Copyright (c) 2016      Los Alamos National Security, LLC. All rights
  19  *                         reserved.
  20  * $COPYRIGHT$
  21  *
  22  * Additional copyrights may follow
  23  *
  24  * $HEADER$
  25  */
  26 
  27 #include "ompi_config.h"
  28 #include <string.h>
  29 
  30 #include "ompi/mpi/c/bindings.h"
  31 #include "ompi/runtime/params.h"
  32 #include "ompi/errhandler/errhandler.h"
  33 #include "ompi/communicator/communicator.h"
  34 #include "ompi/proc/proc.h"
  35 #include "ompi/memchecker.h"
  36 
  37 #if OMPI_BUILD_MPI_PROFILING
  38 #if OPAL_HAVE_WEAK_SYMBOLS
  39 #pragma weak MPI_Intercomm_merge = PMPI_Intercomm_merge
  40 #endif
  41 #define MPI_Intercomm_merge PMPI_Intercomm_merge
  42 #endif
  43 
  44 static const char FUNC_NAME[] = "MPI_Intercomm_merge";
  45 
  46 
  47 int MPI_Intercomm_merge(MPI_Comm intercomm, int high,
  48                         MPI_Comm *newcomm)
  49 {
  50     ompi_communicator_t *newcomp=MPI_COMM_NULL;
  51     ompi_proc_t **procs=NULL;
  52     int local_size, remote_size;
  53     int first;
  54     int total_size;
  55     int rc=MPI_SUCCESS;
  56     int thigh = high;
  57     ompi_group_t *new_group_pointer;
  58 
  59     MEMCHECKER(
  60         memchecker_comm(intercomm);
  61     );
  62 
  63     if ( MPI_PARAM_CHECK ) {
  64         OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
  65 
  66         if (ompi_comm_invalid ( intercomm ) ||
  67              !( intercomm->c_flags & OMPI_COMM_INTER ) )
  68             return OMPI_ERRHANDLER_INVOKE ( MPI_COMM_WORLD, MPI_ERR_COMM,
  69                                             FUNC_NAME);
  70 
  71         if ( NULL == newcomm )
  72             return OMPI_ERRHANDLER_INVOKE ( intercomm, MPI_ERR_ARG,
  73                                             FUNC_NAME);
  74     }
  75 
  76     OPAL_CR_ENTER_LIBRARY();
  77 
  78     local_size  = ompi_comm_size ( intercomm );
  79     remote_size = ompi_comm_remote_size ( intercomm );
  80     total_size  = local_size + remote_size;
  81     procs = (ompi_proc_t **) malloc ( total_size * sizeof(ompi_proc_t *));
  82     if ( NULL == procs ) {
  83         rc = MPI_ERR_INTERN;
  84         goto exit;
  85     }
  86 
  87     first = ompi_comm_determine_first ( intercomm, thigh );
  88     if ( MPI_UNDEFINED == first ) {
  89         rc = MPI_ERR_INTERN;
  90         goto exit;
  91     }
  92 
  93     if ( first ) {
  94         ompi_group_union ( intercomm->c_local_group, intercomm->c_remote_group, &new_group_pointer );
  95     }
  96     else {
  97         ompi_group_union ( intercomm->c_remote_group, intercomm->c_local_group, &new_group_pointer );
  98     }
  99 
 100     rc = ompi_comm_set ( &newcomp,                 /* new comm */
 101                          intercomm,                /* old comm */
 102                          total_size,               /* local_size */
 103                          NULL,                     /* local_procs*/
 104                          0,                        /* remote_size */
 105                          NULL,                     /* remote_procs */
 106                          NULL,                     /* attrs */
 107                          intercomm->error_handler, /* error handler*/
 108                          false,                    /* don't copy the topo */
 109                          new_group_pointer,        /* local group */
 110                          NULL                      /* remote group */
 111                          );
 112     if ( MPI_SUCCESS != rc ) {
 113         goto exit;
 114     }
 115 
 116     OBJ_RELEASE(new_group_pointer);
 117     new_group_pointer = MPI_GROUP_NULL;
 118 
 119     /* Determine context id */
 120     rc = ompi_comm_nextcid (newcomp, intercomm, NULL, NULL, NULL, false,
 121                             OMPI_COMM_CID_INTER);
 122     if ( OMPI_SUCCESS != rc ) {
 123         goto exit;
 124     }
 125 
 126     /* activate communicator and init coll-module */
 127     rc = ompi_comm_activate (&newcomp, intercomm, NULL, NULL, NULL, false,
 128                              OMPI_COMM_CID_INTER);
 129     if ( OMPI_SUCCESS != rc ) {
 130         goto exit;
 131     }
 132 
 133  exit:
 134     OPAL_CR_EXIT_LIBRARY();
 135 
 136     if ( NULL != procs ) {
 137         free ( procs );
 138     }
 139     if ( MPI_SUCCESS != rc ) {
 140         if ( MPI_COMM_NULL != newcomp && NULL != newcomp ) {
 141             OBJ_RELEASE(newcomp);
 142         }
 143         *newcomm = MPI_COMM_NULL;
 144         return OMPI_ERRHANDLER_INVOKE(intercomm, rc,  FUNC_NAME);
 145     }
 146 
 147     *newcomm = newcomp;
 148     return MPI_SUCCESS;
 149 }
 150 

/* [<][>][^][v][top][bottom][index][help] */