33 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
44 * University Research and Technology
55 * Corporation. All rights reserved.
6- * Copyright (c) 2004-2007 The University of Tennessee and The University
6+ * Copyright (c) 2004-2020 The University of Tennessee and The University
77 * of Tennessee Research Foundation. All rights
88 * reserved.
99 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
@@ -55,11 +55,68 @@ OMPI_DECLSPEC extern int ompi_mpi_errcode_lastpredefined;
5555
5656OMPI_DECLSPEC extern ompi_mpi_errcode_t ompi_err_unknown ;
5757
58+ /**
59+ * Initialize the error codes
60+ *
61+ * @returns OMPI_SUCCESS Upon success
62+ * @returns OMPI_ERROR Otherwise
63+ *
64+ * Invoked from ompi_mpi_init(); sets up all static MPI error codes,
65+ */
66+ int ompi_mpi_errcode_init (void );
67+
68+ /**
69+ * Finalize the error codes.
70+ *
71+ * @returns OMPI_SUCCESS Always
72+ *
73+ * Invokes from ompi_mpi_finalize(); tears down the error code array.
74+ */
75+ int ompi_mpi_errcode_finalize (void );
76+
77+ /**
78+ * Add an error code
79+ *
80+ * @param: error class to which this new error code belongs to
81+ *
82+ * @returns the new error code on SUCCESS (>0)
83+ * @returns OMPI_ERROR otherwise
84+ *
85+ */
86+ int ompi_mpi_errcode_add (int errclass );
87+
88+ /**
89+ * Add an error class
90+ *
91+ * @param: none
92+ *
93+ * @returns the new error class on SUCCESS (>0)
94+ * @returns OMPI_ERROR otherwise
95+ *
96+ */
97+ int ompi_mpi_errclass_add (void );
98+
99+ /**
100+ * Add an error string to an error code
101+ *
102+ * @param: error code for which the string is defined
103+ * @param: error string to add
104+ * @param: length of the string
105+ *
106+ * @returns OMPI_SUCCESS on success
107+ * @returns OMPI_ERROR on error
108+ */
109+ int ompi_mpi_errnum_add_string (int errnum , const char * string , int len );
110+
58111/**
59112 * Check for a valid error code
60113 */
61114static inline bool ompi_mpi_errcode_is_invalid (int errcode )
62115{
116+ if (OPAL_UNLIKELY ( 0 == ompi_mpi_errcode_lastpredefined )) {
117+ ompi_mpi_errcode_init ();
118+ }
119+
63120 if ( errcode >= 0 && errcode <= ompi_mpi_errcode_lastused )
64121 return 0 ;
65122 else
@@ -73,23 +130,31 @@ static inline int ompi_mpi_errcode_get_class (int errcode)
73130{
74131 ompi_mpi_errcode_t * err = NULL ;
75132
133+ if (OPAL_UNLIKELY ( 0 == ompi_mpi_errcode_lastpredefined )) {
134+ ompi_mpi_errcode_init ();
135+ }
136+
76137 if (errcode >= 0 ) {
77138 err = (ompi_mpi_errcode_t * )opal_pointer_array_get_item (& ompi_mpi_errcodes , errcode );
78139 /* If we get a bogus errcode, return MPI_ERR_UNKNOWN */
79140 }
80141
81142 if (NULL != err ) {
82- if ( err -> code != MPI_UNDEFINED ) {
83- return err -> cls ;
84- }
143+ if ( err -> code != MPI_UNDEFINED ) {
144+ return err -> cls ;
145+ }
85146 }
86147 return ompi_err_unknown .cls ;
87148}
88149
89150static inline int ompi_mpi_errcode_is_predefined ( int errcode )
90151{
152+ if (OPAL_UNLIKELY ( 0 == ompi_mpi_errcode_lastpredefined )) {
153+ ompi_mpi_errcode_init ();
154+ }
155+
91156 if ( errcode >= 0 && errcode <= ompi_mpi_errcode_lastpredefined )
92- return true;
157+ return true;
93158
94159 return false;
95160}
@@ -98,23 +163,27 @@ static inline int ompi_mpi_errnum_is_class ( int errnum )
98163{
99164 ompi_mpi_errcode_t * err ;
100165
166+ if (OPAL_UNLIKELY ( 0 == ompi_mpi_errcode_lastpredefined )) {
167+ ompi_mpi_errcode_init ();
168+ }
169+
101170 if (errnum < 0 ) {
102171 return false;
103172 }
104173
105174 if ( errnum <= ompi_mpi_errcode_lastpredefined ) {
106- /* Predefined error values represent an error code and
107- an error class at the same time */
108- return true;
175+ /* Predefined error values represent an error code and
176+ an error class at the same time */
177+ return true;
109178 }
110179
111180 err = (ompi_mpi_errcode_t * )opal_pointer_array_get_item (& ompi_mpi_errcodes , errnum );
112181 if (NULL != err ) {
113- if ( MPI_UNDEFINED == err -> code ) {
114- /* Distinction between error class and error code is that for the
115- first one the code section is set to MPI_UNDEFINED */
116- return true;
117- }
182+ if ( MPI_UNDEFINED == err -> code ) {
183+ /* Distinction between error class and error code is that for the
184+ first one the code section is set to MPI_UNDEFINED */
185+ return true;
186+ }
118187 }
119188
120189 return false;
@@ -128,6 +197,10 @@ static inline char* ompi_mpi_errnum_get_string (int errnum)
128197{
129198 ompi_mpi_errcode_t * err = NULL ;
130199
200+ if (OPAL_UNLIKELY ( 0 == ompi_mpi_errcode_lastpredefined )) {
201+ ompi_mpi_errcode_init ();
202+ }
203+
131204 if (errnum >= 0 ) {
132205 err = (ompi_mpi_errcode_t * )opal_pointer_array_get_item (& ompi_mpi_errcodes , errnum );
133206 /* If we get a bogus errcode, return a string indicating that this
@@ -142,59 +215,6 @@ static inline char* ompi_mpi_errnum_get_string (int errnum)
142215}
143216
144217
145- /**
146- * Initialize the error codes
147- *
148- * @returns OMPI_SUCCESS Upon success
149- * @returns OMPI_ERROR Otherwise
150- *
151- * Invoked from ompi_mpi_init(); sets up all static MPI error codes,
152- */
153- int ompi_mpi_errcode_init (void );
154-
155- /**
156- * Finalize the error codes.
157- *
158- * @returns OMPI_SUCCESS Always
159- *
160- * Invokes from ompi_mpi_finalize(); tears down the error code array.
161- */
162- int ompi_mpi_errcode_finalize (void );
163-
164- /**
165- * Add an error code
166- *
167- * @param: error class to which this new error code belongs to
168- *
169- * @returns the new error code on SUCCESS (>0)
170- * @returns OMPI_ERROR otherwise
171- *
172- */
173- int ompi_mpi_errcode_add (int errclass );
174-
175- /**
176- * Add an error class
177- *
178- * @param: none
179- *
180- * @returns the new error class on SUCCESS (>0)
181- * @returns OMPI_ERROR otherwise
182- *
183- */
184- int ompi_mpi_errclass_add (void );
185-
186- /**
187- * Add an error string to an error code
188- *
189- * @param: error code for which the string is defined
190- * @param: error string to add
191- * @param: length of the string
192- *
193- * @returns OMPI_SUCCESS on success
194- * @returns OMPI_ERROR on error
195- */
196- int ompi_mpi_errnum_add_string (int errnum , const char * string , int len );
197-
198218END_C_DECLS
199219
200220#endif /* OMPI_MPI_ERRCODE_H */
0 commit comments