root/orte/mca/schizo/alps/schizo_alps.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. check_launch_environment
  2. finalize

   1 /*
   2  * Copyright (c) 2016-2017 Intel, Inc. All rights reserved.
   3  * $COPYRIGHT$
   4  *
   5  * Additional copyrights may follow
   6  *
   7  * $HEADER$
   8  *
   9  */
  10 
  11 #include "orte_config.h"
  12 #include "orte/types.h"
  13 #include "opal/types.h"
  14 
  15 #ifdef HAVE_UNISTD_H
  16 #include <unistd.h>
  17 #endif
  18 #include <ctype.h>
  19 #include <sys/syscall.h>
  20 
  21 #include "opal/util/argv.h"
  22 #include "opal/util/basename.h"
  23 #include "opal/util/opal_environ.h"
  24 
  25 #include "orte/runtime/orte_globals.h"
  26 #include "orte/util/name_fns.h"
  27 #include "orte/mca/schizo/base/base.h"
  28 
  29 #include "schizo_alps.h"
  30 
  31 static orte_schizo_launch_environ_t check_launch_environment(void);
  32 static void finalize(void);
  33 
  34 orte_schizo_base_module_t orte_schizo_alps_module = {
  35     .check_launch_environment = check_launch_environment,
  36     .finalize = finalize
  37 };
  38 
  39 static char **pushed_envs = NULL;
  40 static char **pushed_vals = NULL;
  41 static orte_schizo_launch_environ_t myenv;
  42 static bool myenvdefined = false;
  43 
  44 static orte_schizo_launch_environ_t check_launch_environment(void)
  45 {
  46     int i;
  47     const char proc_job_file[]="/proc/job";
  48     FILE *fd = NULL, *fd_task_is_app = NULL;
  49     char task_is_app_fname[PATH_MAX];
  50 
  51     if (myenvdefined) {
  52         return myenv;
  53     }
  54     myenvdefined = true;
  55 
  56     /* we were only selected because we are an app,
  57      * so no need to further check that here. Instead,
  58      * see if we were direct launched vs launched via mpirun */
  59     if (NULL != orte_process_info.my_daemon_uri) {
  60         /* nope */
  61         myenv = ORTE_SCHIZO_NATIVE_LAUNCHED;
  62         opal_argv_append_nosize(&pushed_envs, OPAL_MCA_PREFIX"ess");
  63         opal_argv_append_nosize(&pushed_vals, "pmi");
  64         /* do not try to bind when launched with aprun. there is a significant
  65          * launch performance penalty for hwloc at high ppn on knl */
  66         opal_argv_append_nosize(&pushed_envs, OPAL_MCA_PREFIX "orte_bound_at_launch");
  67         opal_argv_append_nosize(&pushed_vals, "true");
  68         /* mark that we are native */
  69         opal_argv_append_nosize(&pushed_envs, "ORTE_SCHIZO_DETECTION");
  70         opal_argv_append_nosize(&pushed_vals, "NATIVE");
  71         goto setup;
  72     }
  73 
  74     /* mark that we are on ALPS */
  75     opal_argv_append_nosize(&pushed_envs, "ORTE_SCHIZO_DETECTION");
  76     opal_argv_append_nosize(&pushed_vals, "ALPS");
  77 
  78     /* see if we are running in a Cray PAGG container */
  79     fd = fopen(proc_job_file, "r");
  80     if (NULL == fd) {
  81         /* we are a singleton */
  82         myenv = ORTE_SCHIZO_MANAGED_SINGLETON;
  83         opal_argv_append_nosize(&pushed_envs, OPAL_MCA_PREFIX"ess");
  84         opal_argv_append_nosize(&pushed_vals, "singleton");
  85     } else {
  86         if (NULL != orte_process_info.my_daemon_uri) {
  87             myenv = ORTE_SCHIZO_NATIVE_LAUNCHED;
  88         } else {
  89             myenv = ORTE_SCHIZO_DIRECT_LAUNCHED;
  90         }
  91         opal_argv_append_nosize(&pushed_envs, OPAL_MCA_PREFIX"ess");
  92         opal_argv_append_nosize(&pushed_vals, "pmi");
  93         snprintf(task_is_app_fname,sizeof(task_is_app_fname),
  94                  "/proc/self/task/%ld/task_is_app",syscall(SYS_gettid));
  95         fd_task_is_app = fopen(task_is_app_fname, "r");
  96         if (fd_task_is_app != NULL) {   /* okay we're in a PAGG container,
  97                                            and we are an app task (not just a process
  98                                            running on a mom node, for example) */
  99             opal_argv_append_nosize(&pushed_envs, OPAL_MCA_PREFIX"pmix");
 100             opal_argv_append_nosize(&pushed_vals, "cray");
 101         }
 102         fclose(fd);
 103     }
 104 
 105   setup:
 106     opal_output_verbose(1, orte_schizo_base_framework.framework_output,
 107                         "schizo:alps DECLARED AS %s", orte_schizo_base_print_env(myenv));
 108     if (NULL != pushed_envs) {
 109         for (i=0; NULL != pushed_envs[i]; i++) {
 110             opal_setenv(pushed_envs[i], pushed_vals[i], true, &environ);
 111         }
 112     }
 113 
 114     return myenv;
 115 }
 116 
 117 static void finalize(void)
 118 {
 119     int i;
 120 
 121     if (NULL != pushed_envs) {
 122         for (i=0; NULL != pushed_envs[i]; i++) {
 123             opal_unsetenv(pushed_envs[i], &environ);
 124         }
 125         opal_argv_free(pushed_envs);
 126         opal_argv_free(pushed_vals);
 127     }
 128 }

/* [<][>][^][v][top][bottom][index][help] */