1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
/***************************************************************************
* *
* Open MPI: Open Source High Performance Computing *
* *
* https://www.open-mpi.org/ *
* *
***************************************************************************/
#include "ompi_config.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#if HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif /* HAVE_SYS_STAT_H */
#include <string.h>
#include "opal/mca/base/base.h"
#include "opal/mca/installdirs/base/base.h"
#include "opal/runtime/opal.h"
#include "opal/util/argv.h"
#include "opal/util/basename.h"
#include "opal/util/opal_environ.h"
#include "opal/util/os_dirpath.h"
#include "opal/util/os_path.h"
#include "opal/util/path.h"
#include "opal/util/printf.h"
#include "opal/util/show_help.h"
#include "ompi/constants.h"
static char *find_prterun(void)
{
char *filename = NULL;
#if !OMPI_USING_INTERNAL_PRRTE
char *prrte_prefix = NULL;
#endif
/* 1) Did the user tell us exactly where to find prterun? */
filename = getenv("OMPI_PRTERUN");
if (NULL != filename) {
return filename;
}
#if OMPI_USING_INTERNAL_PRRTE
/* 2) If using internal PRRTE, use our bindir. Note that this
* will obey OPAL_PREFIX and OPAL_DESTDIR */
opal_asprintf(&filename, "%s%sprterun", opal_install_dirs.bindir, OPAL_PATH_SEP);
return filename;
#else
/* 3) Look in ${PRTE_PREFIX}/bin */
prrte_prefix = getenv("PRTE_PREFIX");
if (NULL != prrte_prefix) {
opal_asprintf(&filename, "%s%sbin%sprterun", prrte_prefix, OPAL_PATH_SEP, OPAL_PATH_SEP);
return filename;
}
/* 4) See if configure told us where to look, if set */
#if defined(OMPI_PRTERUN_PATH)
return strdup(OMPI_PRTERUN_PATH);
#else
/* 5) Use path search */
filename = opal_find_absolute_path("prterun");
return filename;
#endif
#endif
}
static void append_prefixes(char ***out, const char *in)
{
if (NULL == in) {
return;
}
char **tokenized;
tokenized = opal_argv_split(in, ' ');
if (NULL == tokenized) {
return;
}
int count = opal_argv_count(*out);
for (int i = 0; tokenized[i] != NULL; ++i) {
// Skip adding the names "common" and "pmix" to the list
if (strcmp(tokenized[i], "common") == 0 ||
strcmp(tokenized[i], "pmix") == 0) {
continue;
}
opal_argv_append(&count, out, tokenized[i]);
}
opal_argv_free(tokenized);
}
static void setup_mca_prefixes(void)
{
int count = 0;
char **tmp = NULL;
opal_argv_append(&count, &tmp, "mca");
opal_argv_append(&count, &tmp, "opal");
opal_argv_append(&count, &tmp, "ompi");
append_prefixes(&tmp, MCA_oshmem_FRAMEWORKS);
append_prefixes(&tmp, MCA_ompi_FRAMEWORKS);
append_prefixes(&tmp, MCA_opal_FRAMEWORKS);
char *env_str = opal_argv_join(tmp, ',');
opal_setenv("OMPI_MCA_PREFIXES", env_str, true,
&environ);
free(env_str);
opal_argv_free(tmp);
}
int main(int argc, char *argv[])
{
char *opal_prefix = getenv("OPAL_PREFIX");
char *full_prterun_path = NULL;
char **prterun_args = NULL;
int ret;
size_t i;
ret = opal_init_util(&argc, &argv);
if (OMPI_SUCCESS != ret) {
fprintf(stderr, "Failed initializing opal: %d\n", ret);
exit(1);
}
/* note that we just modify our environment rather than create a
* child environment because it is easier and we're not going to
* be around long enough for it to matter (since we exec prterun
* asap */
setenv("PRTE_MCA_schizo_proxy", "ompi", 1);
setenv("OMPI_VERSION", OMPI_VERSION, 1);
char *base_tool_name = opal_basename(argv[0]);
setenv("OMPI_TOOL_NAME", base_tool_name, 1);
free(base_tool_name);
/* TODO: look for --prefix and compare with OPAL_PREFIX and pick
* one */
/* as a special case, if OPAL_PREFIX was set and either PRRTE or
* PMIx are internal builds, set their prefix variables as well */
if (NULL != opal_prefix) {
#if OMPI_USING_INTERNAL_PRRTE
setenv("PRTE_PREFIX", opal_prefix, 1);
#endif
#if OPAL_USING_INTERNAL_PMIX
setenv("PMIX_PREFIX", opal_prefix, 1);
#endif
}
full_prterun_path = find_prterun();
if (NULL == full_prterun_path) {
opal_show_help("help-mpirun.txt", "no-prterun-found", 1);
exit(1);
}
/*
* set environment variable for our install location
* used within the OMPI prrte schizo component
*/
setenv("OMPI_LIBDIR_LOC", opal_install_dirs.libdir, 1);
// Set environment variable to tell PRTE what MCA prefixes belong
// to Open MPI.
setup_mca_prefixes();
/* calling mpirun (and now prterun) with a full path has a special
* meaning in terms of -prefix behavior, so copy that behavior
* into prterun */
if (opal_path_is_absolute(argv[0])) {
opal_argv_append_nosize(&prterun_args, full_prterun_path);
} else {
opal_argv_append_nosize(&prterun_args, "prterun");
}
/* Copy all the mpirun arguments to prterun.
* TODO: Need to handle --prefix rationally here. */
for (i = 1; NULL != argv[i]; i++) {
opal_argv_append_nosize(&prterun_args, argv[i]);
}
ret = execv(full_prterun_path, prterun_args);
opal_show_help("help-mpirun.txt", "prterun-exec-failed",
1, full_prterun_path, strerror(errno));
exit(1);
}
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2017-2020 Intel, Inc. All rights reserved.
* Copyright (c) 2020-2022 Cisco Systems, Inc. All rights reserved
* Copyright (c) 2021 Nanook Consulting. All rights reserved.
* Copyright (c) 2022 Amazon.com, Inc. or its affiliates. All Rights reserved.
* Copyright (c) 2022 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
|