File: opal_datatype_dump.c

package info (click to toggle)
openmpi 5.0.8-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 201,684 kB
  • sloc: ansic: 613,078; makefile: 42,353; sh: 11,194; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,179; python: 1,859; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (206 lines) | stat: -rw-r--r-- 8,398 bytes parent folder | download | duplicates (3)
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
/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
 * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2019 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2006 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2009      Sun Microsystems, Inc. All rights reserved.
 * Copyright (c) 2009      Oak Ridge National Labs.  All rights reserved.
 * Copyright (c) 2018      Cisco Systems, Inc.  All rights reserved
 * Copyright (c) 2018      Research Organization for Information Science
 *                         and Technology (RIST).  All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "opal_config.h"

#include <stdio.h>
#include <stdlib.h>

#include "opal/constants.h"
#include "opal/datatype/opal_datatype.h"
#include "opal/datatype/opal_datatype_internal.h"
#include "opal/util/output.h"

/********************************************************
 * Data dumping functions
 ********************************************************/

int opal_datatype_contain_basic_datatypes(const opal_datatype_t *pData, char *ptr, size_t length)
{
    int i;
    int32_t index = 0;
    uint64_t mask = 1;

    if (pData->flags & OPAL_DATATYPE_FLAG_USER_LB) {
        index += snprintf(ptr, length - index, "lb ");
    }
    if (pData->flags & OPAL_DATATYPE_FLAG_USER_UB) {
        index += snprintf(ptr + index, length - index, "ub ");
    }
    for (i = 0; i < OPAL_DATATYPE_MAX_PREDEFINED; i++) {
        if (pData->bdt_used & mask) {
            if (NULL == pData->ptypes) {
                index += snprintf(ptr + index, length - index, "%s:* ",
                                  opal_datatype_basicDatatypes[i]->name);
            } else {
                index += snprintf(ptr + index, length - index, "%s:%" PRIsize_t " ",
                                  opal_datatype_basicDatatypes[i]->name, pData->ptypes[i]);
            }
        }
        mask <<= 1;
        if (length <= (size_t) index) {
            break;
        }
    }
    return index;
}

int opal_datatype_dump_data_flags(unsigned short usflags, char *ptr, size_t length)
{
    int index = 0;
    if (length < 22) {
        return 0;
    }
    index = snprintf(ptr, 22, "-----------[---][---]"); /* set everything to - */
    if (usflags & OPAL_DATATYPE_FLAG_COMMITTED) {
        ptr[1] = 'c';
    }
    if (usflags & OPAL_DATATYPE_FLAG_CONTIGUOUS) {
        ptr[2] = 'C';
    }
    if (usflags & OPAL_DATATYPE_FLAG_OVERLAP) {
        ptr[3] = 'o';
    }
    if (usflags & OPAL_DATATYPE_FLAG_USER_LB) {
        ptr[4] = 'l';
    }
    if (usflags & OPAL_DATATYPE_FLAG_USER_UB) {
        ptr[5] = 'u';
    }
    if (usflags & OPAL_DATATYPE_FLAG_PREDEFINED) {
        ptr[6] = 'P';
    }
    if (!(usflags & OPAL_DATATYPE_FLAG_NO_GAPS)) {
        ptr[7] = 'G';
    }
    if (usflags & OPAL_DATATYPE_FLAG_DATA) {
        ptr[8] = 'D';
    }
    if ((usflags & OPAL_DATATYPE_FLAG_BASIC) == OPAL_DATATYPE_FLAG_BASIC) {
        ptr[9] = 'B';
    } else if (usflags & OPAL_DATATYPE_OPTIMIZED_RESTRICTED) {
        ptr[9] = 'H';  /* optimized description restricted to homogeneous cases */
    }
    /* We know nothing about the upper level language or flags! */
    /* ... */
    return index;
}

