Skip to content

Commit 04207e5

Browse files
committed
implement MPI_Info_create_env
related to #7993 Signed-off-by: Howard Pritchard <[email protected]>
1 parent 01ebde1 commit 04207e5

22 files changed

+363
-38
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
.. _mpi_info_create_env:
2+
3+
4+
MPI_Info_create_env
5+
===================
6+
7+
.. include_body
8+
9+
:ref:`MPI_Info_create_env` - Creates a new info object with the same construction as MPI_INFO_ENV as created during :ref:`MPI_Init` or :ref:`MPI_Init_thread` when the same arguments
10+
are used.
11+
12+
13+
SYNTAX
14+
------
15+
16+
17+
C Syntax
18+
^^^^^^^^
19+
20+
.. code-block:: c
21+
22+
#include <mpi.h>
23+
24+
int MPI_Info_create_env(int argc, char *argv[], MPI_Info *info)
25+
26+
27+
Fortran Syntax
28+
^^^^^^^^^^^^^^
29+
30+
.. code-block:: fortran
31+
32+
USE MPI
33+
! or the older form: INCLUDE 'mpif.h'
34+
MPI_INFO_CREATE_ENV(INFO, IERROR)
35+
INTEGER INFO, IERROR
36+
37+
38+
Fortran 2008 Syntax
39+
^^^^^^^^^^^^^^^^^^^
40+
41+
.. code-block:: fortran
42+
43+
USE mpi_f08
44+
MPI_Info_create_env(info, ierror)
45+
TYPE(MPI_Info), INTENT(OUT) :: info
46+
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
47+
48+
49+
OUTPUT PARAMETERS
50+
-----------------
51+
* ``info``: Info object created (handle).
52+
* ``IERROR``: Fortran only: Error status (integer).
53+
54+
DESCRIPTION
55+
-----------
56+
57+
:ref:`MPI_Info_create_env` creates a new info object and populates it with the same key/value pairs as are present in MPI_INFO_ENV.
58+
59+
Note
60+
----
61+
62+
:ref:`MPI_Info_create_env` is one of the few functions that can be called
63+
before :ref:`MPI_Init` and after :ref:`MPI_Finalize`.
64+
65+
ERRORS
66+
------
67+
68+
Almost all MPI routines return an error value; C routines as the value
69+
of the function and Fortran routines in the last argument.
70+
71+
Before the error value is returned, the current MPI error handler is
72+
called. By default, this error handler aborts the MPI job, except for
73+
I/O function errors. The error handler may be changed with
74+
:ref:`MPI_Comm_set_errhandler`; the predefined error handler MPI_ERRORS_RETURN
75+
may be used to cause error values to be returned. Note that MPI does not
76+
guarantee that an MPI program can continue past an error.
77+
78+
79+
.. seealso::
80+
:ref:`MPI_Info_delete` :ref:`MPI_Info_dup` :ref:`MPI_Info_free` :ref:`MPI_Info_get` :ref:`MPI_Info_set`

docs/man-openmpi/man3/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ MPI API manual pages (section 3)
221221
MPI_Ineighbor_alltoallw.3.rst
222222
MPI_Info_c2f.3.rst
223223
MPI_Info_create.3.rst
224+
MPI_Info_create_env.3.rst
224225
MPI_Info_delete.3.rst
225226
MPI_Info_dup.3.rst
226227
MPI_Info_env.3.rst

ompi/include/mpi.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,7 @@ OMPI_DECLSPEC int MPI_Imrecv(void *buf, int count, MPI_Datatype type,
17471747
MPI_Message *message, MPI_Request *request);
17481748
OMPI_DECLSPEC MPI_Fint MPI_Info_c2f(MPI_Info info);
17491749
OMPI_DECLSPEC int MPI_Info_create(MPI_Info *info);
1750+
OMPI_DECLSPEC int MPI_Info_create_env(int argc, char *argv[], MPI_Info *info);
17501751
OMPI_DECLSPEC int MPI_Info_delete(MPI_Info info, const char *key);
17511752
OMPI_DECLSPEC int MPI_Info_dup(MPI_Info info, MPI_Info *newinfo);
17521753
OMPI_DECLSPEC MPI_Info MPI_Info_f2c(MPI_Fint info);
@@ -2507,6 +2508,7 @@ OMPI_DECLSPEC int PMPI_Imrecv(void *buf, int count, MPI_Datatype type,
25072508
MPI_Message *message, MPI_Request *request);
25082509
OMPI_DECLSPEC MPI_Fint PMPI_Info_c2f(MPI_Info info);
25092510
OMPI_DECLSPEC int PMPI_Info_create(MPI_Info *info);
2511+
OMPI_DECLSPEC int PMPI_Info_create_env(int argc, char **argv, MPI_Info *info);
25102512
OMPI_DECLSPEC int PMPI_Info_delete(MPI_Info info, const char *key);
25112513
OMPI_DECLSPEC int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo);
25122514
OMPI_DECLSPEC MPI_Info PMPI_Info_f2c(MPI_Fint info);

