root/opal/util/proc.c

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

DEFINITIONS

This source file includes following definitions.
  1. opal_proc_construct
  2. opal_proc_destruct
  3. opal_compare_opal_procs
  4. opal_proc_local_get
  5. opal_proc_local_set
  6. opal_proc_set_name
  7. opal_process_name_print_should_never_be_called
  8. opal_vpid_print_should_never_be_called
  9. opal_jobid_print_should_never_be_called
  10. opal_convert_string_to_process_name_should_never_be_called
  11. opal_convert_process_name_to_string_should_never_be_called
  12. opal_snprintf_jobid_should_never_be_called
  13. opal_convert_string_to_jobid_should_never_be_called
  14. opal_proc_for_name_should_never_be_called
  15. opal_get_proc_hostname

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2013      The University of Tennessee and The University
   4  *                         of Tennessee Research Foundation.  All rights
   5  *                         reserved.
   6  * Copyright (c) 2013      Inria.  All rights reserved.
   7  * Copyright (c) 2014-2017 Intel, Inc.  All rights reserved.
   8  * Copyright (c) 2014-2017 Research Organization for Information Science
   9  *                         and Technology (RIST). All rights reserved.
  10  * Copyright (c) 2015      Los Alamos National Security, LLC. All rights
  11  *                         reserved.
  12  * $COPYRIGHT$
  13  *
  14  * Additional copyrights may follow
  15  *
  16  * $HEADER$
  17  */
  18 
  19 #include "opal_config.h"
  20 
  21 #include "proc.h"
  22 #include "opal/util/proc.h"
  23 #include "opal/util/arch.h"
  24 #include "opal/util/string_copy.h"
  25 #include "opal/mca/pmix/pmix.h"
  26 
  27 opal_process_name_t opal_name_wildcard = {OPAL_JOBID_WILDCARD, OPAL_VPID_WILDCARD};
  28 opal_process_name_t opal_name_invalid = {OPAL_JOBID_INVALID, OPAL_VPID_INVALID};
  29 
  30 opal_process_info_t opal_process_info = {
  31     .nodename = NULL,
  32     .job_session_dir = NULL,
  33     .proc_session_dir = NULL,
  34     .num_local_peers = 0,  /* there is nobody else but me */
  35     .my_local_rank = 0,    /* I'm the only process around here */
  36     .cpuset = NULL,
  37 };
  38 
  39 static opal_proc_t opal_local_proc = {
  40     { .opal_list_next = NULL,
  41       .opal_list_prev = NULL},
  42     {OPAL_JOBID_INVALID, OPAL_VPID_INVALID},
  43     0,
  44     0,
  45     NULL,
  46     NULL
  47 };
  48 static opal_proc_t* opal_proc_my_name = &opal_local_proc;
  49 
  50 static void opal_proc_construct(opal_proc_t* proc)
  51 {
  52     proc->proc_arch = opal_local_arch;
  53     proc->proc_convertor = NULL;
  54     proc->proc_flags = 0;
  55     proc->proc_name = *OPAL_NAME_INVALID;
  56     proc->proc_hostname  = NULL;
  57 }
  58 
  59 static void opal_proc_destruct(opal_proc_t* proc)
  60 {
  61     proc->proc_flags     = 0;
  62     proc->proc_name      = *OPAL_NAME_INVALID;
  63     proc->proc_hostname  = NULL;
  64     proc->proc_convertor = NULL;
  65 }
  66 
  67 OBJ_CLASS_INSTANCE(opal_proc_t, opal_list_item_t,
  68                    opal_proc_construct, opal_proc_destruct);
  69 
  70 OBJ_CLASS_INSTANCE(opal_namelist_t, opal_list_item_t,
  71                    NULL, NULL);
  72 
  73 static int
  74 opal_compare_opal_procs(const opal_process_name_t p1,
  75                         const opal_process_name_t p2)
  76 {
  77     if( p1.jobid < p2.jobid ) {
  78         return  -1;
  79     }
  80     if( p1.jobid > p2.jobid ) {
  81         return  1;
  82     }
  83     if( p1.vpid <  p2.vpid ) {
  84         return -1;
  85     }
  86     if( p1.vpid >  p2.vpid ) {
  87         return 1;
  88     }
  89     return 0;
  90 }
  91 
  92 opal_compare_proc_fct_t opal_compare_proc = opal_compare_opal_procs;
  93 
  94 opal_proc_t* opal_proc_local_get(void)
  95 {
  96     return opal_proc_my_name;
  97 }
  98 
  99 int opal_proc_local_set(opal_proc_t* proc)
 100 {
 101     if( proc != opal_proc_my_name ) {
 102         if( NULL != proc )
 103             OBJ_RETAIN(proc);
 104         if( &opal_local_proc != opal_proc_my_name )
 105             OBJ_RELEASE(opal_proc_my_name);
 106         if( NULL != proc ) {
 107             opal_proc_my_name = proc;
 108         } else {
 109             opal_proc_my_name = &opal_local_proc;
 110         }
 111     }
 112     return OPAL_SUCCESS;
 113 }
 114 
 115 /* this function is used to temporarily set the local
 116  * name while OPAL and upper layers are initializing,
 117  * thus allowing debug messages to be more easily
 118  * understood */
 119 void opal_proc_set_name(opal_process_name_t *name)
 120 {
 121     /* to protect alignment, copy the name across */
 122     memcpy(&opal_local_proc.proc_name, name, sizeof(opal_process_name_t));
 123 }
 124 
 125 /**
 126  * The following functions are surrogates for the RTE functionality, and are not supposed
 127  * to be called. Instead, the corresponding function pointer should be set by the upper layer
 128  * before the call to opal_init, to make them point to the correct accessors based on the
 129  * underlying RTE.
 130  */
 131 static char*
 132 opal_process_name_print_should_never_be_called(const opal_process_name_t procname)
 133 {
 134     return "My Name is Nobody";
 135 }
 136 
 137 static char*
 138 opal_vpid_print_should_never_be_called(const opal_vpid_t unused)
 139 {
 140     return "My VPID";
 141 }
 142 
 143 static char*
 144 opal_jobid_print_should_never_be_called(const opal_jobid_t unused)
 145 {
 146     return "My JOBID";
 147 }
 148 
 149 static int opal_convert_string_to_process_name_should_never_be_called(opal_process_name_t *name,
 150                                                                       const char* name_string)
 151 {
 152     return OPAL_ERR_NOT_SUPPORTED;
 153 }
 154 
 155 static int opal_convert_process_name_to_string_should_never_be_called(char** name_string,
 156                                                                       const opal_process_name_t *name)
 157 {
 158     return OPAL_ERR_NOT_SUPPORTED;
 159 }
 160 
 161 static int opal_snprintf_jobid_should_never_be_called(char* name_string, size_t size, opal_jobid_t jobid)
 162 {
 163     (void)opal_string_copy(name_string, "My JOBID", size);
 164     return OPAL_SUCCESS;
 165 }
 166 
 167 static int opal_convert_string_to_jobid_should_never_be_called(opal_jobid_t *jobid, const char *jobid_string)
 168 {
 169     return OPAL_ERR_NOT_SUPPORTED;
 170 }
 171 
 172 static struct opal_proc_t *opal_proc_for_name_should_never_be_called (opal_process_name_t name)
 173 {
 174     return NULL;
 175 }
 176 
 177 char* (*opal_process_name_print)(const opal_process_name_t) = opal_process_name_print_should_never_be_called;
 178 char* (*opal_vpid_print)(const opal_vpid_t) = opal_vpid_print_should_never_be_called;
 179 char* (*opal_jobid_print)(const opal_jobid_t) = opal_jobid_print_should_never_be_called;
 180 int (*opal_convert_string_to_process_name)(opal_process_name_t *name, const char* name_string) = opal_convert_string_to_process_name_should_never_be_called;
 181 int (*opal_convert_process_name_to_string)(char** name_string, const opal_process_name_t *name) = opal_convert_process_name_to_string_should_never_be_called;
 182 int (*opal_snprintf_jobid)(char* name_string, size_t size, opal_jobid_t jobid) = opal_snprintf_jobid_should_never_be_called;
 183 int (*opal_convert_string_to_jobid)(opal_jobid_t *jobid, const char *jobid_string) = opal_convert_string_to_jobid_should_never_be_called;
 184 struct opal_proc_t *(*opal_proc_for_name) (const opal_process_name_t name) = opal_proc_for_name_should_never_be_called;
 185 
 186 char* opal_get_proc_hostname(const opal_proc_t *proc)
 187 {
 188     int ret;
 189 
 190     /* if the proc is NULL, then we can't know */
 191     if (NULL == proc) {
 192         return "unknown";
 193     }
 194 
 195     /* if it is my own hostname we are after, then just hand back
 196      * the value in opal_process_info */
 197     if (proc == opal_proc_my_name) {
 198         return opal_process_info.nodename;
 199     }
 200 
 201     /* see if we already have the data - if so, pass it back */
 202     if (NULL != proc->proc_hostname) {
 203         return proc->proc_hostname;
 204     }
 205 
 206     /* if we don't already have it, then try to get it */
 207     OPAL_MODEX_RECV_VALUE_OPTIONAL(ret, OPAL_PMIX_HOSTNAME, &proc->proc_name,
 208                                    (char**)&(proc->proc_hostname), OPAL_STRING);
 209     if (OPAL_SUCCESS != ret) {
 210         return "unknown";  // return something so the caller doesn't segfault
 211     }
 212 
 213     /* user is not allowed to release the data */
 214     return proc->proc_hostname;
 215 }

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