root/ompi/mpi/c/info_set.c

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

DEFINITIONS

This source file includes following definitions.
  1. MPI_Info_set

   1 /*
   2  * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2013 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2012-2013 Inria.  All rights reserved.
  13  * Copyright (c) 2015      Research Organization for Information Science
  14  *                         and Technology (RIST). All rights reserved.
  15  * Copyright (c) 2018 IBM Corporation. All rights reserved.
  16  * $COPYRIGHT$
  17  *
  18  * Additional copyrights may follow
  19  *
  20  * $HEADER$
  21  */
  22 
  23 #include "ompi_config.h"
  24 
  25 #include "ompi/mpi/c/bindings.h"
  26 #include "ompi/runtime/params.h"
  27 #include "ompi/communicator/communicator.h"
  28 #include "ompi/errhandler/errhandler.h"
  29 #include "ompi/info/info.h"
  30 #include "opal/util/show_help.h"
  31 #include <stdlib.h>
  32 #include <string.h>
  33 
  34 #if OMPI_BUILD_MPI_PROFILING
  35 #if OPAL_HAVE_WEAK_SYMBOLS
  36 #pragma weak MPI_Info_set = PMPI_Info_set
  37 #endif
  38 #define MPI_Info_set PMPI_Info_set
  39 #endif
  40 
  41 static const char FUNC_NAME[] = "MPI_Info_set";
  42 
  43 
  44 /**
  45  *   MPI_Info_set - Set a (key, value) pair in an 'MPI_Info' object
  46  *
  47  *   @param key null-terminated character string of the index key
  48  *   @param value null-terminated character string of the value
  49  *   @param info info object (handle)
  50  *
  51  *   @retval MPI_SUCCESS
  52  *   @retval MPI_ERR_ARG
  53  *   @retval MPI_ERR_INFO_KEY
  54  *   @retval MPI_ERR_INFO_VAL
  55  *   @retval MPI_ERR_INFO_NOKEY
  56  *   @retval MPI_ERR_NO_MEM
  57  *
  58  *   MPI_Info_set adds the (key,value) pair to info, and overrides
  59  *   the value if for the same key a previsou value was set. key and
  60  *   value must be NULL terminated strings in C. In Fortan, leading
  61  *   and trailing spaces in key and value are stripped. If either
  62  *   key or value is greater than the allowed maxima, MPI_ERR_INFO_KEY
  63  *   and MPI_ERR_INFO_VALUE are raised
  64  */
  65 int MPI_Info_set(MPI_Info info, const char *key, const char *value)
  66 {
  67     int err;
  68     int key_length;
  69     int value_length;
  70 
  71     /*
  72      * Error conditions are
  73      *   - info is NULL
  74      *   - No storage space available for the new value
  75      *   - Key length exceeded MPI_MAX_KEY_VAL
  76      *   - value length exceeded MPI_MAX_KEY_VAL
  77      */
  78 
  79     if (MPI_PARAM_CHECK) {
  80         OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
  81         if (NULL == info || MPI_INFO_NULL == info ||
  82             ompi_info_is_freed(info)) {
  83             return OMPI_ERRHANDLER_INVOKE (MPI_COMM_WORLD, MPI_ERR_INFO,
  84                                            FUNC_NAME);
  85         }
  86 
  87         key_length = (key) ? (int)strlen (key) : 0;
  88         if ((NULL == key) || (0 == key_length) ||
  89             (MPI_MAX_INFO_KEY <= key_length)) {
  90             return OMPI_ERRHANDLER_INVOKE (MPI_COMM_WORLD, MPI_ERR_INFO_KEY,
  91                                            FUNC_NAME);
  92         }
  93 
  94         value_length = (value) ? (int)strlen (value) : 0;
  95         if ((NULL == value) || (0 == value_length) ||
  96             (MPI_MAX_INFO_VAL <= value_length)) {
  97             return OMPI_ERRHANDLER_INVOKE (MPI_COMM_WORLD, MPI_ERR_INFO_VALUE,
  98                                            FUNC_NAME);
  99         }
 100     }
 101 
 102 // An extra warning condition is a key that uses our reserved prefix "__IN_".
 103 // That one is used internally to deal with the dynamic nature the key/val
 104 // pairs where we have callbacks that modify the val, and the MPI standard
 105 // wants the get_info call to give back the original setting rather than
 106 // the callback-modified setting. So if a user directly used a key __IN_foo
 107 // it would confuse our accounting slightly.
 108     if (0 == strncmp(key, OPAL_INFO_SAVE_PREFIX, strlen(OPAL_INFO_SAVE_PREFIX))) {
 109         opal_show_help("help-mpi-api.txt", "info-set-with-reserved-prefix", true,
 110             key, OPAL_INFO_SAVE_PREFIX);
 111     }
 112 
 113     OPAL_CR_ENTER_LIBRARY();
 114 
 115     /*
 116      * If all is right with the arguments, then call the back-end
 117      * allocator.
 118      */
 119 
 120     err = ompi_info_set (info, key, value);
 121     OMPI_ERRHANDLER_RETURN(err, MPI_COMM_WORLD, err, FUNC_NAME);
 122 }

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