ompi/info/info.c

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -116,76 +116,91 @@ int ompi_mpiinfo_init(void)
116116
return OMPI_SUCCESS;
117117
}
118118

119-
/*
120-
* Fill in the MPI_INFO_ENV if using MPI3 initialization
119+
/**
120+
* Fill in an info object with ENV info. Used for setting
121+
* MPI_INFO_ENV and by invocation of MPI_Info_create_env.
121122
*/
122-
int ompi_mpiinfo_init_mpi3(void)
123+
124+
int ompi_mpiinfo_init_env(int argc, char **argv, ompi_info_t *info)
123125
{
124-
char *cptr, **tmp;
126+
char *cptr = NULL, **tmp = NULL;
125127

126128
/* fill the env info object */
127129

128130
/* command for this app_context */
129-
if (NULL != ompi_process_info.command) {
131+
if (NULL != argv) {
132+
tmp = argv;
133+
} else if (NULL != ompi_process_info.command) {
130134
tmp = opal_argv_split(ompi_process_info.command, ' ');
131-
opal_info_set(&ompi_mpi_info_env.info.super, "command", tmp[0]);
135+
}
136+
137+
if (NULL != tmp) {
138+
if (NULL != tmp[0]) {
139+
opal_info_set(&info->super, "command", tmp[0]);
140+
}
132141

133142
/* space-separated list of argv for this command */
134143
if (1 < opal_argv_count(tmp)) {
135144
cptr = opal_argv_join(&tmp[1], ' ');
136145
} else {
137-
cptr = strdup(tmp[0]);
146+
if (NULL != tmp[0]) {
147+
cptr = strdup(tmp[0]);
148+
}
149+
}
150+
if (NULL == argv) {
151+
opal_argv_free(tmp);
152+
}
153+
opal_info_set(&info->super, "argv", cptr);
154+
if (NULL != cptr) {
155+
free(cptr);
138156
}
139-
opal_argv_free(tmp);
140-
opal_info_set(&ompi_mpi_info_env.info.super, "argv", cptr);
141-
free(cptr);
142157
}
143158

144159
/* max procs for the entire job */
145160
opal_asprintf(&cptr, "%u", ompi_process_info.num_procs);
146-
opal_info_set(&ompi_mpi_info_env.info.super, "maxprocs", cptr);
161+
opal_info_set(&info->super, "maxprocs", cptr);
147162
/* Open MPI does not support the "soft" option, so set it to maxprocs */
148-
opal_info_set(&ompi_mpi_info_env.info.super, "soft", cptr);
163+
opal_info_set(&info->super, "soft", cptr);
149164
free(cptr);
150165

151166
/* the initial error handler, set it as requested (nothing if not
152167
* requested) */
153168
if (NULL != ompi_process_info.initial_errhandler) {
154-
opal_info_set(&ompi_mpi_info_env.info.super, "mpi_initial_errhandler", ompi_process_info.initial_errhandler);
169+
opal_info_set(&info->super, "mpi_initial_errhandler", ompi_process_info.initial_errhandler);
155170
}
156171

157172
/* local host name */
158-
opal_info_set(&ompi_mpi_info_env.info.super, "host", ompi_process_info.nodename);
173+
opal_info_set(&info->super, "host", ompi_process_info.nodename);
159174

160175
#ifdef HAVE_SYS_UTSNAME_H
161176
{
162177
struct utsname sysname;
163178
uname(&sysname);
164179
cptr = sysname.machine;
165-
opal_info_set(&ompi_mpi_info_env.info.super, "arch", cptr);
180+
opal_info_set(&info->super, "arch", cptr);
166181
}
167182
#endif
168183

169184
/* initial working dir of this process, if provided */
170185
if (NULL != ompi_process_info.initial_wdir) {
171-
opal_info_set(&ompi_mpi_info_env.info.super, "wdir", ompi_process_info.initial_wdir);
186+
opal_info_set(&info->super, "wdir", ompi_process_info.initial_wdir);
172187
}
173188

174189
/* provide the REQUESTED thread level - may be different
175190
* than the ACTUAL thread level you get.
176191
* ugly, but have to do a switch to find the string representation */
177192
switch (ompi_mpi_thread_requested) {
178193
case MPI_THREAD_SINGLE:
179-
opal_info_set(&ompi_mpi_info_env.info.super, "thread_level", "MPI_THREAD_SINGLE");
194+
opal_info_set(&info->super, "thread_level", "MPI_THREAD_SINGLE");
180195
break;
181196
case MPI_THREAD_FUNNELED:
182-
opal_info_set(&ompi_mpi_info_env.info.super, "thread_level", "MPI_THREAD_FUNNELED");
197+
opal_info_set(&info->super, "thread_level", "MPI_THREAD_FUNNELED");
183198
break;
184199
case MPI_THREAD_SERIALIZED:
185-
opal_info_set(&ompi_mpi_info_env.info.super, "thread_level", "MPI_THREAD_SERIALIZED");
200+
opal_info_set(&info->super, "thread_level", "MPI_THREAD_SERIALIZED");
186201
break;
187202
case MPI_THREAD_MULTIPLE:
188-
opal_info_set(&ompi_mpi_info_env.info.super, "thread_level", "MPI_THREAD_MULTIPLE");
203+
opal_info_set(&info->super, "thread_level", "MPI_THREAD_MULTIPLE");
189204
break;
190205
default:
191206
/* do nothing - don't know the value */
@@ -196,24 +211,24 @@ int ompi_mpiinfo_init_mpi3(void)
196211

197212
/* the number of app_contexts in this job */
198213
opal_asprintf(&cptr, "%u", ompi_process_info.num_apps);
199-
opal_info_set(&ompi_mpi_info_env.info.super, "ompi_num_apps", cptr);
214+
opal_info_set(&info->super, "ompi_num_apps", cptr);
200215
free(cptr);
201216

202217
/* space-separated list of first MPI rank of each app_context */
203218
if (NULL != ompi_process_info.app_ldrs) {
204-
opal_info_set(&ompi_mpi_info_env.info.super, "ompi_first_rank", ompi_process_info.app_ldrs);
219+
opal_info_set(&info->super, "ompi_first_rank", ompi_process_info.app_ldrs);
205220
}
206221

207222
/* space-separated list of num procs for each app_context */
208223
if (NULL != ompi_process_info.app_sizes) {
209-
opal_info_set(&ompi_mpi_info_env.info.super, "ompi_np", ompi_process_info.app_sizes);
224+
opal_info_set(&info->super, "ompi_np", ompi_process_info.app_sizes);
210225
}
211226

212227
/* location of the directory containing any prepositioned files
213228
* the user may have requested
214229
*/
215230
if (NULL != ompi_process_info.proc_session_dir) {
216-
opal_info_set(&ompi_mpi_info_env.info.super, "ompi_positioned_file_dir", ompi_process_info.proc_session_dir);
231+
opal_info_set(&info->super, "ompi_positioned_file_dir", ompi_process_info.proc_session_dir);
217232
}
218233

219234
/* All done */

ompi/info/info.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ OMPI_DECLSPEC OBJ_CLASS_DECLARATION(ompi_info_t);
9292
int ompi_mpiinfo_init(void);
9393

9494
/**
95-
* This function is invoked during ompi_mpi_init() and sets up
96-
* the MPI_INFO_ENV object
95+
* Fill in an info object with ENV info. Used for setting
96+
* MPI_INFO_ENV and by invocation of MPI_Info_create_env.
9797
*/
98-
int ompi_mpiinfo_init_mpi3(void);
98+
int ompi_mpiinfo_init_env(int argc, char *argv[], ompi_info_t *info);
9999

100100
/**
101101
* This function is used to free a ompi level info

ompi/instance/instance.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,9 @@ static int ompi_mpi_instance_init_common (int argc, char **argv)
448448
return ret;
449449
}
450450

451-
/* initialize info */
452-
if (OMPI_SUCCESS != (ret = ompi_mpiinfo_init_mpi3())) {
453-
return ompi_instance_print_error ("ompi_info_init_mpi3() failed", ret);
451+
/* initialize MPI_INFO_ENV */
452+
if (OMPI_SUCCESS != (ret = ompi_mpiinfo_init_env(0, NULL, &ompi_mpi_info_env.info))) {
453+
return ompi_instance_print_error ("ompi_info_init_env() failed", ret);
454454
}
455455

456456
/* declare our presence for interlib coordination, and

ompi/mpi/c/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ interface_profile_sources = \
266266
imrecv.c \
267267
info_c2f.c \
268268
info_create.c \
269+
info_create_env.c \
269270
info_delete.c \
270271
info_dup.c \
271272
info_f2c.c \

ompi/mpi/c/info_create_env.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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) 2015 Research Organization for Information Science
14+
* and Technology (RIST). All rights reserved.
15+
* Copyright (c) 2018-2021 Triad National Security, LLC. All rights
16+
* reserved.
17+
* $COPYRIGHT$
18+
*
19+
* Additional copyrights may follow
20+
*
21+
* $HEADER$
22+
*/
23+
24+
#include "ompi_config.h"
25+
26+
#include "ompi/mpi/c/bindings.h"
27+
#include "ompi/runtime/params.h"
28+
#include "ompi/communicator/communicator.h"
29+
#include "ompi/errhandler/errhandler.h"
30+
#include "ompi/info/info.h"
31+
32+
#if OMPI_BUILD_MPI_PROFILING
33+
#if OPAL_HAVE_WEAK_SYMBOLS
34+
#pragma weak MPI_Info_create_env = PMPI_Info_create_env
35+
#endif
36+
#define MPI_Info_create_env PMPI_Info_create_env
37+
#endif
38+
39+
static const char FUNC_NAME[] = "MPI_Info_create_env";
40+
41+
/**
42+
* Returns an info object with the same construction as MPI_INFO_ENV as created
43+
* during MPI_INIT or MPI_INIT_THREAD when the same arguments are used.
44+
*
45+
* @param argc number or arguments (Integer)
46+
* @param argv Pointer to array of arguments
47+
* @param info Pointer to the MPI_Info handle
48+
*
49+
* @retval MPI_SUCCESS
50+
* @retval MPI_ERR_INFO
51+
* @retval MPI_ERR_NO_MEM
52+
*
53+
* When an MPI_Info object is not being used, it should be freed using
54+
* MPI_Info_free
55+
*/
56+
int MPI_Info_create_env(int argc, char *argv[], MPI_Info *info)
57+
{
58+
int rc;
59+
ompi_info_t *the_info;
60+
61+
if (MPI_PARAM_CHECK) {
62+
if (NULL == info) {
63+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_INFO,
64+
FUNC_NAME);
65+
}
66+
}
67+
68+
the_info = ompi_info_allocate ();
69+
if (NULL == the_info) {
70+
return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_NO_MEM,
71+
FUNC_NAME);
72+
}
73+
74+
*info = the_info;
75+
76+
rc = ompi_mpiinfo_init_env(argc, argv, the_info);
77+
OMPI_ERRHANDLER_NOHANDLE_CHECK(rc, rc, FUNC_NAME);
78+
return MPI_SUCCESS;
79+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# and Technology (RIST). All rights reserved.
1919
# Copyright (c) 2016 IBM Corporation. All rights reserved.
2020
# Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
21-
# Copyright (c) 2021 Triad National Security, LLC. All rights
21+
# Copyright (c) 2021-2022 Triad National Security, LLC. All rights
2222
# reserved.
2323
#
2424
# $COPYRIGHT$
@@ -334,6 +334,7 @@ lib@OMPI_LIBMPI_NAME@_mpifh_la_SOURCES += \
334334
ineighbor_alltoallv_f.c \
335335
ineighbor_alltoallw_f.c \
336336
info_create_f.c \
337+
info_create_env_f.c \
337338
info_delete_f.c \
338339
info_dup_f.c \
339340
info_free_f.c \

0 commit comments

Comments
 (0)