Skip to content

Commit 232c59d

Browse files
committed
MPI4: add support for mpi_info_get_string
related to #9192 Signed-off-by: Howard Pritchard <howardp@lanl.gov>
1 parent 2f7a3d9 commit 232c59d

17 files changed

+344
-0
lines changed

ompi/include/mpi.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,8 @@ OMPI_DECLSPEC int MPI_Info_get_nkeys(MPI_Info info, int *nkeys);
16791679
OMPI_DECLSPEC int MPI_Info_get_nthkey(MPI_Info info, int n, char *key);
16801680
OMPI_DECLSPEC int MPI_Info_get_valuelen(MPI_Info info, const char *key, int *valuelen,
16811681
int *flag);
1682+
OMPI_DECLSPEC int MPI_Info_get_string(MPI_Info info, const char *key, int *buflen,
1683+
char *value, int *flag);
16821684
OMPI_DECLSPEC int MPI_Info_set(MPI_Info info, const char *key, const char *value);
16831685
OMPI_DECLSPEC int MPI_Init(int *argc, char ***argv);
16841686
OMPI_DECLSPEC int MPI_Initialized(int *flag);
@@ -2409,6 +2411,8 @@ OMPI_DECLSPEC int PMPI_Info_get(MPI_Info info, const char *key, int valuelen,
24092411
char *value, int *flag);
24102412
OMPI_DECLSPEC int PMPI_Info_get_nkeys(MPI_Info info, int *nkeys);
24112413
OMPI_DECLSPEC int PMPI_Info_get_nthkey(MPI_Info info, int n, char *key);
2414+
OMPI_DECLSPEC int PMPI_Info_get_string(MPI_Info info, const char *key, int *buflen,
2415+
char *value, int *flag);
24122416
OMPI_DECLSPEC int PMPI_Info_get_valuelen(MPI_Info info, const char *key, int *valuelen,
24132417
int *flag);
24142418
OMPI_DECLSPEC int PMPI_Info_set(MPI_Info info, const char *key, const char *value);

ompi/mpi/c/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ libmpi_c_mpi_la_SOURCES = \
271271
info_get.c \
272272
info_get_nkeys.c \
273273
info_get_nthkey.c \
274+
info_get_string.c \
274275
info_get_valuelen.c \
275276
info_set.c \
276277
init.c \

ompi/mpi/c/info_get_string.c

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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-2020 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 Research Organization for Information Science
16+
* and Technology (RIST). All rights reserved.
17+
* Copyright (c) 2016-2017 IBM Corporation. All rights reserved.
18+
* Copyright (c) 2021 Triad 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+
29+
#include "ompi/mpi/c/bindings.h"
30+
#include "ompi/runtime/params.h"
31+
#include "ompi/communicator/communicator.h"
32+
#include "ompi/errhandler/errhandler.h"
33+
#include "ompi/info/info.h"
34+
#include "opal/util/string_copy.h"
35+
#include <stdlib.h>
36+
#include <string.h>
37+
38+
#if OMPI_BUILD_MPI_PROFILING
39+
#if OPAL_HAVE_WEAK_SYMBOLS
40+
#pragma weak MPI_Info_get_string = PMPI_Info_get_string
41+
#endif
42+
#define MPI_Info_get_string PMPI_Info_get_string
43+
#endif
44+
45+
static const char FUNC_NAME[] = "MPI_Info_get_string";
46+
47+
/**
48+
* MPI_Info_get_string - Get a (key, value) pair from an 'MPI_Info' object
49+
*
50+
* @param info info object (handle)
51+
* @param key null-terminated character string of the index key
52+
* @param buflen maximum length of 'value' (integer)
53+
* @param value null-terminated character string of the value
54+
* @param flag true (1) if 'key' defined on 'info', false (0) if not
55+
* (logical)
56+
*
57+
* @retval MPI_SUCCESS
58+
* @retval MPI_ERR_ARG
59+
* @retval MPI_ERR_INFO
60+
* @retval MPI_ERR_INFO_KEY
61+
* @retval MPI_ERR_INFO_VALUE
62+
*
63+
*/
64+
int MPI_Info_get_string(MPI_Info info, const char *key, int *buflen,
65+
char *value, int *flag)
66+
{
67+
int err;
68+
int key_length;
69+
opal_cstring_t *info_str;
70+
71+
/*
72+
* Simple function. All we need to do is search for the value
73+
* having the "key" associated with it and then populate the
74+
* necessary structures.
75+
*/
76+
if (MPI_PARAM_CHECK) {
77+
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
78+
if (NULL == info || MPI_INFO_NULL == info ||
79+
ompi_info_is_freed(info)) {
80+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_INFO,
81+
FUNC_NAME);
82+
}
83+
84+
key_length = (key) ? (int)strlen (key) : 0;
85+
if ((NULL == key) || (0 == key_length) ||
86+
(MPI_MAX_INFO_KEY <= key_length)) {
87+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_INFO_KEY,
88+
FUNC_NAME);
89+
}
90+
if (NULL == buflen) {
91+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_ARG,
92+
FUNC_NAME);
93+
}
94+
if ((NULL == value) && *buflen) {
95+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_INFO_VALUE,
96+
FUNC_NAME);
97+
}
98+
if (NULL == flag) {
99+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_ARG,
100+
FUNC_NAME);
101+
}
102+
}
103+
104+
if (0 == *buflen) {
105+
err = ompi_info_get_valuelen(info, key, buflen, flag);
106+
if (1 == *flag) {
107+
*buflen += 1; /* add on for the \0, see MPI 4.0 Standard */
108+
}
109+
} else {
110+
err = ompi_info_get(info, key, &info_str, flag);
111+
if (*flag) {
112+
opal_string_copy(value, info_str->string, *buflen);
113+
*buflen = info_str->length + 1; /* add on for the \0, see MPI 4.0 Standard */
114+
OBJ_RELEASE(info_str);
115+
}
116+
}
117+
118+
OMPI_ERRHANDLER_NOHANDLE_RETURN(err, err, FUNC_NAME);
119+
}

