File: rmaps_base_print_fns.c

package info (click to toggle)
openmpi 3.1.3-11
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 118,572 kB
  • sloc: ansic: 628,972; f90: 17,993; makefile: 13,761; sh: 7,051; java: 6,360; perl: 3,215; cpp: 2,225; python: 1,350; lex: 988; fortran: 52; tcl: 12
file content (224 lines) | stat: -rw-r--r-- 6,342 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
 * Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2011 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2005 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2011      Cisco Systems, Inc.  All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "orte_config.h"
#include "orte/constants.h"

#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif  /* HAVE_UNISTD_H */
#include <string.h>

#include "opal/util/if.h"
#include "opal/util/output.h"
#include "orte/mca/mca.h"
#include "opal/mca/base/base.h"
#include "opal/mca/hwloc/base/base.h"
#include "opal/threads/tsd.h"

#include "orte/types.h"
#include "orte/util/show_help.h"
#include "orte/util/name_fns.h"
#include "orte/runtime/orte_globals.h"
#include "orte/util/hostfile/hostfile.h"
#include "orte/util/dash_host/dash_host.h"
#include "orte/mca/errmgr/errmgr.h"
#include "orte/mca/ess/ess.h"
#include "orte/runtime/data_type_support/orte_dt_support.h"

#include "orte/mca/rmaps/base/rmaps_private.h"
#include "orte/mca/rmaps/base/base.h"

#define ORTE_RMAPS_PRINT_MAX_SIZE   50
#define ORTE_RMAPS_PRINT_NUM_BUFS   16

static bool fns_init=false;
static opal_tsd_key_t print_tsd_key;
static char* orte_rmaps_print_null = "NULL";
typedef struct {
    char *buffers[ORTE_RMAPS_PRINT_NUM_BUFS];
    int cntr;
} orte_rmaps_print_buffers_t;

static void buffer_cleanup(void *value)
{
    int i;
    orte_rmaps_print_buffers_t *ptr;

    if (NULL != value) {
        ptr = (orte_rmaps_print_buffers_t*)value;
        for (i=0; i < ORTE_RMAPS_PRINT_NUM_BUFS; i++) {
            free(ptr->buffers[i]);
        }
    }
}

static orte_rmaps_print_buffers_t *get_print_buffer(void)
{
    orte_rmaps_print_buffers_t *ptr;
    int ret, i;

    if (!fns_init) {
        /* setup the print_args function */
        if (ORTE_SUCCESS != (ret = opal_tsd_key_create(&print_tsd_key, buffer_cleanup))) {
            ORTE_ERROR_LOG(ret);
            return NULL;
        }
        fns_init = true;
    }

    ret = opal_tsd_getspecific(print_tsd_key, (void**)&ptr);
    if (OPAL_SUCCESS != ret) return NULL;

    if (NULL == ptr) {
        ptr = (orte_rmaps_print_buffers_t*)malloc(sizeof(orte_rmaps_print_buffers_t));
        for (i=0; i < ORTE_RMAPS_PRINT_NUM_BUFS; i++) {
            ptr->buffers[i] = (char *) malloc((ORTE_RMAPS_PRINT_MAX_SIZE+1) * sizeof(char));
        }
        ptr->cntr = 0;
        ret = opal_tsd_setspecific(print_tsd_key, (void*)ptr);
    }

    return (orte_rmaps_print_buffers_t*) ptr;
}

