14
14
#if HAVE_SYS_STAT_H
15
15
# include <sys/stat.h>
16
16
#endif /* HAVE_SYS_STAT_H */
17
+ #include <string.h>
17
18
18
19
#include "opal/mca/base/base.h"
19
20
#include "opal/mca/installdirs/base/base.h"
21
+ #include "opal/runtime/opal.h"
20
22
#include "opal/util/argv.h"
21
23
#include "opal/util/basename.h"
22
24
#include "opal/util/opal_environ.h"
23
25
#include "opal/util/os_dirpath.h"
24
26
#include "opal/util/os_path.h"
25
27
#include "opal/util/path.h"
26
28
#include "opal/util/printf.h"
29
+ #include "opal/util/show_help.h"
30
+ #include "ompi/constants.h"
27
31
28
- int main ( int argc , char * argv [] )
32
+ static char * find_prterun ( void )
29
33
{
30
- char * evar ;
31
- char * * pargs = NULL ;
32
- char * pfx = NULL ;
33
- int m , param_len ;
34
- char * truepath = NULL ;
34
+ char * filename = NULL ;
35
+ char * prrte_prefix = NULL ;
35
36
36
- if (NULL != (evar = getenv ("OPAL_PREFIX" ))) {
37
+ /* 1) Did the user tell us exactly where to find prterun? */
38
+ filename = getenv ("OMPI_PRTERUN" );
39
+ if (NULL != filename ) {
40
+ return filename ;
41
+ }
37
42
38
43
#if OMPI_USING_INTERNAL_PRRTE
39
- setenv ("PRTE_PREFIX" , evar , 1 );
40
- #endif
44
+ /* 2) If using internal PRRTE, use our bindir. Note that this
45
+ * will obey OPAL_PREFIX and OPAL_DESTDIR */
46
+ opal_asprintf (& filename , "%s%sprterun" , opal_install_dirs .bindir , OPAL_PATH_SEP );
47
+ return filename ;
48
+ #else
41
49
42
- #if OPAL_USING_INTERNAL_PMIX
43
- setenv ("PMIX_PREFIX" , evar , 1 );
50
+ /* 3) Look in ${PRTE_PREFIX}/bin */
51
+ prrte_prefix = getenv ("PRTE_PREFIX" );
52
+ if (NULL != prrte_prefix ) {
53
+ opal_asprintf (& filename , "%s%sbin%sprterun" , prrte_prefix , OPAL_PATH_SEP , OPAL_PATH_SEP );
54
+ return filename ;
55
+ }
56
+
57
+ /* 4) See if configure told us where to look, if set */
58
+ #if defined(OMPI_PRTERUN_PATH )
59
+ return strdup (OMPI_PRTERUN_PATH );
60
+ #else
61
+
62
+ /* 5) Use path search */
63
+ filename = opal_find_absolute_path ("prterun" );
64
+
65
+ return filename ;
66
+ #endif
44
67
#endif
68
+ }
69
+
70
+
71
+ int main (int argc , char * argv [])
72
+ {
73
+ char * opal_prefix = getenv ("OPAL_PREFIX" );
74
+ char * full_prterun_path = NULL ;
75
+ char * * prterun_args = NULL ;
76
+ int ret ;
77
+ size_t i ;
78
+
79
+ ret = opal_init_util (& argc , & argv );
80
+ if (OMPI_SUCCESS != ret ) {
81
+ fprintf (stderr , "Failed initializing opal: %d\n" , ret );
82
+ exit (1 );
45
83
}
84
+
85
+ /* note that we just modify our environment rather than create a
86
+ * child environment because it is easier and we're not going to
87
+ * be around long enough for it to matter (since we exec prterun
88
+ * asap */
46
89
setenv ("PRTE_MCA_schizo_proxy" , "ompi" , 1 );
47
90
setenv ("OMPI_VERSION" , OMPI_VERSION , 1 );
48
91
char * base_tool_name = opal_basename (argv [0 ]);
49
92
setenv ("OMPI_TOOL_NAME" , base_tool_name , 1 );
50
93
free (base_tool_name );
51
94
95
+ /* TODO: look for --prefix and compare with OPAL_PREFIX and pick
96
+ * one */
52
97
53
- opal_argv_append_nosize (& pargs , "prterun" );
54
- for (m = 1 ; NULL != argv [m ]; m ++ ) {
55
- opal_argv_append_nosize (& pargs , argv [m ]);
56
- /* Did the user specify a prefix, or want prefix by default? */
57
- if (0 == strcmp (argv [m ], "--prefix" )) {
58
- opal_asprintf (& pfx , "%s%s" , argv [m + 1 ], "/bin" );
59
- }
60
- }
61
-
62
- if (NULL != pfx ) {
63
- /* "Parse" the param, aka remove superfluous path_sep. */
64
- param_len = strlen (pfx );
65
- while (0 == strcmp (OPAL_PATH_SEP , & (pfx [param_len - 1 ]))) {
66
- pfx [param_len - 1 ] = '\0' ;
67
- param_len -- ;
68
- if (0 == param_len ) {
69
- fprintf (stderr , "A prefix was supplied to mpirun that only contained slashes.\n"
70
- "This is a fatal error; mpirun will now abort.\nNo processes were launched.\n" );
71
- exit (1 );
72
- }
73
- }
74
- } else if (opal_path_is_absolute (argv [0 ])) {
75
- /* Check if called with fully-qualified path to mpirun.
76
- * (Note: Put this second so can override with --prefix (above). */
77
- pfx = opal_dirname (argv [0 ]);
98
+ /* as a special case, if OPAL_PREFIX was set and either PRRTE or
99
+ * PMIx are internal builds, set their prefix variables as well */
100
+ if (NULL != opal_prefix ) {
78
101
#if OMPI_USING_INTERNAL_PRRTE
79
- } else {
80
- /* in case --enable-prefix-by-default was given */
81
- mca_base_framework_open (& opal_installdirs_base_framework , 0 ); // fill in the installdirs
82
- if (NULL != opal_install_dirs .bindir ) {
83
- pfx = strdup (opal_install_dirs .bindir );
84
- }
102
+ setenv ("PRTE_PREFIX" , opal_prefix , 1 );
85
103
#endif
86
- }
87
-
88
- if (NULL == pfx ) {
89
- truepath = opal_path_findv ("prterun" , X_OK , environ , NULL );
90
- #if !OMPI_USING_INTERNAL_PRRTE
91
- // if OMPI_PRTERUN_PATH is available, try that
92
- // for external builds if the user didn't explictly
93
- // add a prefix and it isn't in the users path.
94
- if ((NULL == truepath ) && (0 != strlen (OMPI_PRTERUN_PATH ))) {
95
- truepath = opal_os_path (0 , OMPI_PRTERUN_PATH , "prterun" , NULL );
96
- }
104
+ #if OPAL_USING_INTERNAL_PMIX
105
+ setenv ("PMIX_PREFIX" , opal_prefix , 1 );
97
106
#endif
98
- } else {
99
- truepath = opal_os_path (0 , pfx , "prterun" , NULL );
100
- free (pfx );
101
107
}
102
108
103
- if (NULL == truepath ) {
104
- fprintf (stderr , "prterun executable could not be found - unable to run\n" );
109
+ full_prterun_path = find_prterun ();
110
+ if (NULL == full_prterun_path ) {
111
+ opal_show_help ("help-mpirun.txt" , "no-prterun-found" , 1 );
105
112
exit (1 );
106
113
}
107
114
108
- execve (truepath , pargs , environ );
109
- fprintf (stderr , "The mpirun (\"%s\") cmd failed to exec its actual executable - your application will NOT execute. Error: %s\n" ,
110
- truepath ? truepath : "NULL" , strerror (errno ));
115
+ /* calling mpirun (and now prterun) with a full path has a special
116
+ * meaning in terms of -prefix behavior, so copy that behavior
117
+ * into prterun */
118
+ if (opal_path_is_absolute (argv [0 ])) {
119
+ opal_argv_append_nosize (& prterun_args , full_prterun_path );
120
+ } else {
121
+ opal_argv_append_nosize (& prterun_args , "prterun" );
122
+ }
123
+
124
+ /* Copy all the mpirun arguments to prterun.
125
+ * TODO: Need to handle --prefix rationally here. */
126
+ for (i = 1 ; NULL != argv [i ]; i ++ ) {
127
+ opal_argv_append_nosize (& prterun_args , argv [i ]);
128
+ }
129
+ ret = execv (full_prterun_path , prterun_args );
130
+ opal_show_help ("help-mpirun.txt" , "prterun-exec-failed" ,
131
+ 1 , full_prterun_path , strerror (errno ));
111
132
exit (1 );
112
133
}
113
134
@@ -125,6 +146,7 @@ int main(int argc, char *argv[])
125
146
* Copyright (c) 2017-2020 Intel, Inc. All rights reserved.
126
147
* Copyright (c) 2020 Cisco Systems, Inc. All rights reserved.
127
148
* Copyright (c) 2021 Nanook Consulting. All rights reserved.
149
+ * Copyright (c) 2022 Amazon.com, Inc. or its affiliates. All Rights reserved.
128
150
* $COPYRIGHT$
129
151
*
130
152
* Additional copyrights may follow
0 commit comments