root/orte/util/name_fns.c

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

DEFINITIONS

This source file includes following definitions.
  1. orte_namelist_construct
  2. orte_namelist_destructor
  3. buffer_cleanup
  4. get_print_name_buffer
  5. orte_util_print_name_args
  6. orte_util_print_jobids
  7. orte_util_print_job_family
  8. orte_util_print_local_jobid
  9. orte_util_print_vpids
  10. orte_util_snprintf_jobid
  11. orte_util_convert_jobid_to_string
  12. orte_util_convert_string_to_jobid
  13. orte_util_convert_vpid_to_string
  14. orte_util_convert_string_to_vpid
  15. orte_util_convert_string_to_process_name
  16. orte_util_convert_process_name_to_string
  17. orte_util_create_process_name
  18. orte_util_compare_name_fields
  19. orte_util_hash_vpid
  20. orte_util_convert_string_to_sysinfo
  21. orte_util_convert_sysinfo_to_string
  22. orte_pretty_print_timing

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2011 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2010      Oracle and/or its affiliates.  All rights reserved.
  13  * Copyright (c) 2014-2016 Research Organization for Information Science
  14  *                         and Technology (RIST). All rights reserved.
  15  * Copyright (c) 2016-2018 Intel, Inc.  All rights reserved.
  16  * Copyright (c) 2018      Cisco Systems, Inc.  All rights reserved
  17  * $COPYRIGHT$
  18  *
  19  * Additional copyrights may follow
  20  *
  21  * $HEADER$
  22  */
  23 #include "orte_config.h"
  24 #include "orte/types.h"
  25 #include "orte/constants.h"
  26 
  27 #include <stdio.h>
  28 #include <string.h>
  29 
  30 #include "opal/util/printf.h"
  31 #include "opal/util/string_copy.h"
  32 #include "opal/threads/tsd.h"
  33 
  34 #include "orte/mca/errmgr/errmgr.h"
  35 
  36 #include "orte/util/name_fns.h"
  37 
  38 #define ORTE_PRINT_NAME_ARGS_MAX_SIZE   50
  39 #define ORTE_PRINT_NAME_ARG_NUM_BUFS    16
  40 
  41 #define ORTE_SCHEMA_DELIMITER_CHAR      '.'
  42 #define ORTE_SCHEMA_WILDCARD_CHAR       '*'
  43 #define ORTE_SCHEMA_WILDCARD_STRING     "*"
  44 #define ORTE_SCHEMA_INVALID_CHAR        '$'
  45 #define ORTE_SCHEMA_INVALID_STRING      "$"
  46 
  47 /* constructor - used to initialize namelist instance */
  48 static void orte_namelist_construct(orte_namelist_t* list)
  49 {
  50     list->name.jobid = ORTE_JOBID_INVALID;
  51     list->name.vpid = ORTE_VPID_INVALID;
  52 }
  53 
  54 /* destructor - used to free any resources held by instance */
  55 static void orte_namelist_destructor(orte_namelist_t* list)
  56 {
  57 }
  58 
  59 /* define instance of opal_class_t */
  60 OBJ_CLASS_INSTANCE(orte_namelist_t,              /* type name */
  61                    opal_list_item_t,             /* parent "class" name */
  62                    orte_namelist_construct,      /* constructor */
  63                    orte_namelist_destructor);    /* destructor */
  64 
  65 static bool fns_init=false;
  66 
  67 static opal_tsd_key_t print_args_tsd_key;
  68 char* orte_print_args_null = "NULL";
  69 typedef struct {
  70     char *buffers[ORTE_PRINT_NAME_ARG_NUM_BUFS];
  71     int cntr;
  72 } orte_print_args_buffers_t;
  73 
  74 static void
  75 buffer_cleanup(void *value)
  76 {
  77     int i;
  78     orte_print_args_buffers_t *ptr;
  79 
  80     if (NULL != value) {
  81         ptr = (orte_print_args_buffers_t*)value;
  82         for (i=0; i < ORTE_PRINT_NAME_ARG_NUM_BUFS; i++) {
  83             free(ptr->buffers[i]);
  84         }
  85         free (ptr);
  86     }
  87 }
  88 
  89 static orte_print_args_buffers_t*
  90 get_print_name_buffer(void)
  91 {
  92     orte_print_args_buffers_t *ptr;
  93     int ret, i;
  94 
  95     if (!fns_init) {
  96         /* setup the print_args function */
  97         if (ORTE_SUCCESS != (ret = opal_tsd_key_create(&print_args_tsd_key, buffer_cleanup))) {
  98             ORTE_ERROR_LOG(ret);
  99             return NULL;
 100         }
 101         fns_init = true;
 102     }
 103 
 104     ret = opal_tsd_getspecific(print_args_tsd_key, (void**)&ptr);
 105     if (OPAL_SUCCESS != ret) return NULL;
 106 
 107     if (NULL == ptr) {
 108         ptr = (orte_print_args_buffers_t*)malloc(sizeof(orte_print_args_buffers_t));
 109         for (i=0; i < ORTE_PRINT_NAME_ARG_NUM_BUFS; i++) {
 110             ptr->buffers[i] = (char *) malloc((ORTE_PRINT_NAME_ARGS_MAX_SIZE+1) * sizeof(char));
 111         }
 112         ptr->cntr = 0;
 113         ret = opal_tsd_setspecific(print_args_tsd_key, (void*)ptr);
 114     }
 115 
 116     return (orte_print_args_buffers_t*) ptr;
 117 }
 118 
 119 char* orte_util_print_name_args(const orte_process_name_t *name)
 120 {
 121     orte_print_args_buffers_t *ptr;
 122     char *job, *vpid;
 123 
 124     /* protect against NULL names */
 125     if (NULL == name) {
 126         /* get the next buffer */
 127         ptr = get_print_name_buffer();
 128         if (NULL == ptr) {
 129             ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
 130             return orte_print_args_null;
 131         }
 132         /* cycle around the ring */
 133         if (ORTE_PRINT_NAME_ARG_NUM_BUFS == ptr->cntr) {
 134             ptr->cntr = 0;
 135         }
 136         snprintf(ptr->buffers[ptr->cntr++], ORTE_PRINT_NAME_ARGS_MAX_SIZE, "[NO-NAME]");
 137         return ptr->buffers[ptr->cntr-1];
 138     }
 139 
 140     /* get the jobid, vpid strings first - this will protect us from
 141      * stepping on each other's buffer. This also guarantees
 142      * that the print_args function has been initialized, so
 143      * we don't need to duplicate that here
 144      */
 145     job = orte_util_print_jobids(name->jobid);
 146     vpid = orte_util_print_vpids(name->vpid);
 147 
 148     /* get the next buffer */
 149     ptr = get_print_name_buffer();
 150 
 151     if (NULL == ptr) {
 152         ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
 153         return orte_print_args_null;
 154     }
 155 
 156     /* cycle around the ring */
 157     if (ORTE_PRINT_NAME_ARG_NUM_BUFS == ptr->cntr) {
 158         ptr->cntr = 0;
 159     }
 160 
 161     snprintf(ptr->buffers[ptr->cntr++],
 162              ORTE_PRINT_NAME_ARGS_MAX_SIZE,
 163              "[%s,%s]", job, vpid);
 164 
 165     return ptr->buffers[ptr->cntr-1];
 166 }
 167 
 168 char* orte_util_print_jobids(const orte_jobid_t job)
 169 {
 170     orte_print_args_buffers_t *ptr;
 171     unsigned long tmp1, tmp2;
 172 
 173     ptr = get_print_name_buffer();
 174 
 175     if (NULL == ptr) {
 176         ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
 177         return orte_print_args_null;
 178     }
 179 
 180     /* cycle around the ring */
 181     if (ORTE_PRINT_NAME_ARG_NUM_BUFS == ptr->cntr) {
 182         ptr->cntr = 0;
 183     }
 184 
 185     if (ORTE_JOBID_INVALID == job) {
 186         snprintf(ptr->buffers[ptr->cntr++], ORTE_PRINT_NAME_ARGS_MAX_SIZE, "[INVALID]");
 187     } else if (ORTE_JOBID_WILDCARD == job) {
 188         snprintf(ptr->buffers[ptr->cntr++], ORTE_PRINT_NAME_ARGS_MAX_SIZE, "[WILDCARD]");
 189     } else {
 190         tmp1 = ORTE_JOB_FAMILY((unsigned long)job);
 191         tmp2 = ORTE_LOCAL_JOBID((unsigned long)job);
 192         snprintf(ptr->buffers[ptr->cntr++],
 193                  ORTE_PRINT_NAME_ARGS_MAX_SIZE,
 194                  "[%lu,%lu]", tmp1, tmp2);
 195     }
 196     return ptr->buffers[ptr->cntr-1];
 197 }
 198 
 199 char* orte_util_print_job_family(const orte_jobid_t job)
 200 {
 201     orte_print_args_buffers_t *ptr;
 202     unsigned long tmp1;
 203 
 204     ptr = get_print_name_buffer();
 205 
 206     if (NULL == ptr) {
 207         ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
 208         return orte_print_args_null;
 209     }
 210 
 211     /* cycle around the ring */
 212     if (ORTE_PRINT_NAME_ARG_NUM_BUFS == ptr->cntr) {
 213         ptr->cntr = 0;
 214     }
 215 
 216     if (ORTE_JOBID_INVALID == job) {
 217         snprintf(ptr->buffers[ptr->cntr++], ORTE_PRINT_NAME_ARGS_MAX_SIZE, "INVALID");
 218     } else if (ORTE_JOBID_WILDCARD == job) {
 219         snprintf(ptr->buffers[ptr->cntr++], ORTE_PRINT_NAME_ARGS_MAX_SIZE, "WILDCARD");
 220     } else {
 221         tmp1 = ORTE_JOB_FAMILY((unsigned long)job);
 222         snprintf(ptr->buffers[ptr->cntr++],
 223                  ORTE_PRINT_NAME_ARGS_MAX_SIZE,
 224                  "%lu", tmp1);
 225     }
 226     return ptr->buffers[ptr->cntr-1];
 227 }
 228 
 229 char* orte_util_print_local_jobid(const orte_jobid_t job)
 230 {
 231     orte_print_args_buffers_t *ptr;
 232     unsigned long tmp1;
 233 
 234     ptr = get_print_name_buffer();
 235 
 236     if (NULL == ptr) {
 237         ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
 238         return orte_print_args_null;
 239     }
 240 
 241     /* cycle around the ring */
 242     if (ORTE_PRINT_NAME_ARG_NUM_BUFS == ptr->cntr) {
 243         ptr->cntr = 0;
 244     }
 245 
 246     if (ORTE_JOBID_INVALID == job) {
 247         snprintf(ptr->buffers[ptr->cntr++], ORTE_PRINT_NAME_ARGS_MAX_SIZE, "INVALID");
 248     } else if (ORTE_JOBID_WILDCARD == job) {
 249         snprintf(ptr->buffers[ptr->cntr++], ORTE_PRINT_NAME_ARGS_MAX_SIZE, "WILDCARD");
 250     } else {
 251         tmp1 = (unsigned long)job & 0x0000ffff;
 252         snprintf(ptr->buffers[ptr->cntr++],
 253                  ORTE_PRINT_NAME_ARGS_MAX_SIZE,
 254                  "%lu", tmp1);
 255     }
 256     return ptr->buffers[ptr->cntr-1];
 257 }
 258 
 259 char* orte_util_print_vpids(const orte_vpid_t vpid)
 260 {
 261     orte_print_args_buffers_t *ptr;
 262 
 263     ptr = get_print_name_buffer();
 264 
 265     if (NULL == ptr) {
 266         ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
 267         return orte_print_args_null;
 268     }
 269 
 270     /* cycle around the ring */
 271     if (ORTE_PRINT_NAME_ARG_NUM_BUFS == ptr->cntr) {
 272         ptr->cntr = 0;
 273     }
 274 
 275     if (ORTE_VPID_INVALID == vpid) {
 276         snprintf(ptr->buffers[ptr->cntr++], ORTE_PRINT_NAME_ARGS_MAX_SIZE, "INVALID");
 277     } else if (ORTE_VPID_WILDCARD == vpid) {
 278         snprintf(ptr->buffers[ptr->cntr++], ORTE_PRINT_NAME_ARGS_MAX_SIZE, "WILDCARD");
 279     } else {
 280         snprintf(ptr->buffers[ptr->cntr++],
 281                  ORTE_PRINT_NAME_ARGS_MAX_SIZE,
 282                  "%ld", (long)vpid);
 283     }
 284     return ptr->buffers[ptr->cntr-1];
 285 }
 286 
 287 
 288 
 289 /***   STRING FUNCTIONS   ***/
 290 
 291 int orte_util_snprintf_jobid(char *jobid_string, size_t size, const orte_jobid_t jobid)
 292 {
 293     int rc;
 294 
 295     /* check for wildcard value - handle appropriately */
 296     if (ORTE_JOBID_WILDCARD == jobid) {
 297         (void)opal_string_copy(jobid_string, ORTE_SCHEMA_WILDCARD_STRING, size);
 298     } else {
 299         rc = snprintf(jobid_string, size, "%ld", (long) jobid);
 300         if (0 > rc) {
 301             return ORTE_ERROR;
 302         }
 303     }
 304 
 305     return ORTE_SUCCESS;
 306 }
 307 
 308 int orte_util_convert_jobid_to_string(char **jobid_string, const orte_jobid_t jobid)
 309 {
 310     int rc;
 311     char str[256];
 312     rc = orte_util_snprintf_jobid(str, 255, jobid);
 313     if (0 > rc) {
 314         *jobid_string = NULL;
 315         return rc;
 316     }
 317     *jobid_string = strdup(str);
 318     if (NULL == *jobid_string) {
 319         ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
 320         return ORTE_ERR_OUT_OF_RESOURCE;
 321     }
 322     return ORTE_SUCCESS;
 323 }
 324 
 325 
 326 int orte_util_convert_string_to_jobid(orte_jobid_t *jobid, const char* jobidstring)
 327 {
 328     if (NULL == jobidstring) {  /* got an error */
 329         ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM);
 330         *jobid = ORTE_JOBID_INVALID;
 331         return ORTE_ERR_BAD_PARAM;
 332     }
 333 
 334     /** check for wildcard character - handle appropriately */
 335     if (0 == strcmp(ORTE_SCHEMA_WILDCARD_STRING, jobidstring)) {
 336         *jobid = ORTE_JOBID_WILDCARD;
 337         return ORTE_SUCCESS;
 338     }
 339 
 340     /* check for invalid value */
 341     if (0 == strcmp(ORTE_SCHEMA_INVALID_STRING, jobidstring)) {
 342         *jobid = ORTE_JOBID_INVALID;
 343         return ORTE_SUCCESS;
 344     }
 345 
 346     *jobid = strtoul(jobidstring, NULL, 10);
 347 
 348     return ORTE_SUCCESS;
 349 }
 350 
 351 int orte_util_convert_vpid_to_string(char **vpid_string, const orte_vpid_t vpid)
 352 {
 353     /* check for wildcard value - handle appropriately */
 354     if (ORTE_VPID_WILDCARD == vpid) {
 355         *vpid_string = strdup(ORTE_SCHEMA_WILDCARD_STRING);
 356         return ORTE_SUCCESS;
 357     }
 358 
 359     /* check for invalid value - handle appropriately */
 360     if (ORTE_VPID_INVALID == vpid) {
 361         *vpid_string = strdup(ORTE_SCHEMA_INVALID_STRING);
 362         return ORTE_SUCCESS;
 363     }
 364 
 365     if (0 > opal_asprintf(vpid_string, "%ld", (long) vpid)) {
 366         ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
 367         return ORTE_ERR_OUT_OF_RESOURCE;
 368     }
 369 
 370     return ORTE_SUCCESS;
 371 }
 372 
 373 
 374 int orte_util_convert_string_to_vpid(orte_vpid_t *vpid, const char* vpidstring)
 375 {
 376     if (NULL == vpidstring) {  /* got an error */
 377         ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM);
 378         *vpid = ORTE_VPID_INVALID;
 379         return ORTE_ERR_BAD_PARAM;
 380     }
 381 
 382     /** check for wildcard character - handle appropriately */
 383     if (0 == strcmp(ORTE_SCHEMA_WILDCARD_STRING, vpidstring)) {
 384         *vpid = ORTE_VPID_WILDCARD;
 385         return ORTE_SUCCESS;
 386     }
 387 
 388     /* check for invalid value */
 389     if (0 == strcmp(ORTE_SCHEMA_INVALID_STRING, vpidstring)) {
 390         *vpid = ORTE_VPID_INVALID;
 391         return ORTE_SUCCESS;
 392     }
 393 
 394     *vpid = strtol(vpidstring, NULL, 10);
 395 
 396     return ORTE_SUCCESS;
 397 }
 398 
 399 int orte_util_convert_string_to_process_name(orte_process_name_t *name,
 400                                              const char* name_string)
 401 {
 402     char *temp, *token;
 403     orte_jobid_t job;
 404     orte_vpid_t vpid;
 405     int return_code=ORTE_SUCCESS;
 406 
 407     /* set default */
 408     name->jobid = ORTE_JOBID_INVALID;
 409     name->vpid = ORTE_VPID_INVALID;
 410 
 411     /* check for NULL string - error */
 412     if (NULL == name_string) {
 413         ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM);
 414         return ORTE_ERR_BAD_PARAM;
 415     }
 416 
 417     temp = strdup(name_string);  /** copy input string as the strtok process is destructive */
 418     token = strchr(temp, ORTE_SCHEMA_DELIMITER_CHAR); /** get first field -> jobid */
 419 
 420     /* check for error */
 421     if (NULL == token) {
 422         ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM);
 423         free(temp);
 424         return ORTE_ERR_BAD_PARAM;
 425     }
 426     *token = '\0';
 427     token++;
 428 
 429     /* check for WILDCARD character - assign
 430      * value accordingly, if found
 431      */
 432     if (0 == strcmp(temp, ORTE_SCHEMA_WILDCARD_STRING)) {
 433         job = ORTE_JOBID_WILDCARD;
 434     } else if (0 == strcmp(temp, ORTE_SCHEMA_INVALID_STRING)) {
 435         job = ORTE_JOBID_INVALID;
 436     } else {
 437         job = strtoul(temp, NULL, 10);
 438     }
 439 
 440     /* check for WILDCARD character - assign
 441      * value accordingly, if found
 442      */
 443     if (0 == strcmp(token, ORTE_SCHEMA_WILDCARD_STRING)) {
 444         vpid = ORTE_VPID_WILDCARD;
 445     } else if (0 == strcmp(token, ORTE_SCHEMA_INVALID_STRING)) {
 446         vpid = ORTE_VPID_INVALID;
 447     } else {
 448         vpid = strtoul(token, NULL, 10);
 449     }
 450 
 451     name->jobid = job;
 452     name->vpid = vpid;
 453 
 454     free(temp);
 455 
 456     return return_code;
 457 }
 458 
 459 int orte_util_convert_process_name_to_string(char **name_string,
 460                                              const orte_process_name_t* name)
 461 {
 462     char *tmp, *tmp2;
 463 
 464     if (NULL == name) { /* got an error */
 465         ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM);
 466         return ORTE_ERR_BAD_PARAM;
 467     }
 468 
 469     /* check for wildcard and invalid values - where encountered, insert the
 470      * corresponding string so we can correctly parse the name string when
 471      * it is passed back to us later
 472      */
 473     if (ORTE_JOBID_WILDCARD == name->jobid) {
 474         opal_asprintf(&tmp, "%s", ORTE_SCHEMA_WILDCARD_STRING);
 475     } else if (ORTE_JOBID_INVALID == name->jobid) {
 476         opal_asprintf(&tmp, "%s", ORTE_SCHEMA_INVALID_STRING);
 477     } else {
 478         opal_asprintf(&tmp, "%lu", (unsigned long)name->jobid);
 479     }
 480 
 481     if (ORTE_VPID_WILDCARD == name->vpid) {
 482         opal_asprintf(&tmp2, "%s%c%s", tmp, ORTE_SCHEMA_DELIMITER_CHAR, ORTE_SCHEMA_WILDCARD_STRING);
 483     } else if (ORTE_VPID_INVALID == name->vpid) {
 484         opal_asprintf(&tmp2, "%s%c%s", tmp, ORTE_SCHEMA_DELIMITER_CHAR, ORTE_SCHEMA_INVALID_STRING);
 485     } else {
 486         opal_asprintf(&tmp2, "%s%c%lu", tmp, ORTE_SCHEMA_DELIMITER_CHAR, (unsigned long)name->vpid);
 487     }
 488 
 489     opal_asprintf(name_string, "%s", tmp2);
 490 
 491     free(tmp);
 492     free(tmp2);
 493 
 494     return ORTE_SUCCESS;
 495 }
 496 
 497 
 498 /****    CREATE PROCESS NAME    ****/
 499 int orte_util_create_process_name(orte_process_name_t **name,
 500                                   orte_jobid_t job,
 501                                   orte_vpid_t vpid
 502                                   )
 503 {
 504     *name = NULL;
 505 
 506     *name = (orte_process_name_t*)malloc(sizeof(orte_process_name_t));
 507     if (NULL == *name) { /* got an error */
 508         ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
 509         return ORTE_ERR_OUT_OF_RESOURCE;
 510     }
 511 
 512     (*name)->jobid = job;
 513     (*name)->vpid = vpid;
 514 
 515     return ORTE_SUCCESS;
 516 }
 517 
 518 /****    COMPARE NAME FIELDS     ****/
 519 int orte_util_compare_name_fields(orte_ns_cmp_bitmask_t fields,
 520                                   const orte_process_name_t* name1,
 521                                   const orte_process_name_t* name2)
 522 {
 523     /* handle the NULL pointer case */
 524     if (NULL == name1 && NULL == name2) {
 525         return OPAL_EQUAL;
 526     } else if (NULL == name1) {
 527         return OPAL_VALUE2_GREATER;
 528     } else if (NULL == name2) {
 529         return OPAL_VALUE1_GREATER;
 530     }
 531 
 532     /* in this comparison function, we check for exact equalities.
 533      * In the case of wildcards, we check to ensure that the fields
 534      * actually match those values - thus, a "wildcard" in this
 535      * function does not actually stand for a wildcard value, but
 536      * rather a specific value - UNLESS the CMP_WILD bitmask value
 537      * is set
 538      */
 539 
 540     /* check job id */
 541     if (ORTE_NS_CMP_JOBID & fields) {
 542         if (ORTE_NS_CMP_WILD & fields &&
 543             (ORTE_JOBID_WILDCARD == name1->jobid ||
 544              ORTE_JOBID_WILDCARD == name2->jobid)) {
 545             goto check_vpid;
 546         }
 547         if (name1->jobid < name2->jobid) {
 548             return OPAL_VALUE2_GREATER;
 549         } else if (name1->jobid > name2->jobid) {
 550             return OPAL_VALUE1_GREATER;
 551         }
 552     }
 553 
 554     /* get here if jobid's are equal, or not being checked
 555      * now check vpid
 556      */
 557  check_vpid:
 558     if (ORTE_NS_CMP_VPID & fields) {
 559         if (ORTE_NS_CMP_WILD & fields &&
 560             (ORTE_VPID_WILDCARD == name1->vpid ||
 561              ORTE_VPID_WILDCARD == name2->vpid)) {
 562             return OPAL_EQUAL;
 563         }
 564         if (name1->vpid < name2->vpid) {
 565             return OPAL_VALUE2_GREATER;
 566         } else if (name1->vpid > name2->vpid) {
 567             return OPAL_VALUE1_GREATER;
 568         }
 569     }
 570 
 571     /* only way to get here is if all fields are being checked and are equal,
 572     * or jobid not checked, but vpid equal,
 573     * only vpid being checked, and equal
 574     * return that fact
 575     */
 576     return OPAL_EQUAL;
 577 }
 578 
 579 /* hash a vpid based on Robert Jenkin's algorithm - note
 580  * that the precise values of the constants in the algo are
 581  * irrelevant.
 582  */
 583 uint32_t  orte_util_hash_vpid(orte_vpid_t vpid) {
 584     uint32_t hash;
 585 
 586     hash = vpid;
 587     hash = (hash + 0x7ed55d16) + (hash<<12);
 588     hash = (hash ^ 0xc761c23c) ^ (hash>>19);
 589     hash = (hash + 0x165667b1) + (hash<<5);
 590     hash = (hash + 0xd3a2646c) ^ (hash<<9);
 591     hash = (hash + 0xfd7046c5) + (hash<<3);
 592     hash = (hash ^ 0xb55a4f09) ^ (hash>>16);
 593     return hash;
 594 }
 595 
 596 /* sysinfo conversion to and from string */
 597 int orte_util_convert_string_to_sysinfo(char **cpu_type, char **cpu_model,
 598                                         const char* sysinfo_string)
 599 {
 600     char *temp, *token;
 601     int return_code=ORTE_SUCCESS;
 602 
 603     /* check for NULL string - error */
 604     if (NULL == sysinfo_string) {
 605         ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM);
 606         return ORTE_ERR_BAD_PARAM;
 607     }
 608 
 609     temp = strdup(sysinfo_string);  /** copy input string as the strtok process is destructive */
 610     token = strchr(temp, ORTE_SCHEMA_DELIMITER_CHAR); /** get first field -> cpu_type */
 611 
 612     /* check for error */
 613     if (NULL == token) {
 614         free(temp);
 615         ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM);
 616         return ORTE_ERR_BAD_PARAM;
 617     }
 618     *token = '\0';
 619     token++;
 620 
 621     /* If type is a valid string get the value otherwise leave cpu_type untouched.
 622      */
 623     if (0 != strcmp(temp, ORTE_SCHEMA_INVALID_STRING)) {
 624         *cpu_type = strdup(temp);
 625     }
 626 
 627     /* If type is a valid string get the value otherwise leave cpu_type untouched.
 628      */
 629     if (0 != strcmp(token, ORTE_SCHEMA_INVALID_STRING)) {
 630         *cpu_model = strdup(token);
 631     }
 632 
 633     free(temp);
 634 
 635     return return_code;
 636 }
 637 
 638 int orte_util_convert_sysinfo_to_string(char **sysinfo_string,
 639                                         const char *cpu_type, const char *cpu_model)
 640 {
 641     char *tmp;
 642 
 643     /* check for no sysinfo values (like empty cpu_type) - where encountered, insert the
 644      * invalid string so we can correctly parse the name string when
 645      * it is passed back to us later
 646      */
 647     if (NULL == cpu_type) {
 648         opal_asprintf(&tmp, "%s", ORTE_SCHEMA_INVALID_STRING);
 649     } else {
 650         opal_asprintf(&tmp, "%s", cpu_type);
 651     }
 652 
 653     if (NULL == cpu_model) {
 654         opal_asprintf(sysinfo_string, "%s%c%s", tmp, ORTE_SCHEMA_DELIMITER_CHAR, ORTE_SCHEMA_INVALID_STRING);
 655     } else {
 656         opal_asprintf(sysinfo_string, "%s%c%s", tmp, ORTE_SCHEMA_DELIMITER_CHAR, cpu_model);
 657     }
 658     free(tmp);
 659     return ORTE_SUCCESS;
 660 }
 661 
 662 char *orte_pretty_print_timing(int64_t secs, int64_t usecs)
 663 {
 664     unsigned long minutes, seconds;
 665     float fsecs;
 666     char *timestring;
 667 
 668     seconds = secs + (usecs / 1000000l);
 669     minutes = seconds / 60l;
 670     seconds = seconds % 60l;
 671     if (0 == minutes && 0 == seconds) {
 672         fsecs = ((float)(secs)*1000000.0 + (float)usecs) / 1000.0;
 673         opal_asprintf(&timestring, "%8.2f millisecs", fsecs);
 674     } else {
 675         opal_asprintf(&timestring, "%3lu:%02lu min:sec", minutes, seconds);
 676     }
 677 
 678     return timestring;
 679 }

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