Skip to content

Commit ee3387d

Browse files
committed
Create an mpirun dedicated executable
If we install the embedded versions or PRRTE and PMIx, then OPAL_PREFIX needs to adjust the installed location for PMIx as well as for PRRTE when launching via mpirun. In mpirun: Detect OPAL_PREFIX and set the corresponding PRRTE and PMIx prefixes. Take advantage of the simplified proxy detection support in PRRTE. Deal with absolute path names In MPI_Init: Detect OPAL_PREFIX and set the corresponding PMIx prefix Signed-off-by: Ralph Castain <[email protected]>
1 parent dff15b3 commit ee3387d

File tree

8 files changed

+155
-7
lines changed

8 files changed

+155
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ ompi/tools/mpisync/mpisync
341341
ompi/tools/mpisync/mpirun_prof
342342
ompi/tools/mpisync/ompi_timing_post
343343
ompi/tools/mpisync/mpisync.1
344+
ompi/tools/mpirun/mpirun
344345

345346
ompi/tools/ompi_info/ompi_info
346347
ompi/tools/ompi_info/ompi_info.1

config/ompi_setup_prrte.m4

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ AC_DEFUN([OMPI_SETUP_PRRTE],[
9898
# so try the internal version.
9999
AS_IF([test "$prrte_setup_external_happy" = "0" -a "$prrte_setup_internal_happy" = "1"],
100100
[opal_prrte_mode="internal"
101-
_OMPI_SETUP_PRRTE_INTERNAL_POST()])
101+
OMPI_USING_INTERNAL_PRRTE=1
102+
_OMPI_SETUP_PRRTE_INTERNAL_POST()],
103+
[OMPI_USING_INTERNAL_PRRTE=0])
102104
103105
AS_IF([test "$opal_prrte_mode" != "disabled"],
104106
[AS_IF([test "$prrte_setup_external_happy" = "0" -a "$prrte_setup_internal_happy" = "0"],
@@ -115,6 +117,10 @@ AC_DEFUN([OMPI_SETUP_PRRTE],[
115117
[$OMPI_HAVE_PRRTE],
116118
[Whether or not PRRTE is available])
117119
120+
AC_DEFINE_UNQUOTED([OMPI_USING_INTERNAL_PRRTE],
121+
[$OMPI_USING_INTERNAL_PRRTE],
122+
[Whether or not we are using the internal PRRTE])
123+
118124
OPAL_SUMMARY_ADD([[Miscellaneous]], [[prrte]], [prrte], [$opal_prrte_mode])
119125
120126
OPAL_VAR_SCOPE_POP

config/opal_config_pmix.m4

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,17 @@ AC_DEFUN([OPAL_CONFIG_PMIX], [
122122
# so try the internal version.
123123
AS_IF([test "$external_pmix_happy" = "0" -a "$internal_pmix_happy" = "1"],
124124
[opal_pmix_mode="internal"
125-
_OPAL_CONFIG_PMIX_INTERNAL_POST()])
125+
OPAL_USING_INTERNAL_PMIX=1
126+
_OPAL_CONFIG_PMIX_INTERNAL_POST()],
127+
[OPAL_USING_INTERNAL_PMIX=0])
126128
127129
AS_IF([test "$external_pmix_happy" = "0" -a "$internal_pmix_happy" = "0"],
128130
[AC_MSG_ERROR([Could not find viable pmix build.])])
129131
132+
AC_DEFINE_UNQUOTED([OPAL_USING_INTERNAL_PMIX],
133+
[$OPAL_USING_INTERNAL_PMIX],
134+
[Whether or not we are using the internal PMIx])
135+
130136
AC_SUBST(opal_pmix_CPPFLAGS)
131137
AC_SUBST(opal_pmix_LDFLAGS)
132138
AC_SUBST(opal_pmix_LIBS)

ompi/runtime/ompi_mpi_init.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ int ompi_mpi_init(int argc, char **argv, int requested, int *provided,
397397
ompi_proc_t** procs;
398398
size_t nprocs;
399399
char *error = NULL;
400+
char *evar;
400401
volatile bool active;
401402
bool background_fence = false;
402403
pmix_info_t info[2];
@@ -439,6 +440,14 @@ int ompi_mpi_init(int argc, char **argv, int requested, int *provided,
439440
}
440441
}
441442

443+
/* deal with OPAL_PREFIX to ensure that an internal PMIx installation
444+
* is also relocated if necessary */
445+
#if OPAL_USING_INTERNAL_PMIX
446+
if (NULL != (evar = getenv("OPAL_PREFIX"))) {
447+
opal_setenv("PMIX_PREFIX", evar, true, &environ);
448+
}
449+
#endif
450+
442451
/* Figure out the final MPI thread levels. If we were not
443452
compiled for support for MPI threads, then don't allow
444453
MPI_THREAD_MULTIPLE. Set this stuff up here early in the

ompi/tools/mpirun/Makefile.am

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Copyright (c) 2020 IBM Corporation. All rights reserved.
44
# Copyright (c) 2021 Amazon.com, Inc. or its affiliates.
55
# All Rights reserved.
6+
# Copyright (c) 2021 Nanook Consulting. All rights reserved.
67
# $COPYRIGHT$
78
#
89
# Additional copyrights may follow
@@ -11,10 +12,18 @@
1112
#
1213

1314
if OMPI_WANT_PRRTE
15+
16+
bin_PROGRAMS = mpirun
17+
18+
mpirun_SOURCES = \
19+
main.c
20+
21+
mpirun_LDADD = \
22+
$(top_builddir)/opal/libopen-pal.la
23+
1424
install-exec-hook:
15-
(cd $(DESTDIR)$(bindir); rm -f mpirun$(EXEEXT); $(LN_S) $(PRTE_PATH)$(EXEEXT) mpirun$(EXEEXT))
16-
(cd $(DESTDIR)$(bindir); rm -f mpiexec$(EXEEXT); $(LN_S) $(PRTE_PATH)$(EXEEXT) mpiexec$(EXEEXT))
17-
(cd $(DESTDIR)$(bindir); rm -f oshrun$(EXEEXT); $(LN_S) $(PRTE_PATH)$(EXEEXT) oshrun$(EXEEXT))
25+
(cd $(DESTDIR)$(bindir); rm -f mpiexec$(EXEEXT); $(LN_S) mpirun$(EXEEXT) mpiexec$(EXEEXT))
26+
(cd $(DESTDIR)$(bindir); rm -f oshrun$(EXEEXT); $(LN_S) mpirun$(EXEEXT) oshrun$(EXEEXT))
1827

1928
uninstall-local:
2029
rm -f $(DESTDIR)$(bindir)/mpirun$(EXEEXT) \

ompi/tools/mpirun/main.c

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/***************************************************************************
2+
* *
3+
* Open MPI: Open Source High Performance Computing *
4+
* *
5+
* http://www.open-mpi.org/ *
6+
* *
7+
***************************************************************************/
8+
#include "ompi_config.h"
9+
10+
#include <stdio.h>
11+
#include <stdlib.h>
12+
#include <unistd.h>
13+
#if HAVE_SYS_STAT_H
14+
# include <sys/stat.h>
15+
#endif /* HAVE_SYS_STAT_H */
16+
17+
#include "opal/mca/base/base.h"
18+
#include "opal/mca/installdirs/base/base.h"
19+
#include "opal/util/argv.h"
20+
#include "opal/util/basename.h"
21+
#include "opal/util/opal_environ.h"
22+
#include "opal/util/os_dirpath.h"
23+
#include "opal/util/os_path.h"
24+
#include "opal/util/path.h"
25+
26+
int main(int argc, char *argv[])
27+
{
28+
char *evar, *pvar;
29+
char **pargs = NULL;
30+
char *pfx = NULL;
31+
int m, param_len;
32+
char *truepath;
33+
34+
if (NULL != (evar = getenv("OPAL_PREFIX"))) {
35+
36+
#if OMPI_USING_INTERNAL_PRRTE
37+
(void)asprintf(&pvar, "PRTE_PREFIX=%s", evar);
38+
putenv(pvar);
39+
#endif
40+
41+
#if OPAL_USING_INTERNAL_PMIX
42+
(void)asprintf(&pvar, "PMIX_PREFIX=%s", evar);
43+
putenv(pvar);
44+
#endif
45+
}
46+
putenv("PRTE_MCA_schizo_proxy=ompi");
47+
48+
opal_argv_append_nosize(&pargs, "prterun");
49+
for (m=1; NULL != argv[m]; m++) {
50+
opal_argv_append_nosize(&pargs, argv[m]);
51+
/* Did the user specify a prefix, or want prefix by default? */
52+
if (0 == strcmp(argv[m], "--prefix")) {
53+
pfx = strdup(argv[m+1]);
54+
}
55+
}
56+
57+
if (NULL != pfx) {
58+
/* "Parse" the param, aka remove superfluous path_sep. */
59+
param_len = strlen(pfx);
60+
while (0 == strcmp(OPAL_PATH_SEP, &(pfx[param_len - 1]))) {
61+
pfx[param_len - 1] = '\0';
62+
param_len--;
63+
if (0 == param_len) {
64+
fprintf(stderr, "A prefix was supplied to mpirun that only contained slashes.\n"
65+
"This is a fatal error; mpirun will now abort.\nNo processes were launched.\n");
66+
exit(1);
67+
}
68+
}
69+
} else if (opal_path_is_absolute(argv[0])) {
70+
/* Check if called with fully-qualified path to mpirun.
71+
* (Note: Put this second so can override with --prefix (above). */
72+
pfx = opal_dirname(argv[0]);
73+
#if OMPI_USING_INTERNAL_PRRTE
74+
} else {
75+
/* in case --enable-prefix-by-default was given */
76+
mca_base_framework_open(&opal_installdirs_base_framework, 0); // fill in the installdirs
77+
if (NULL != opal_install_dirs.prefix) {
78+
pfx = strdup(opal_install_dirs.prefix);
79+
}
80+
#endif
81+
}
82+
83+
if (NULL == pfx) {
84+
truepath = opal_path_findv("prterun", X_OK, environ, NULL);
85+
} else {
86+
truepath = opal_os_path(0, pfx, "prterun", NULL);
87+
free(pfx);
88+
}
89+
90+
if (NULL == truepath) {
91+
fprintf(stderr, "prterun executable could not be found - unable to run\n");
92+
exit(1);
93+
}
94+
95+
execve(truepath, pargs, environ);
96+
}
97+
98+
/*
99+
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
100+
* University Research and Technology
101+
* Corporation. All rights reserved.
102+
* Copyright (c) 2004-2005 The University of Tennessee and The University
103+
* of Tennessee Research Foundation. All rights
104+
* reserved.
105+
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
106+
* University of Stuttgart. All rights reserved.
107+
* Copyright (c) 2004-2005 The Regents of the University of California.
108+
* All rights reserved.
109+
* Copyright (c) 2017-2020 Intel, Inc. All rights reserved.
110+
* Copyright (c) 2020 Cisco Systems, Inc. All rights reserved.
111+
* Copyright (c) 2021 Nanook Consulting. All rights reserved.
112+
* $COPYRIGHT$
113+
*
114+
* Additional copyrights may follow
115+
*
116+
* $HEADER$
117+
*/

0 commit comments

Comments
 (0)