ompi/mpi/c/profile/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ nodist_libmpi_c_pmpi_la_SOURCES = \
251251
pinfo_get.c \
252252
pinfo_get_nkeys.c \
253253
pinfo_get_nthkey.c \
254+
pinfo_get_string.c \
254255
pinfo_get_valuelen.c \
255256
pinfo_set.c \
256257
pinit.c \

ompi/mpi/fortran/mpif-h/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ lib@OMPI_LIBMPI_NAME@_mpifh_la_SOURCES += \
334334
info_get_f.c \
335335
info_get_nkeys_f.c \
336336
info_get_nthkey_f.c \
337+
info_get_string_f.c \
337338
info_get_valuelen_f.c \
338339
info_set_f.c \
339340
init_f.c \
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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, valuelen, 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, valuelen, 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+
}

ompi/mpi/fortran/mpif-h/profile/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ linked_files = \
247247
pinfo_get_f.c \
248248
pinfo_get_nkeys_f.c \
249249
pinfo_get_nthkey_f.c \
250+
pinfo_get_string_f.c \
250251
pinfo_get_valuelen_f.c \
251252
pinfo_set_f.c \
252253
pinit_f.c \

ompi/mpi/fortran/mpif-h/prototypes_mpi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ PN2(void, MPI_Info_free, mpi_info_free, MPI_INFO_FREE, (MPI_Fint *info, MPI_Fint
303303
PN2(void, MPI_Info_get, mpi_info_get, MPI_INFO_GET, (MPI_Fint *info, char *key, MPI_Fint *valuelen, char *value, ompi_fortran_logical_t *flag, MPI_Fint *ierr, int key_len, int value_len));
304304
PN2(void, MPI_Info_get_nkeys, mpi_info_get_nkeys, MPI_INFO_GET_NKEYS, (MPI_Fint *info, MPI_Fint *nkeys, MPI_Fint *ierr));
305305
PN2(void, MPI_Info_get_nthkey, mpi_info_get_nthkey, MPI_INFO_GET_NTHKEY, (MPI_Fint *info, MPI_Fint *n, char *key, MPI_Fint *ierr, int key_len));
306+
PN2(void, MPI_Info_get_string, mpi_info_get_string, MPI_INFO_GET_STRING, (MPI_Fint *info, char *key, MPI_Fint *buflen, char *value, ompi_fortran_logical_t *flag, MPI_Fint *ierr, int key_len, int value_len));
306307
PN2(void, MPI_Info_get_valuelen, mpi_info_get_valuelen, MPI_INFO_GET_VALUELEN, (MPI_Fint *info, char *key, MPI_Fint *valuelen, ompi_fortran_logical_t *flag, MPI_Fint *ierr, int key_len));
307308
PN2(void, MPI_Info_set, mpi_info_set, MPI_INFO_SET, (MPI_Fint *info, char *key, char *value, MPI_Fint *ierr, int key_len, int value_len));
308309
PN2(void, MPI_Init, mpi_init, MPI_INIT, (MPI_Fint *ierr));

ompi/mpi/fortran/use-mpi-f08/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ mpi_api_files = \
318318
info_get_nkeys_f08.F90 \
319319
info_get_nthkey_f08.F90 \
320320
info_get_valuelen_f08.F90 \
321+
info_get_string_f08.F90 \
321322
info_set_f08.F90 \
322323
init_f08.F90 \
323324
initialized_f08.F90 \
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
! -*- f90 -*-
2+
!
3+
! Copyright (c) 2010-2013 Cisco Systems, Inc. All rights reserved.
4+
! Copyright (c) 2009-2012 Los Alamos National Security, LLC.
5+
! All Rights reserved.
6+
! Copyright (c) 2019-2020 Research Organization for Information Science
7+
! and Technology (RIST). All rights reserved.
8+
! $COPYRIGHT$
9+
10+
#include "mpi-f08-rename.h"
11+
12+
subroutine MPI_Info_get_string_f08(info,key,buflen,value,flag,ierror)
13+
use :: mpi_f08_types, only : MPI_Info
14+
! See note in mpi-f-interfaces-bind.h for why we "use mpi" here and
15+
! call a PMPI_* subroutine below.
16+
use :: mpi, only : PMPI_Info_get_string
17+
implicit none
18+
TYPE(MPI_Info), INTENT(IN) :: info
19+
CHARACTER(LEN=*), INTENT(IN) :: key
20+
INTEGER, INTENT(INOUT) :: buflen
21+
CHARACTER(LEN=*), INTENT(OUT) :: value
22+
LOGICAL, INTENT(OUT) :: flag
23+
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
24+
integer :: c_ierror
25+
26+
call PMPI_Info_get_string(info%MPI_VAL,key,buflen,value,flag,c_ierror)
27+
if (present(ierror)) ierror = c_ierror
28+
end subroutine MPI_Info_get_string_f08

0 commit comments

Comments
 (0)