underling  0.3.2
error.h
Go to the documentation of this file.
1 /***************************************************************************
2 // Adapted from the GNU Scientific Library
3 // Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
4 //-----------------------------------------------------------------------bl-
5 // underling 0.3.1: an FFTW MPI-based library for 3D pencil decompositions
6 // https://github.com/RhysU/underling
7 //
8 // Copyright (C) 2010--2013, 2026 Rhys Ulerich
9 // Copyright (C) 2012, 2013 The PECOS Development Team
10 //
11 // This file is part of underling.
12 //
13 // underling is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // underling is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with underling. If not, see <http://www.gnu.org/licenses/>.
25 //-----------------------------------------------------------------------el-
26 // $Id$
27 ***************************************************************************/
28 
29 #ifndef UNDERLING_ERROR_H
30 #define UNDERLING_ERROR_H
31 
32 #include <stdio.h>
33 #include <underling/visibility.h>
34 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
66 };
67 
87 void
88 underling_error(const char * reason,
89  const char * file,
90  int line,
91  int underling_errno) UNDERLING_API;
92 
104 void
105 underling_stream_printf(const char *label,
106  const char *file,
107  int line,
108  const char *reason) UNDERLING_API;
109 
117 const char *
118 underling_strerror(const int underling_errno) UNDERLING_API;
119 
131 typedef void underling_error_handler_t(const char * reason,
132  const char * file,
133  int line,
134  int underling_errno);
135 
147 typedef void underling_stream_handler_t(const char * label,
148  const char * file,
149  int line,
150  const char * reason);
151 
162  UNDERLING_API;
163 
171 underling_set_error_handler_off(void) UNDERLING_API;
172 
184  UNDERLING_API;
185 
194 FILE *
195 underling_set_stream(FILE * new_stream) UNDERLING_API;
196 
205 #define UNDERLING_ERROR(reason, underling_errno) \
206  do { \
207  underling_error (reason, __FILE__, __LINE__, underling_errno) ; \
208  return underling_errno ; \
209  } while (0)
210 
219 #define UNDERLING_ERROR_VAL(reason, underling_errno, value) \
220  do { \
221  underling_error (reason, __FILE__, __LINE__, underling_errno) ; \
222  return value ; \
223  } while (0)
224 
232 #define UNDERLING_ERROR_VOID(reason, underling_errno) \
233  do { \
234  underling_error (reason, __FILE__, __LINE__, underling_errno) ; \
235  return ; \
236  } while (0)
237 
246 #define UNDERLING_ERROR_NULL(reason, underling_errno) \
247  UNDERLING_ERROR_VAL(reason, underling_errno, 0)
248 
257 #define UNDERLING_ERROR_NULL_FMT(underling_errno, fmt, ...) \
258  do { \
259  char _err_buf[256]; \
260  snprintf(_err_buf, sizeof(_err_buf), fmt, __VA_ARGS__); \
261  underling_error (_err_buf, __FILE__, __LINE__, underling_errno) ; \
262  return 0 ; \
263  } while (0)
264 
273 #define UNDERLING_ERROR_REPORT(reason, underling_errno) \
274  do { \
275  underling_error (reason, __FILE__, __LINE__, underling_errno) ; \
276  } while (0)
277 
279 /* Internal helper macro for implementing UNDERLING_MPICHKx macros */
280 #define UNDERLING_MPICHKx_TEMPLATE(underling_error_macro,stmt) \
281  do { \
282  const int _chk_stat = (stmt); \
283  if (_chk_stat != MPI_SUCCESS) { \
284  char _chk_reason[MPI_MAX_ERROR_STRING + 64]; \
285  char _chk_mpistring[MPI_MAX_ERROR_STRING]; \
286  int _chk_len; \
287  const int _chk_string_stat \
288  = MPI_Error_string(_chk_stat,_chk_mpistring,&_chk_len); \
289  snprintf(_chk_reason, sizeof(_chk_reason)/sizeof(_chk_reason[0]), \
290  "Encountered MPI error code %d: %s", _chk_stat, \
291  (_chk_string_stat == MPI_SUCCESS) \
292  ? _chk_mpistring : "UNKNOWN"); \
293  underling_error_macro(_chk_reason, UNDERLING_EFAILED); \
294  } \
295  } while(0)
296 
311 #define UNDERLING_MPICHKQ(stmt) \
312  UNDERLING_MPICHKx_TEMPLATE(UNDERLING_ERROR,stmt)
313 
326 #define UNDERLING_MPICHKN(stmt) \
327  UNDERLING_MPICHKx_TEMPLATE(UNDERLING_ERROR_NULL,stmt)
328 
341 #define UNDERLING_MPICHKV(stmt) \
342  UNDERLING_MPICHKx_TEMPLATE(UNDERLING_ERROR_VOID,stmt)
343 
356 #define UNDERLING_MPICHKR(stmt) \
357  UNDERLING_MPICHKx_TEMPLATE(UNDERLING_ERROR_REPORT,stmt)
358 
359 #ifdef __cplusplus
360 } /* extern "C" */
361 #endif
362 
363 #endif /* UNDERLING_ERROR_H__ */
UNDERLING_ENOMEM
@ UNDERLING_ENOMEM
Memory allocation failed.
Definition: error.h:65
underling_set_error_handler_off
underling_error_handler_t * underling_set_error_handler_off(void)
An error handler implementation that disables all error reporting.
underling_strerror
const char * underling_strerror(const int underling_errno)
Look up a human-readable error message for the given error status.
underling_stream_handler_t
void underling_stream_handler_t(const char *label, const char *file, int line, const char *reason)
Defines the function prototype necessary for a stream handler.
Definition: error.h:147
underling_set_stream
FILE * underling_set_stream(FILE *new_stream)
Set the default stream for error message display.
UNDERLING_ESANITY
@ UNDERLING_ESANITY
Sanity check failed - shouldn't happen.
Definition: error.h:64
underling_status
underling_status
Standardized error status codes used throughout underling.
Definition: error.h:59
UNDERLING_EFAILED
@ UNDERLING_EFAILED
Generic failure.
Definition: error.h:63
underling_stream_printf
void underling_stream_printf(const char *label, const char *file, int line, const char *reason)
Print an error message to the current error stream.
UNDERLING_SUCCESS
@ UNDERLING_SUCCESS
Success.
Definition: error.h:60
underling_error_handler_t
void underling_error_handler_t(const char *reason, const char *file, int line, int underling_errno)
Defines the function prototype necessary for an error handler.
Definition: error.h:131
underling_set_stream_handler
underling_stream_handler_t * underling_set_stream_handler(underling_stream_handler_t *new_handler)
Sets the current stream handler for the process.
UNDERLING_EINVAL
@ UNDERLING_EINVAL
Invalid argument supplied by user.
Definition: error.h:62
underling_error
void underling_error(const char *reason, const char *file, int line, int underling_errno)
Calls the error handler last set using underling_set_error_handler when invoked.
UNDERLING_EFAULT
@ UNDERLING_EFAULT
Invalid pointer.
Definition: error.h:61
underling_set_error_handler
underling_error_handler_t * underling_set_error_handler(underling_error_handler_t *new_handler)
Sets the current error handler for the process.

Generated on Wed Jul 1 2026 13:22:57 for underling by  doxygen 1.8.17