OpenMPI 0.1.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

errcode.h
Go to the documentation of this file.
1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
2 /*
3 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4 * University Research and Technology
5 * Corporation. All rights reserved.
6 * Copyright (c) 2004-2007 The University of Tennessee and The University
7 * of Tennessee Research Foundation. All rights
8 * reserved.
9 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10 * University of Stuttgart. All rights reserved.
11 * Copyright (c) 2004-2005 The Regents of the University of California.
12 * All rights reserved.
13 * Copyright (c) 2006 University of Houston. All rights reserved.
14 * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
15 * $COPYRIGHT$
16 *
17 * Additional copyrights may follow
18 *
19 * $HEADER$
20 */
21 /** @file **/
22
23 #ifndef OMPI_MPI_ERRCODE_H
24 #define OMPI_MPI_ERRCODE_H
25
26 #include "ompi_config.h"
27
28 #include "mpi.h"
29 #include "opal/class/opal_object.h"
30 #include "opal/class/opal_pointer_array.h"
31
32 BEGIN_C_DECLS
33
34 /**
35 * Back-end type for MPI error codes.
36 * Please note:
37 * if code == MPI_UNDEFINED, than the according structure
38 * represents an error class.
39 * For the predefined error codes and classes, code and
40 * cls are both set to the according value.
41 */
42 struct ompi_mpi_errcode_t {
43 opal_object_t super;
44 int code;
45 int cls;
46 char errstring[MPI_MAX_ERROR_STRING];
47 };
48 typedef struct ompi_mpi_errcode_t ompi_mpi_errcode_t;
49
50 OMPI_DECLSPEC extern opal_pointer_array_t ompi_mpi_errcodes;
51 OMPI_DECLSPEC extern int ompi_mpi_errcode_lastused;
52 OMPI_DECLSPEC extern int ompi_mpi_errcode_lastpredefined;
53
54 OMPI_DECLSPEC extern ompi_mpi_errcode_t ompi_err_unknown;
55
56 /**
57 * Check for a valid error code
58 */
59 static inline bool ompi_mpi_errcode_is_invalid(int errcode)
60 {
61 if ( errcode >= 0 && errcode <= ompi_mpi_errcode_lastused )
62 return 0;
63 else
64 return 1;
65 }
66
67 /**
68 * Return the error class
69 */
70 static inline int ompi_mpi_errcode_get_class (int errcode)
71 {
72 ompi_mpi_errcode_t *err;
73
74 err = (ompi_mpi_errcode_t *)opal_pointer_array_get_item(&ompi_mpi_errcodes, errcode);
75 /* If we get a bogus errcode, return MPI_ERR_UNKNOWN */
76 if (NULL != err) {
77 if ( err->code != MPI_UNDEFINED ) {
78 return err->cls;
79 }
80 }
81 return ompi_err_unknown.cls;
82 }
83
84 static inline int ompi_mpi_errcode_is_predefined ( int errcode )
85 {
86 if ( errcode >= 0 && errcode <= ompi_mpi_errcode_lastpredefined )
87 return true;
88
89 return false;
90 }
91
92 static inline int ompi_mpi_errnum_is_class ( int errnum )
93 {
94 ompi_mpi_errcode_t *err;
95
96 if ( errnum <= ompi_mpi_errcode_lastpredefined ) {
97 /* Predefined error values represent an error code and
98 an error class at the same time */
99 return true;
100 }
101
102 err = (ompi_mpi_errcode_t *)opal_pointer_array_get_item(&ompi_mpi_errcodes, errnum);
103 if (NULL != err) {
104 if ( MPI_UNDEFINED == err->code) {
105 /* Distinction between error class and error code is that for the
106 first one the code section is set to MPI_UNDEFINED */
107 return true;
108 }
109 }
110
111 return false;
112 }
113
114
115 /**
116 * Return the error string
117 */
118 static inline char* ompi_mpi_errnum_get_string (int errnum)
119 {
120 ompi_mpi_errcode_t *err;
121
122 err = (ompi_mpi_errcode_t *)opal_pointer_array_get_item(&ompi_mpi_errcodes, errnum);
123 /* If we get a bogus errcode, return a string indicating that this
124 truly should not happen */
125 if (NULL != err) {
126 return err->errstring;
127 } else {
128 return "Unknown error (this should not happen!)";
129 }
130 }
131
132
133 /**
134 * Initialize the error codes
135 *
136 * @returns OMPI_SUCCESS Upon success
137 * @returns OMPI_ERROR Otherwise
138 *
139 * Invoked from ompi_mpi_init(); sets up all static MPI error codes,
140 */
141 int ompi_mpi_errcode_init(void);
142
143 /**
144 * Finalize the error codes.
145 *
146 * @returns OMPI_SUCCESS Always
147 *
148 * Invokes from ompi_mpi_finalize(); tears down the error code array.
149 */
150 int ompi_mpi_errcode_finalize(void);
151
152 /**
153 * Add an error code
154 *
155 * @param: error class to which this new error code belongs to
156 *
157 * @returns the new error code on SUCCESS (>0)
158 * @returns OMPI_ERROR otherwise
159 *
160 */
161 int ompi_mpi_errcode_add (int errclass);
162
163 /**
164 * Add an error class
165 *
166 * @param: none
167 *
168 * @returns the new error class on SUCCESS (>0)
169 * @returns OMPI_ERROR otherwise
170 *
171 */
172 int ompi_mpi_errclass_add (void);
173
174 /**
175 * Add an error string to an error code
176 *
177 * @param: error code for which the string is defined
178 * @param: error string to add
179 * @param: length of the string
180 *
181 * @returns OMPI_SUCCESS on success
182 * @returns OMPI_ERROR on error
183 */
184 int ompi_mpi_errnum_add_string (int errnum, char* string, int len);
185
186 END_C_DECLS
187
188 #endif /* OMPI_MPI_ERRCODE_H */
opal_pointer_array_t
dynamic pointer array
Definition: opal_pointer_array.h:45
ompi_mpi_errnum_get_string
static char * ompi_mpi_errnum_get_string(int errnum)
Return the error string.
Definition: errcode.h:118
opal_pointer_array_get_item
static void * opal_pointer_array_get_item(opal_pointer_array_t *table, int element_index)
Get the value of an element in array.
Definition: opal_pointer_array.h:125
opal_pointer_array.h
See opal_bitmap.h for an explanation of why there is a split between OPAL and ORTE for this generic c...
ompi_mpi_errcode_t
Back-end type for MPI error codes.
Definition: errcode.h:42
ompi_mpi_errnum_add_string
int ompi_mpi_errnum_add_string(int errnum, char *string, int len)
Add an error string to an error code.
Definition: errcode.c:298
ompi_mpi_errcode_add
int ompi_mpi_errcode_add(int errclass)
Add an error code.
Definition: errcode.c:273
ompi_mpi_errcode_is_invalid
static bool ompi_mpi_errcode_is_invalid(int errcode)
Check for a valid error code.
Definition: errcode.h:59
opal_object_t
Base object.
Definition: opal_object.h:182
ompi_mpi_errcode_init
int ompi_mpi_errcode_init(void)
Initialize the error codes.
Definition: errcode.c:114
ompi_mpi_errcode_finalize
int ompi_mpi_errcode_finalize(void)
Finalize the error codes.
Definition: errcode.c:196
opal_object.h
A simple C-language object-oriented system with single inheritance and ownership-based memory managem...
ompi_mpi_errcode_get_class
static int ompi_mpi_errcode_get_class(int errcode)
Return the error class.
Definition: errcode.h:70
ompi_mpi_errclass_add
int ompi_mpi_errclass_add(void)
Add an error class.
Definition: errcode.c:286