root/ompi/mpi/c/publish_name.c

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

DEFINITIONS

This source file includes following definitions.
  1. MPI_Publish_name

   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-2005 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) 2013      Los Alamos National Security, LLC.  All rights
  14  *                         reserved.
  15  * Copyright (c) 2015-2016 Intel, Inc. All rights reserved.
  16  * Copyright (c) 2015      Research Organization for Information Science
  17  *                         and Technology (RIST). All rights reserved.
  18  * Copyright (c) 2015      Cisco Systems, Inc.  All rights reserved.
  19  * $COPYRIGHT$
  20  *
  21  * Additional copyrights may follow
  22  *
  23  * $HEADER$
  24  */
  25 #include "ompi_config.h"
  26 #include <stdio.h>
  27 
  28 #include "opal/class/opal_list.h"
  29 #include "opal/mca/pmix/pmix.h"
  30 #include "opal/util/show_help.h"
  31 
  32 #include "ompi/mpi/c/bindings.h"
  33 #include "ompi/runtime/params.h"
  34 #include "ompi/errhandler/errhandler.h"
  35 #include "ompi/info/info.h"
  36 #include "ompi/communicator/communicator.h"
  37 
  38 #if OMPI_BUILD_MPI_PROFILING
  39 #if OPAL_HAVE_WEAK_SYMBOLS
  40 #pragma weak MPI_Publish_name = PMPI_Publish_name
  41 #endif
  42 #define MPI_Publish_name PMPI_Publish_name
  43 #endif
  44 
  45 static const char FUNC_NAME[] = "MPI_Publish_name";
  46 
  47 
  48 int MPI_Publish_name(const char *service_name, MPI_Info info,
  49                      const char *port_name)
  50 {
  51     int rc;
  52     char range[OPAL_MAX_INFO_VAL];
  53     int flag=0;
  54     opal_value_t *rng;
  55     opal_list_t values;
  56 
  57     if ( MPI_PARAM_CHECK ) {
  58         OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
  59 
  60         if ( NULL == port_name || 0 == strlen(port_name) ) {
  61             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG,
  62                                           FUNC_NAME);
  63         }
  64         if ( NULL == service_name || 0 == strlen(service_name) ) {
  65             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG,
  66                                           FUNC_NAME);
  67         }
  68         if (NULL == info || ompi_info_is_freed(info)) {
  69             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_INFO,
  70                                           FUNC_NAME);
  71         }
  72     }
  73 
  74     if (NULL == opal_pmix.publish) {
  75         opal_show_help("help-mpi-api.txt",
  76                        "MPI function not supported",
  77                        true,
  78                        FUNC_NAME,
  79                        "Underlying runtime environment does not support name publishing functionality");
  80         return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD,
  81                                       OMPI_ERR_NOT_SUPPORTED,
  82                                         FUNC_NAME);
  83     }
  84 
  85     OPAL_CR_ENTER_LIBRARY();
  86     OBJ_CONSTRUCT(&values, opal_list_t);
  87 
  88     /* OMPI supports info keys to pass the range and persistence to
  89      * be used for the given key */
  90     if (MPI_INFO_NULL != info) {
  91         ompi_info_get (info, "range", sizeof(range) - 1, range, &flag);
  92         if (flag) {
  93             if (0 == strcmp(range, "nspace")) {
  94                 rng = OBJ_NEW(opal_value_t);
  95                 rng->key = strdup(OPAL_PMIX_RANGE);
  96                 rng->type = OPAL_INT;
  97                 rng->data.integer = OPAL_PMIX_RANGE_NAMESPACE;  // share only with procs in same nspace
  98                 opal_list_append(&values, &rng->super);
  99             } else if (0 == strcmp(range, "session")) {
 100                 rng = OBJ_NEW(opal_value_t);
 101                 rng->key = strdup(OPAL_PMIX_RANGE);
 102                 rng->type = OPAL_INT;
 103                 rng->data.integer = OPAL_PMIX_RANGE_SESSION; // share only with procs in same session
 104                 opal_list_append(&values, &rng->super);
 105             } else {
 106                 /* unrecognized scope */
 107                 OPAL_LIST_DESTRUCT(&values);
 108                 OPAL_CR_EXIT_LIBRARY();
 109                 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG,
 110                                             FUNC_NAME);
 111             }
 112         }
 113         ompi_info_get (info, "persistence", sizeof(range) - 1, range, &flag);
 114         if (flag) {
 115             if (0 == strcmp(range, "indef")) {
 116                 rng = OBJ_NEW(opal_value_t);
 117                 rng->key = strdup(OPAL_PMIX_PERSISTENCE);
 118                 rng->type = OPAL_INT;
 119                 rng->data.integer = OPAL_PMIX_PERSIST_INDEF;   // retain until specifically deleted
 120                 opal_list_append(&values, &rng->super);
 121             } else if (0 == strcmp(range, "proc")) {
 122                 rng = OBJ_NEW(opal_value_t);
 123                 rng->key = strdup(OPAL_PMIX_PERSISTENCE);
 124                 rng->type = OPAL_INT;
 125                 rng->data.integer = OPAL_PMIX_PERSIST_PROC;    // retain until publishing process terminates
 126                 opal_list_append(&values, &rng->super);
 127             } else if (0 == strcmp(range, "app")) {
 128                 rng = OBJ_NEW(opal_value_t);
 129                 rng->key = strdup(OPAL_PMIX_PERSISTENCE);
 130                 rng->type = OPAL_INT;
 131                 rng->data.integer = OPAL_PMIX_PERSIST_APP;     // retain until application terminates
 132                 opal_list_append(&values, &rng->super);
 133             } else if (0 == strcmp(range, "session")) {
 134                 rng = OBJ_NEW(opal_value_t);
 135                 rng->key = strdup(OPAL_PMIX_PERSISTENCE);
 136                 rng->type = OPAL_INT;
 137                 rng->data.integer = OPAL_PMIX_PERSIST_SESSION; // retain until session/allocation terminates
 138                 opal_list_append(&values, &rng->super);
 139             } else {
 140                 /* unrecognized persistence */
 141                 OPAL_LIST_DESTRUCT(&values);
 142                 OPAL_CR_EXIT_LIBRARY();
 143                 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG,
 144                                             FUNC_NAME);
 145             }
 146         }
 147     }
 148 
 149     /* publish the service name */
 150     rng = OBJ_NEW(opal_value_t);
 151     rng->key = strdup(service_name);
 152     rng->type = OPAL_STRING;
 153     rng->data.string = strdup(port_name);
 154     opal_list_append(&values, &rng->super);
 155 
 156     rc = opal_pmix.publish(&values);
 157     OPAL_LIST_DESTRUCT(&values);
 158 
 159     OPAL_CR_EXIT_LIBRARY();
 160     if ( OPAL_SUCCESS != rc ) {
 161         if (OPAL_EXISTS == rc) {
 162             /* already exists - can't publish it */
 163             rc = MPI_ERR_FILE_EXISTS;
 164         } else if (OPAL_ERR_NOT_SUPPORTED == rc) {
 165             /* this PMIX environment doesn't support publishing */
 166             rc = OMPI_ERR_NOT_SUPPORTED;
 167             opal_show_help("help-mpi-api.txt",
 168                            "MPI function not supported",
 169                            true,
 170                            FUNC_NAME,
 171                            "Underlying runtime environment does not support name publishing functionality");
 172         } else {
 173             rc = MPI_ERR_INTERN;
 174         }
 175 
 176         return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, rc, FUNC_NAME);
 177     }
 178 
 179     return MPI_SUCCESS;
 180 }

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