root/orte/mca/rmaps/base/rmaps_base_print_fns.c

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

DEFINITIONS

This source file includes following definitions.
  1. buffer_cleanup
  2. get_print_buffer
  3. orte_rmaps_base_print_mapping
  4. orte_rmaps_base_print_ranking

   1 /*
   2  * Copyright (c) 2004-2010 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) 2011      Cisco Systems, Inc.  All rights reserved.
  13  * Copyright (c) 2018      Intel, Inc.  All rights reserved.
  14  * $COPYRIGHT$
  15  *
  16  * Additional copyrights may follow
  17  *
  18  * $HEADER$
  19  */
  20 
  21 #include "orte_config.h"
  22 #include "orte/constants.h"
  23 
  24 #include <sys/types.h>
  25 #ifdef HAVE_UNISTD_H
  26 #include <unistd.h>
  27 #endif  /* HAVE_UNISTD_H */
  28 #include <string.h>
  29 
  30 #include "opal/util/if.h"
  31 #include "opal/util/output.h"
  32 #include "orte/mca/mca.h"
  33 #include "opal/mca/base/base.h"
  34 #include "opal/mca/hwloc/base/base.h"
  35 #include "opal/threads/tsd.h"
  36 
  37 #include "orte/types.h"
  38 #include "orte/util/show_help.h"
  39 #include "orte/util/name_fns.h"
  40 #include "orte/runtime/orte_globals.h"
  41 #include "orte/util/hostfile/hostfile.h"
  42 #include "orte/util/dash_host/dash_host.h"
  43 #include "orte/mca/errmgr/errmgr.h"
  44 #include "orte/mca/ess/ess.h"
  45 #include "orte/runtime/data_type_support/orte_dt_support.h"
  46 
  47 #include "orte/mca/rmaps/base/rmaps_private.h"
  48 #include "orte/mca/rmaps/base/base.h"
  49 
  50 #define ORTE_RMAPS_PRINT_MAX_SIZE   50
  51 #define ORTE_RMAPS_PRINT_NUM_BUFS   16
  52 
  53 static bool fns_init=false;
  54 static opal_tsd_key_t print_tsd_key;
  55 static char* orte_rmaps_print_null = "NULL";
  56 typedef struct {
  57     char *buffers[ORTE_RMAPS_PRINT_NUM_BUFS];
  58     int cntr;
  59 } orte_rmaps_print_buffers_t;
  60 
  61 static void buffer_cleanup(void *value)
  62 {
  63     int i;
  64     orte_rmaps_print_buffers_t *ptr;
  65 
  66     if (NULL != value) {
  67         ptr = (orte_rmaps_print_buffers_t*)value;
  68         for (i=0; i < ORTE_RMAPS_PRINT_NUM_BUFS; i++) {
  69             free(ptr->buffers[i]);
  70         }
  71     }
  72 }
  73 
  74 static orte_rmaps_print_buffers_t *get_print_buffer(void)
  75 {
  76     orte_rmaps_print_buffers_t *ptr;
  77     int ret, i;
  78 
  79     if (!fns_init) {
  80         /* setup the print_args function */
  81         if (ORTE_SUCCESS != (ret = opal_tsd_key_create(&print_tsd_key, buffer_cleanup))) {
  82             ORTE_ERROR_LOG(ret);
  83             return NULL;
  84         }
  85         fns_init = true;
  86     }
  87 
  88     ret = opal_tsd_getspecific(print_tsd_key, (void**)&ptr);
  89     if (OPAL_SUCCESS != ret) return NULL;
  90 
  91     if (NULL == ptr) {
  92         ptr = (orte_rmaps_print_buffers_t*)malloc(sizeof(orte_rmaps_print_buffers_t));
  93         for (i=0; i < ORTE_RMAPS_PRINT_NUM_BUFS; i++) {
  94             ptr->buffers[i] = (char *) malloc((ORTE_RMAPS_PRINT_MAX_SIZE+1) * sizeof(char));
  95         }
  96         ptr->cntr = 0;
  97         ret = opal_tsd_setspecific(print_tsd_key, (void*)ptr);
  98     }
  99 
 100     return (orte_rmaps_print_buffers_t*) ptr;
 101 }
 102 
 103 char* orte_rmaps_base_print_mapping(orte_mapping_policy_t mapping)
 104 {
 105     char *ret, *map, *mymap, *tmp;
 106     orte_rmaps_print_buffers_t *ptr;
 107 
 108     if (ORTE_MAPPING_CONFLICTED & ORTE_GET_MAPPING_DIRECTIVE(mapping)) {
 109         return "CONFLICTED";
 110     }
 111 
 112     ptr = get_print_buffer();
 113     if (NULL == ptr) {
 114         ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
 115         return orte_rmaps_print_null;
 116     }
 117     /* cycle around the ring */
 118     if (ORTE_RMAPS_PRINT_NUM_BUFS == ptr->cntr) {
 119         ptr->cntr = 0;
 120     }
 121 
 122     switch(ORTE_GET_MAPPING_POLICY(mapping)) {
 123     case ORTE_MAPPING_BYNODE:
 124         map = "BYNODE";
 125         break;
 126     case ORTE_MAPPING_BYBOARD:
 127         map = "BYBOARD";
 128         break;
 129     case ORTE_MAPPING_BYNUMA:
 130         map = "BYNUMA";
 131         break;
 132     case ORTE_MAPPING_BYSOCKET:
 133         map = "BYSOCKET";
 134         break;
 135     case ORTE_MAPPING_BYL3CACHE:
 136         map = "BYL3CACHE";
 137         break;
 138     case ORTE_MAPPING_BYL2CACHE:
 139         map = "BYL2CACHE";
 140         break;
 141     case ORTE_MAPPING_BYL1CACHE:
 142         map = "BYL1CACHE";
 143         break;
 144     case ORTE_MAPPING_BYCORE:
 145         map = "BYCORE";
 146         break;
 147     case ORTE_MAPPING_BYHWTHREAD:
 148         map = "BYHWTHREAD";
 149         break;
 150     case ORTE_MAPPING_BYSLOT:
 151         map = "BYSLOT";
 152         break;
 153     case ORTE_MAPPING_SEQ:
 154         map = "SEQUENTIAL";
 155         break;
 156     case ORTE_MAPPING_BYUSER:
 157         map = "BYUSER";
 158         break;
 159     case ORTE_MAPPING_BYDIST:
 160         map = "MINDIST";
 161         break;
 162     default:
 163         if (ORTE_MAPPING_PPR & ORTE_GET_MAPPING_DIRECTIVE(mapping)) {
 164             map = "PPR";
 165         } else {
 166             map = "UNKNOWN";
 167         }
 168     }
 169     if (0 != strcmp(map, "PPR") && (ORTE_MAPPING_PPR & ORTE_GET_MAPPING_DIRECTIVE(mapping))) {
 170         opal_asprintf(&mymap, "%s[PPR]:", map);
 171     } else {
 172         opal_asprintf(&mymap, "%s:", map);
 173     }
 174     if (ORTE_MAPPING_NO_USE_LOCAL & ORTE_GET_MAPPING_DIRECTIVE(mapping)) {
 175         opal_asprintf(&tmp, "%sNO_USE_LOCAL,", mymap);
 176         free(mymap);
 177         mymap = tmp;
 178     }
 179     if (ORTE_MAPPING_NO_OVERSUBSCRIBE & ORTE_GET_MAPPING_DIRECTIVE(mapping)) {
 180         opal_asprintf(&tmp, "%sNOOVERSUBSCRIBE,", mymap);
 181         free(mymap);
 182         mymap = tmp;
 183     } else if (ORTE_MAPPING_SUBSCRIBE_GIVEN & ORTE_GET_MAPPING_DIRECTIVE(mapping)) {
 184         opal_asprintf(&tmp, "%sOVERSUBSCRIBE,", mymap);
 185         free(mymap);
 186         mymap = tmp;
 187     }
 188     if (ORTE_MAPPING_SPAN & ORTE_GET_MAPPING_DIRECTIVE(mapping)) {
 189         opal_asprintf(&tmp, "%sSPAN,", mymap);
 190         free(mymap);
 191         mymap = tmp;
 192     }
 193 
 194     /* remove the trailing mark */
 195     mymap[strlen(mymap)-1] = '\0';
 196 
 197     snprintf(ptr->buffers[ptr->cntr], ORTE_RMAPS_PRINT_MAX_SIZE, "%s", mymap);
 198     free(mymap);
 199     ret = ptr->buffers[ptr->cntr];
 200     ptr->cntr++;
 201 
 202     return ret;
 203 }
 204 
 205 char* orte_rmaps_base_print_ranking(orte_ranking_policy_t ranking)
 206 {
 207     switch(ORTE_GET_RANKING_POLICY(ranking)) {
 208     case ORTE_RANK_BY_NODE:
 209         return "NODE";
 210     case ORTE_RANK_BY_BOARD:
 211         return "BOARD";
 212     case ORTE_RANK_BY_NUMA:
 213         return "NUMA";
 214     case ORTE_RANK_BY_SOCKET:
 215         return "SOCKET";
 216     case ORTE_RANK_BY_CORE:
 217         return "CORE";
 218     case ORTE_RANK_BY_HWTHREAD:
 219         return "HWTHREAD";
 220     case ORTE_RANK_BY_SLOT:
 221         return "SLOT";
 222     default:
 223         return "UNKNOWN";
 224     }
 225 }

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