|
| 1 | +/* |
| 2 | + * Copyright (c) 2016-2017 Intel, Inc. All rights reserved. |
| 3 | + * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved. |
| 4 | + * Copyright (c) 2017-2019 IBM Corporation. All rights reserved. |
| 5 | + * $COPYRIGHT$ |
| 6 | + * |
| 7 | + * Additional copyrights may follow |
| 8 | + * |
| 9 | + * $HEADER$ |
| 10 | + * |
| 11 | + */ |
| 12 | + |
| 13 | +#include "orte_config.h" |
| 14 | +#include "orte/types.h" |
| 15 | +#include "opal/types.h" |
| 16 | + |
| 17 | +#ifdef HAVE_UNISTD_H |
| 18 | +#include <unistd.h> |
| 19 | +#endif |
| 20 | +#include <ctype.h> |
| 21 | + |
| 22 | +#include "opal/util/argv.h" |
| 23 | +#include "opal/util/basename.h" |
| 24 | +#include "opal/util/opal_environ.h" |
| 25 | + |
| 26 | +#include "orte/runtime/orte_globals.h" |
| 27 | +#include "orte/util/name_fns.h" |
| 28 | +#include "orte/mca/schizo/base/base.h" |
| 29 | + |
| 30 | +#include "schizo_jsm.h" |
| 31 | + |
| 32 | +static orte_schizo_launch_environ_t check_launch_environment(void); |
| 33 | +static void finalize(void); |
| 34 | + |
| 35 | +orte_schizo_base_module_t orte_schizo_jsm_module = { |
| 36 | + .check_launch_environment = check_launch_environment, |
| 37 | + .finalize = finalize |
| 38 | +}; |
| 39 | + |
| 40 | +static char **pushed_envs = NULL; |
| 41 | +static char **pushed_vals = NULL; |
| 42 | +static orte_schizo_launch_environ_t myenv; |
| 43 | +static bool myenvdefined = false; |
| 44 | + |
| 45 | +static orte_schizo_launch_environ_t check_launch_environment(void) |
| 46 | +{ |
| 47 | + int i; |
| 48 | + |
| 49 | + if (myenvdefined) { |
| 50 | + return myenv; |
| 51 | + } |
| 52 | + myenvdefined = true; |
| 53 | + |
| 54 | + /* we were only selected because JSM was detected |
| 55 | + * and we are an app, so no need to further check |
| 56 | + * that here. Instead, see if we were direct launched |
| 57 | + * vs launched via mpirun ('native') */ |
| 58 | + if (NULL != orte_process_info.my_daemon_uri) { |
| 59 | + /* Use PMI(x) for daemon interactions */ |
| 60 | + myenv = ORTE_SCHIZO_NATIVE_LAUNCHED; |
| 61 | + opal_argv_append_nosize(&pushed_envs, OPAL_MCA_PREFIX"ess"); |
| 62 | + opal_argv_append_nosize(&pushed_vals, "pmi"); |
| 63 | + /* mark that we are native */ |
| 64 | + opal_argv_append_nosize(&pushed_envs, "ORTE_SCHIZO_DETECTION"); |
| 65 | + opal_argv_append_nosize(&pushed_vals, "NATIVE"); |
| 66 | + } |
| 67 | + else { |
| 68 | + /* Use PMI(x) for daemon interactions */ |
| 69 | + myenv = ORTE_SCHIZO_DIRECT_LAUNCHED; |
| 70 | + opal_argv_append_nosize(&pushed_envs, OPAL_MCA_PREFIX"ess"); |
| 71 | + opal_argv_append_nosize(&pushed_vals, "pmi"); |
| 72 | + /* mark that we are JSM */ |
| 73 | + opal_argv_append_nosize(&pushed_envs, "ORTE_SCHIZO_DETECTION"); |
| 74 | + opal_argv_append_nosize(&pushed_vals, "JSM"); |
| 75 | + } |
| 76 | + |
| 77 | + /* We don't support singleton launch by JSM. |
| 78 | + * If we did then the logic should be placed here. |
| 79 | + */ |
| 80 | + |
| 81 | + opal_output_verbose(1, orte_schizo_base_framework.framework_output, |
| 82 | + "schizo:jsm DECLARED AS %s", orte_schizo_base_print_env(myenv)); |
| 83 | + if (NULL != pushed_envs) { |
| 84 | + for (i=0; NULL != pushed_envs[i]; i++) { |
| 85 | + opal_setenv(pushed_envs[i], pushed_vals[i], true, &environ); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + return myenv; |
| 90 | +} |
| 91 | + |
| 92 | + |
| 93 | +static void finalize(void) |
| 94 | +{ |
| 95 | + int i; |
| 96 | + |
| 97 | + if (NULL != pushed_envs) { |
| 98 | + for (i=0; NULL != pushed_envs[i]; i++) { |
| 99 | + opal_unsetenv(pushed_envs[i], &environ); |
| 100 | + } |
| 101 | + opal_argv_free(pushed_envs); |
| 102 | + opal_argv_free(pushed_vals); |
| 103 | + } |
| 104 | +} |
0 commit comments