root/ompi/mpi/c/comm_spawn.c

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

DEFINITIONS

This source file includes following definitions.
  1. MPI_Comm_spawn

   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-2005 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-2015 Cisco Systems, Inc.  All rights reserved.
  14  * Copyright (c) 2009      Sun Microsystems, Inc.  All rights reserved.
  15  * Copyright (c) 2013      Los Alamos National Security, LLC.  All rights
  16  *                         reserved.
  17  * Copyright (c) 2015      Intel, Inc. All rights reserved.
  18  * Copyright (c) 2015      Research Organization for Information Science
  19  *                         and Technology (RIST). All rights reserved.
  20  * $COPYRIGHT$
  21  *
  22  * Additional copyrights may follow
  23  *
  24  * $HEADER$
  25  */
  26 #include "ompi_config.h"
  27 #include <stdio.h>
  28 
  29 #include "opal/util/show_help.h"
  30 
  31 #include "ompi/info/info.h"
  32 #include "ompi/mpi/c/bindings.h"
  33 #include "ompi/runtime/params.h"
  34 #include "ompi/runtime/mpiruntime.h"
  35 #include "ompi/communicator/communicator.h"
  36 #include "ompi/errhandler/errhandler.h"
  37 #include "ompi/dpm/dpm.h"
  38 #include "ompi/memchecker.h"
  39 
  40 #if OMPI_BUILD_MPI_PROFILING
  41 #if OPAL_HAVE_WEAK_SYMBOLS
  42 #pragma weak MPI_Comm_spawn = PMPI_Comm_spawn
  43 #endif
  44 #define MPI_Comm_spawn PMPI_Comm_spawn
  45 #endif
  46 
  47 static const char FUNC_NAME[] = "MPI_Comm_spawn";
  48 
  49 
  50 int MPI_Comm_spawn(const char *command, char *argv[], int maxprocs, MPI_Info info,
  51                    int root, MPI_Comm comm, MPI_Comm *intercomm,
  52                    int array_of_errcodes[])
  53 {
  54     int rank, rc=OMPI_SUCCESS, i, flag;
  55     bool send_first = false; /* we wait to be contacted */
  56     ompi_communicator_t *newcomp=NULL;
  57     char port_name[MPI_MAX_PORT_NAME];
  58     bool non_mpi = false;
  59 
  60     MEMCHECKER(
  61         memchecker_comm(comm);
  62     );
  63 
  64     if ( MPI_PARAM_CHECK ) {
  65         OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
  66 
  67         if ( ompi_comm_invalid (comm)) {
  68             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM,
  69                                           FUNC_NAME);
  70         }
  71         if ( OMPI_COMM_IS_INTER(comm)) {
  72             return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COMM,
  73                                           FUNC_NAME);
  74         }
  75         if ( (0 > root) || (ompi_comm_size(comm) <= root) ) {
  76             return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG,
  77                                           FUNC_NAME);
  78         }
  79         if ( NULL == intercomm ) {
  80             return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG,
  81                                           FUNC_NAME);
  82         }
  83     }
  84 
  85     rank = ompi_comm_rank ( comm );
  86     if ( MPI_PARAM_CHECK ) {
  87         if ( rank == root ) {
  88             if ( NULL == command ) {
  89                 return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG,
  90                                               FUNC_NAME);
  91             }
  92             if ( 0 > maxprocs ) {
  93                 return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG,
  94                                               FUNC_NAME);
  95             }
  96             if (NULL == info || ompi_info_is_freed(info)) {
  97                 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_INFO,
  98                                               FUNC_NAME);
  99             }
 100         }
 101     }
 102 
 103     if (!ompi_mpi_dynamics_is_enabled(FUNC_NAME)) {
 104         return OMPI_ERRHANDLER_INVOKE(comm, OMPI_ERR_NOT_SUPPORTED, FUNC_NAME);
 105     }
 106 
 107     /* initialize the port name to avoid problems */
 108     memset(port_name, 0, MPI_MAX_PORT_NAME);
 109 
 110     /* See if the info key "ompi_non_mpi" was set to true */
 111     if (rank == root) {
 112         ompi_info_get_bool(info, "ompi_non_mpi", &non_mpi, &flag);
 113     }
 114 
 115     OPAL_CR_ENTER_LIBRARY();
 116 
 117     if ( rank == root ) {
 118         if (!non_mpi) {
 119             /* Open a port. The port_name is passed as an environment
 120                variable to the children. */
 121             if (OMPI_SUCCESS != (rc = ompi_dpm_open_port (port_name))) {
 122                 goto error;
 123             }
 124         } else if (1 < ompi_comm_size(comm)) {
 125             /* we do not support non_mpi spawns on comms this size */
 126             rc = OMPI_ERR_NOT_SUPPORTED;
 127             goto error;
 128         }
 129         if (OMPI_SUCCESS != (rc = ompi_dpm_spawn (1, &command, &argv, &maxprocs,
 130                                                   &info, port_name))) {
 131             goto error;
 132         }
 133     }
 134 
 135     if (non_mpi) {
 136         newcomp = MPI_COMM_NULL;
 137     } else {
 138         rc = ompi_dpm_connect_accept (comm, root, port_name, send_first, &newcomp);
 139     }
 140 
 141 error:
 142     if (OPAL_ERR_NOT_SUPPORTED == rc) {
 143         opal_show_help("help-mpi-api.txt",
 144                        "MPI function not supported",
 145                        true,
 146                        FUNC_NAME,
 147                        "Underlying runtime environment does not support spawn functionality");
 148     }
 149 
 150     /* close the port */
 151     if (rank == root && !non_mpi) {
 152         ompi_dpm_close_port(port_name);
 153     }
 154 
 155     OPAL_CR_EXIT_LIBRARY();
 156 
 157     /* set error codes */
 158     if (MPI_ERRCODES_IGNORE != array_of_errcodes) {
 159         for ( i=0; i < maxprocs; i++ ) {
 160             array_of_errcodes[i]=rc;
 161         }
 162     }
 163 
 164     *intercomm = newcomp;
 165     OMPI_ERRHANDLER_RETURN (rc, comm, rc, FUNC_NAME);
 166 }

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