char* orte_rmaps_base_print_mapping(orte_mapping_policy_t mapping)
{
    char *ret, *map, *mymap, *tmp;
    orte_rmaps_print_buffers_t *ptr;

    if (ORTE_MAPPING_CONFLICTED & ORTE_GET_MAPPING_DIRECTIVE(mapping)) {
        return "CONFLICTED";
    }

    ptr = get_print_buffer();
    if (NULL == ptr) {
        ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
        return orte_rmaps_print_null;
    }
    /* cycle around the ring */
    if (ORTE_RMAPS_PRINT_NUM_BUFS == ptr->cntr) {
        ptr->cntr = 0;
    }

    switch(ORTE_GET_MAPPING_POLICY(mapping)) {
    case ORTE_MAPPING_BYNODE:
        map = "BYNODE";
        break;
    case ORTE_MAPPING_BYBOARD:
        map = "BYBOARD";
        break;
    case ORTE_MAPPING_BYNUMA:
        map = "BYNUMA";
        break;
    case ORTE_MAPPING_BYSOCKET:
        map = "BYSOCKET";
        break;
    case ORTE_MAPPING_BYL3CACHE:
        map = "BYL3CACHE";
        break;
    case ORTE_MAPPING_BYL2CACHE:
        map = "BYL2CACHE";
        break;
    case ORTE_MAPPING_BYL1CACHE:
        map = "BYL1CACHE";
        break;
    case ORTE_MAPPING_BYCORE:
        map = "BYCORE";
        break;
    case ORTE_MAPPING_BYHWTHREAD:
        map = "BYHWTHREAD";
        break;
    case ORTE_MAPPING_BYSLOT:
        map = "BYSLOT";
        break;
    case ORTE_MAPPING_SEQ:
        map = "SEQUENTIAL";
        break;
    case ORTE_MAPPING_BYUSER:
        map = "BYUSER";
        break;
    case ORTE_MAPPING_BYDIST:
        map = "MINDIST";
        break;
    default:
        if (ORTE_MAPPING_PPR & ORTE_GET_MAPPING_DIRECTIVE(mapping)) {
            map = "PPR";
        } else {
            map = "UNKNOWN";
        }
    }
    if (0 != strcmp(map, "PPR") && (ORTE_MAPPING_PPR & ORTE_GET_MAPPING_DIRECTIVE(mapping))) {
        asprintf(&mymap, "%s[PPR]:", map);
    } else {
        asprintf(&mymap, "%s:", map);
    }
    if (ORTE_MAPPING_NO_USE_LOCAL & ORTE_GET_MAPPING_DIRECTIVE(mapping)) {
        asprintf(&tmp, "%sNO_USE_LOCAL,", mymap);
        free(mymap);
        mymap = tmp;
    }
    if (ORTE_MAPPING_NO_OVERSUBSCRIBE & ORTE_GET_MAPPING_DIRECTIVE(mapping)) {
        asprintf(&tmp, "%sNOOVERSUBSCRIBE,", mymap);
        free(mymap);
        mymap = tmp;
    } else if (ORTE_MAPPING_SUBSCRIBE_GIVEN & ORTE_GET_MAPPING_DIRECTIVE(mapping)) {
        asprintf(&tmp, "%sOVERSUBSCRIBE,", mymap);
        free(mymap);
        mymap = tmp;
    }
    if (ORTE_MAPPING_SPAN & ORTE_GET_MAPPING_DIRECTIVE(mapping)) {
        asprintf(&tmp, "%sSPAN,", mymap);
        free(mymap);
        mymap = tmp;
    }

    /* remove the trailing mark */
    mymap[strlen(mymap)-1] = '\0';

    snprintf(ptr->buffers[ptr->cntr], ORTE_RMAPS_PRINT_MAX_SIZE, "%s", mymap);
    free(mymap);
    ret = ptr->buffers[ptr->cntr];
    ptr->cntr++;

    return ret;
}

char* orte_rmaps_base_print_ranking(orte_ranking_policy_t ranking)
{
    switch(ORTE_GET_RANKING_POLICY(ranking)) {
    case ORTE_RANK_BY_NODE:
        return "NODE";
    case ORTE_RANK_BY_BOARD:
        return "BOARD";
    case ORTE_RANK_BY_NUMA:
        return "NUMA";
    case ORTE_RANK_BY_SOCKET:
        return "SOCKET";
    case ORTE_RANK_BY_CORE:
        return "CORE";
    case ORTE_RANK_BY_HWTHREAD:
        return "HWTHREAD";
    case ORTE_RANK_BY_SLOT:
        return "SLOT";
    default:
        return "UNKNOWN";
    }
}