File: dss_size.c

package info (click to toggle)
openmpi 1.6.5-9.1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 91,628 kB
  • ctags: 44,305
  • sloc: ansic: 408,966; cpp: 44,454; sh: 27,828; makefile: 10,486; asm: 3,882; python: 1,239; lex: 805; perl: 549; csh: 253; fortran: 232; f90: 126; tcl: 12
file content (164 lines) | stat: -rw-r--r-- 3,862 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2006 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$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "opal_config.h"

#include "opal/dss/dss_internal.h"

int opal_dss_size(size_t *size, void *src, opal_data_type_t type)
{
    opal_dss_type_info_t *info;

    /* check for error */
    if (NULL == size) {
        return OPAL_ERR_BAD_PARAM;
    }

    /* Lookup the size function for this type and call it */

    if (NULL == (info = (opal_dss_type_info_t*)opal_pointer_array_get_item(&opal_dss_types, type))) {
        return OPAL_ERR_UNKNOWN_DATA_TYPE;
    }

    return info->odti_size_fn(size, src, type);
}

/*
 * STANDARD SIZE FUNCTION - WORKS FOR EVERYTHING NON-STRUCTURED
 */
int opal_dss_std_size(size_t *size, void *src, opal_data_type_t type)
{
    switch(type) {
        case OPAL_BOOL:
            *size = sizeof(bool);
            break;

        case OPAL_INT:
        case OPAL_UINT:
            *size = sizeof(int);
            break;

        case OPAL_SIZE:
            *size = sizeof(size_t);
            break;

        case OPAL_PID:
            *size = sizeof(pid_t);
            break;

        case OPAL_BYTE:
        case OPAL_INT8:
        case OPAL_UINT8:
        case OPAL_NULL:
            *size = 1;
            break;

        case OPAL_INT16:
        case OPAL_UINT16:
            *size = sizeof(uint16_t);
            break;

        case OPAL_INT32:
        case OPAL_UINT32:
            *size = sizeof(uint32_t);
            break;

        case OPAL_INT64:
        case OPAL_UINT64:
            *size = sizeof(uint64_t);
            break;

        case OPAL_DATA_TYPE:
            *size = sizeof(opal_data_type_t);
            break;

        default:
            *size = 0;
            return OPAL_ERR_UNKNOWN_DATA_TYPE;
    }

    return OPAL_SUCCESS;
}

/* SIZE FUNCTIONS FOR NON-STANDARD SYSTEM TYPES */

/*
 * STRING
 */
int opal_dss_size_string(size_t *size, char *src, opal_data_type_t type)
{
    if (NULL != src) {
        *size = strlen(src) + 1;
    } else {
        *size = sizeof(char*);  /* account for NULL */
    }

    return OPAL_SUCCESS;

}

/* SIZE FUNCTIONS FOR GENERIC OPAL TYPES */

/*
 * OPAL_DATA_VALUE
 */
int opal_dss_size_data_value(size_t *size, opal_dss_value_t *src, opal_data_type_t type)
{
    size_t data_size;
    int rc;

    /* account for size of object itself... */
    *size = sizeof(opal_dss_value_t);

    if (NULL != src) {
        /* ...and the number of bytes in the payload, IF an actual object was provided */
        if (OPAL_SUCCESS != (rc = opal_dss.size(&data_size, src->data, src->type))) {
            return rc;
        }
        *size += data_size;
    }

    return OPAL_SUCCESS;
}


/*
 * OPAL_BYTE_OBJECT
 */
int opal_dss_size_byte_object(size_t *size, opal_byte_object_t *src, opal_data_type_t type)
{
    /* account for size of object itself... */
    *size = sizeof(opal_byte_object_t);

    if (NULL != src) {
        /* ...and the number of bytes in the payload, IF an actual object was provided */
        *size += src->size;
    }

    return OPAL_SUCCESS;
}

/*
 * OPAL_PSTAT
 */
int opal_dss_size_pstat(size_t *size, opal_pstats_t *src, opal_data_type_t type)
{
    *size = sizeof(opal_pstats_t);
    return OPAL_SUCCESS;
}