File: errcode.h

package info (click to toggle)
openmpi 5.0.8-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 201,672 kB
  • sloc: ansic: 613,078; makefile: 42,354; 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 (266 lines) | stat: -rw-r--r-- 6,809 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
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2020 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) 2006      University of Houston. All rights reserved.
 * Copyright (c) 2007-2015 Cisco Systems, Inc.  All rights reserved.
 * Copyright (c) 2015      Los Alamos National Security, LLC.  All rights
 *                         reserved.
 * Copyright (c) 2018      Triad National Security, LLC. All rights
 *                         reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */
/** @file **/

#ifndef OMPI_MPI_ERRCODE_H
#define OMPI_MPI_ERRCODE_H

#include "ompi_config.h"

#include "mpi.h"
#include "opal/class/opal_object.h"
#include "opal/class/opal_pointer_array.h"

BEGIN_C_DECLS

/**
 * Back-end type for MPI error codes.
 * Please note:
 *   if code == MPI_UNDEFINED, than the according structure
 *                             represents an error class.
 *   For the predefined error codes and classes, code and
 *   cls are both set to the according value.
 */
struct ompi_mpi_errcode_t {
    opal_object_t                      super;
    int                                 code;
    int                                  cls;
    char     errstring[MPI_MAX_ERROR_STRING];
};
typedef struct ompi_mpi_errcode_t ompi_mpi_errcode_t;

OMPI_DECLSPEC extern opal_pointer_array_t ompi_mpi_errcodes;
OMPI_DECLSPEC extern int ompi_mpi_errcode_lastused;
OMPI_DECLSPEC extern int ompi_mpi_errcode_lastpredefined;

OMPI_DECLSPEC extern ompi_mpi_errcode_t ompi_err_unknown;

/**
 * Initialize the error codes
 *
 * @returns OMPI_SUCCESS Upon success
 * @returns OMPI_ERROR Otherwise
 *
 * Invoked from ompi_mpi_init(); sets up all static MPI error codes,
 */
int ompi_mpi_errcode_init(void);

/**
 * Finalize the error codes.
 *
 * @returns OMPI_SUCCESS Always
 *
 * Invokes from ompi_mpi_finalize(); tears down the error code array.
 */
int ompi_mpi_errcode_finalize(void);

/**
 * Add an error code
 *
 * @param: error class to which this new error code belongs to
 *
 * @returns the new error code on SUCCESS (>0)
 * @returns OMPI_ERROR otherwise
 *
 */
int ompi_mpi_errcode_add (int errclass);

/**
 * Add an error class
 *
 * @param: none
 *
 * @returns the new error class on SUCCESS (>0)
 * @returns OMPI_ERROR otherwise
 *
 */
int ompi_mpi_errclass_add (void);

/**
 * Add an error string to an error code
 *
 * @param: error code for which the string is defined
 * @param: error string to add
 * @param: length of the string
 *
 * @returns OMPI_SUCCESS on success
 * @returns OMPI_ERROR on error
 */
int ompi_mpi_errnum_add_string (int errnum, const char* string, int len);

/**
 * Check for a valid error code
 */
static inline bool ompi_mpi_errcode_is_invalid(int errcode)
{
    if (OPAL_UNLIKELY( 0 == ompi_mpi_errcode_lastpredefined )) {
        ompi_mpi_errcode_init();
    }

    if ( errcode >= 0 && errcode <= ompi_mpi_errcode_lastused )
        return 0;
    else
        return 1;
}

/**
 * Return the error class
 */
static inline int ompi_mpi_errcode_get_class (int errcode)
{
    ompi_mpi_errcode_t *err = NULL;

    if (OPAL_UNLIKELY( 0 == ompi_mpi_errcode_lastpredefined )) {
        ompi_mpi_errcode_init();
    }

    if (errcode >= 0) {
        err = (ompi_mpi_errcode_t *)opal_pointer_array_get_item(&ompi_mpi_errcodes, errcode);
        /* If we get a bogus errcode, return MPI_ERR_UNKNOWN */
    }

    if (NULL != err) {
        if ( err->code != MPI_UNDEFINED ) {
            return err->cls;
        }
    }
    return ompi_err_unknown.cls;
}

static inline int ompi_mpi_errcode_is_predefined ( int errcode )
{
    if (OPAL_UNLIKELY( 0 == ompi_mpi_errcode_lastpredefined )) {
        ompi_mpi_errcode_init();
    }

    if ( errcode >= 0 && errcode <= ompi_mpi_errcode_lastpredefined )
        return true;

    return false;
}

static inline int ompi_mpi_errnum_is_class ( int errnum )
{
    ompi_mpi_errcode_t *err;

    if (OPAL_UNLIKELY( 0 == ompi_mpi_errcode_lastpredefined )) {
        ompi_mpi_errcode_init();
    }

    if (errnum < 0) {
        return false;
    }

    if ( errnum <= ompi_mpi_errcode_lastpredefined ) {
        /* Predefined error values represent an error code and
           an error class at the same time */
        return true;
    }

    err = (ompi_mpi_errcode_t *)opal_pointer_array_get_item(&ompi_mpi_errcodes, errnum);
    if (NULL != err) {
        if ( MPI_UNDEFINED == err->code) {
            /* Distinction between error class and error code is that for the
               first one the code section is set to MPI_UNDEFINED  */
            return true;
        }
    }

    return false;
}


/**
 * Return the error string
 */
static inline char* ompi_mpi_errnum_get_string (int errnum)
{
    ompi_mpi_errcode_t *err = NULL;

    if (OPAL_UNLIKELY( 0 == ompi_mpi_errcode_lastpredefined )) {
        ompi_mpi_errcode_init();
    }

    if (errnum >= 0) {
        err = (ompi_mpi_errcode_t *)opal_pointer_array_get_item(&ompi_mpi_errcodes, errnum);
        /* If we get a bogus errcode, return a string indicating that this
           truly should not happen */
    }

    if (NULL != err) {
        return err->errstring;
    } else {
        return "Unknown error (this should not happen!)";
    }
}


/**
 * Initialize the error codes
 *
 * @returns OMPI_SUCCESS Upon success
 * @returns OMPI_ERROR Otherwise
 *
 * Invoked from ompi_mpi_init(); sets up all static MPI error codes,
 */
int ompi_mpi_errcode_init(void);

/**
 * Add an error code
 *
 * @param: error class to which this new error code belongs to
 *
 * @returns the new error code on SUCCESS (>0)
 * @returns OMPI_ERROR otherwise
 *
 */
int ompi_mpi_errcode_add (int errclass);

/**
 * Add an error class
 *
 * @param: none
 *
 * @returns the new error class on SUCCESS (>0)
 * @returns OMPI_ERROR otherwise
 *
 */
int ompi_mpi_errclass_add (void);

/**
 * Add an error string to an error code
 *
 * @param: error code for which the string is defined
 * @param: error string to add
 * @param: length of the string
 *
 * @returns OMPI_SUCCESS on success
 * @returns OMPI_ERROR on error
 */
int ompi_mpi_errnum_add_string (int errnum, const char* string, int len);

END_C_DECLS

#endif /* OMPI_MPI_ERRCODE_H */