int opal_datatype_dump_data_desc(dt_elem_desc_t *pDesc, int nbElems, char *ptr, size_t length)
{
    int i;
    int32_t index = 0;

    for (i = 0; i < nbElems; i++) {
        index += opal_datatype_dump_data_flags(pDesc->elem.common.flags, ptr + index, length);
        if (length <= (size_t) index) {
            break;
        }
        index += snprintf(ptr + index, length - index, "%15s ",
                          opal_datatype_basicDatatypes[pDesc->elem.common.type]->name);
        if (length <= (size_t) index) {
            break;
        }
        if (OPAL_DATATYPE_LOOP == pDesc->elem.common.type) {
            index += snprintf(ptr + index, length - index,
                              "%u times the next %u elements extent %td\n", pDesc->loop.loops,
                              pDesc->loop.items, pDesc->loop.extent);
        } else if (OPAL_DATATYPE_END_LOOP == pDesc->elem.common.type) {
            index += snprintf(
                ptr + index, length - index,
                "prev %u elements first elem displacement %td size of data %" PRIsize_t "\n",
                pDesc->end_loop.items, pDesc->end_loop.first_elem_disp, pDesc->end_loop.size);
        } else {
            index += snprintf(ptr + index, length - index,
                              "count %u disp 0x%tx (%td) blen %" PRIsize_t
                              " extent %td (size %zd)\n",
                              pDesc->elem.count, pDesc->elem.disp, pDesc->elem.disp,
                              pDesc->elem.blocklen, pDesc->elem.extent,
                              (pDesc->elem.count * pDesc->elem.blocklen
                               * opal_datatype_basicDatatypes[pDesc->elem.common.type]->size));
        }
        pDesc++;

        if (length <= (size_t) index) {
            break;
        }
    }
    return index;
}

void opal_datatype_dump(const opal_datatype_t *pData)
{
    size_t length;
    int index = 0;
    char *buffer;

    length = pData->opt_desc.used + pData->desc.used;
    length = length * 100 + 500;
    buffer = (char *) malloc(length);
    index += snprintf(buffer, length - index,
                      "Datatype %p[%s] size %" PRIsize_t " align %u id %u length %" PRIsize_t
                      " used %" PRIsize_t "\n"
                      "true_lb %td true_ub %td (true_extent %td) lb %td ub %td (extent %td)\n"
                      "nbElems %" PRIsize_t " loops %u flags %X (",
                      (void *) pData, pData->name, pData->size, pData->align, (uint32_t) pData->id,
                      pData->desc.length, pData->desc.used, pData->true_lb, pData->true_ub,
                      pData->true_ub - pData->true_lb, pData->lb, pData->ub, pData->ub - pData->lb,
                      pData->nbElems, pData->loops, (int) pData->flags);
    /* dump the flags */
    if (pData->flags == OPAL_DATATYPE_FLAG_PREDEFINED) {
        index += snprintf(buffer + index, length - index, "predefined ");
    } else {
        if (pData->flags & OPAL_DATATYPE_FLAG_COMMITTED) {
            index += snprintf(buffer + index, length - index, "committed ");
        }
        if (pData->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) {
            index += snprintf(buffer + index, length - index, "contiguous ");
        }
    }
    index += snprintf(buffer + index, length - index, ")");
    index += opal_datatype_dump_data_flags(pData->flags, buffer + index, length - index);
    {
        index += snprintf(buffer + index, length - index, "\n   contain ");
        index += opal_datatype_contain_basic_datatypes(pData, buffer + index, length - index);
        index += snprintf(buffer + index, length - index, "\n");
    }
    if ((pData->opt_desc.desc != pData->desc.desc) && (NULL != pData->opt_desc.desc)) {
        /* If the data is already committed print everything including the last
         * fake OPAL_DATATYPE_END_LOOP entry.
         */
        index += opal_datatype_dump_data_desc(pData->desc.desc, pData->desc.used + 1,
                                              buffer + index, length - index);
        index += snprintf(buffer + index, length - index, "Optimized description \n");
        index += opal_datatype_dump_data_desc(pData->opt_desc.desc, pData->opt_desc.used + 1,
                                              buffer + index, length - index);
    } else {
        index += opal_datatype_dump_data_desc(pData->desc.desc, pData->desc.used, buffer + index,
                                              length - index);
        index += snprintf(buffer + index, length - index, "No optimized description\n");
    }
    buffer[index] = '\0'; /* make sure we end the string with 0 */
    opal_output(0, "%s\n", buffer);

    free(buffer);
}