|
| 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-2020 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) 2006-2012 Cisco Systems, Inc. All rights reserved. |
| 13 | + * Copyright (c) 2015-2017 Research Organization for Information Science |
| 14 | + * and Technology (RIST). All rights reserved. |
| 15 | + * $COPYRIGHT$ |
| 16 | + * |
| 17 | + * Additional copyrights may follow |
| 18 | + * |
| 19 | + * $HEADER$ |
| 20 | + */ |
| 21 | + |
| 22 | +#include "ompi_config.h" |
| 23 | + |
| 24 | +#include "ompi/mpi/fortran/mpif-h/bindings.h" |
| 25 | +#include "ompi/constants.h" |
| 26 | +#include "ompi/communicator/communicator.h" |
| 27 | +#include "ompi/mpi/fortran/base/fortran_base_strings.h" |
| 28 | +#include "ompi/info/info.h" |
| 29 | + |
| 30 | +#if OMPI_BUILD_MPI_PROFILING |
| 31 | +#if OPAL_HAVE_WEAK_SYMBOLS |
| 32 | +#pragma weak PMPI_INFO_GET_STRING = ompi_info_get_string_f |
| 33 | +#pragma weak pmpi_info_get_string = ompi_info_get_string_f |
| 34 | +#pragma weak pmpi_info_get_string_ = ompi_info_get_string_f |
| 35 | +#pragma weak pmpi_info_get_string__ = ompi_info_get_string_f |
| 36 | + |
| 37 | +#pragma weak PMPI_Info_get_string_f = ompi_info_get_string_f |
| 38 | +#pragma weak PMPI_Info_get_string_f08 = ompi_info_get_string_f |
| 39 | +#else |
| 40 | +OMPI_GENERATE_F77_BINDINGS (PMPI_INFO_GET_STRING, |
| 41 | + pmpi_info_get_string, |
| 42 | + pmpi_info_get_string_, |
| 43 | + pmpi_info_get_string__, |
| 44 | + pompi_info_get_string_f, |
| 45 | + (MPI_Fint *info, char *key, MPI_Fint *buflen, char *value, ompi_fortran_logical_t *flag, MPI_Fint *ierr, int key_len, int value_len), |
| 46 | + (info, key, buflen, value, flag, ierr, key_len, value_len) ) |
| 47 | +#endif |
| 48 | +#endif |
| 49 | + |
| 50 | +#if OPAL_HAVE_WEAK_SYMBOLS |
| 51 | +#pragma weak MPI_INFO_GET_STRING = ompi_info_get_string_f |
| 52 | +#pragma weak mpi_info_get_string = ompi_info_get_string_f |
| 53 | +#pragma weak mpi_info_get_string_ = ompi_info_get_string_f |
| 54 | +#pragma weak mpi_info_get_string__ = ompi_info_get_string_f |
| 55 | + |
| 56 | +#pragma weak MPI_Info_get_string_f = ompi_info_get_string_f |
| 57 | +#pragma weak MPI_Info_get_string_f08 = ompi_info_get_string_f |
| 58 | +#else |
| 59 | +#if ! OMPI_BUILD_MPI_PROFILING |
| 60 | +OMPI_GENERATE_F77_BINDINGS (MPI_INFO_GET_STRING, |
| 61 | + mpi_info_get_string, |
| 62 | + mpi_info_get_string_, |
| 63 | + mpi_info_get_string__, |
| 64 | + ompi_info_get_string_f, |
| 65 | + (MPI_Fint *info, char *key, MPI_Fint *buflen, char *value, ompi_fortran_logical_t *flag, MPI_Fint *ierr, int key_len, int value_len), |
| 66 | + (info, key, buflen, value, flag, ierr, key_len, value_len) ) |
| 67 | +#else |
| 68 | +#define ompi_info_get_string_f pompi_info_get_string_f |
| 69 | +#endif |
| 70 | +#endif |
| 71 | + |
| 72 | + |
| 73 | +static const char FUNC_NAME[] = "MPI_INFO_GET_STRING"; |
| 74 | + |
| 75 | +/* Note that the key_len and value_len parameters are silently added |
| 76 | + by the Fortran compiler, and will be filled in with the actual |
| 77 | + length of the character array from the caller. Hence, it's the max |
| 78 | + length of the string that we can use. */ |
| 79 | + |
| 80 | +void ompi_info_get_string_f(MPI_Fint *info, char *key, MPI_Fint *buflen, |
| 81 | + char *value, ompi_fortran_logical_t *flag, MPI_Fint *ierr, |
| 82 | + int key_len, int value_len) |
| 83 | +{ |
| 84 | + int c_ierr, ret; |
| 85 | + MPI_Info c_info; |
| 86 | + char *c_key = NULL; |
| 87 | + OMPI_SINGLE_NAME_DECL(buflen); |
| 88 | + OMPI_LOGICAL_NAME_DECL(flag); |
| 89 | + opal_cstring_t *info_str; |
| 90 | + |
| 91 | + if (OMPI_SUCCESS != (ret = ompi_fortran_string_f2c(key, key_len, &c_key))) { |
| 92 | + c_ierr = OMPI_ERRHANDLER_NOHANDLE_INVOKE(ret, FUNC_NAME); |
| 93 | + if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr); |
| 94 | + return; |
| 95 | + } |
| 96 | + |
| 97 | + c_info = PMPI_Info_f2c(*info); |
| 98 | + |
| 99 | + if (0 == *buflen) { |
| 100 | + c_ierr = ompi_info_get_valuelen(c_info, c_key, |
| 101 | + OMPI_SINGLE_NAME_CONVERT(buflen), |
| 102 | + OMPI_LOGICAL_SINGLE_NAME_CONVERT(flag)); |
| 103 | + if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr); |
| 104 | + |
| 105 | + if (MPI_SUCCESS == c_ierr) { |
| 106 | + OMPI_SINGLE_INT_2_FINT(buflen); |
| 107 | + OMPI_SINGLE_INT_2_LOGICAL(flag); |
| 108 | + } |
| 109 | + } else { |
| 110 | + c_ierr = ompi_info_get(c_info, c_key, &info_str, |
| 111 | + OMPI_LOGICAL_SINGLE_NAME_CONVERT(flag)); |
| 112 | + if (NULL != ierr) { |
| 113 | + *ierr = OMPI_INT_2_FINT(c_ierr); |
| 114 | + } |
| 115 | + |
| 116 | + |
| 117 | + if (MPI_SUCCESS == c_ierr) { |
| 118 | + OMPI_SINGLE_INT_2_LOGICAL(flag); |
| 119 | + |
| 120 | + /* If we found the info key, copy the value back to the |
| 121 | + Fortran string (note: all Fortran compilers have FALSE == |
| 122 | + 0, so just check for any nonzero value, because not all |
| 123 | + Fortran compilers have TRUE == 1). Note: use the full |
| 124 | + length of the Fortran string, which means adding one to the 3rd arg |
| 125 | + to ompi_fortran_string_c2f */ |
| 126 | + if (*flag) { |
| 127 | + if (OMPI_SUCCESS != |
| 128 | + (ret = ompi_fortran_string_c2f(info_str->string, value, value_len + 1))) { |
| 129 | + c_ierr = OMPI_ERRHANDLER_NOHANDLE_INVOKE(ret, FUNC_NAME); |
| 130 | + if (NULL != ierr) { |
| 131 | + *ierr = OMPI_INT_2_FINT(c_ierr); |
| 132 | + } |
| 133 | + } |
| 134 | + *buflen = info_str->length; |
| 135 | + OBJ_RELEASE(info_str); |
| 136 | + } |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + if (NULL != c_key) { |
| 141 | + free(c_key); |
| 142 | + } |
| 143 | +} |
0 commit comments