IOR
aiori-debug.h
Go to the documentation of this file.
1 #ifndef _AIORI_UTIL_H
2 #define _AIORI_UTIL_H
3 
4 /* This file contains only debug relevant helpers */
5 
6 #include <stdio.h>
7 #include <mpi.h>
8 
9 extern FILE * out_logfile;
10 extern int verbose; /* verbose output */
11 
12 #define FAIL(...) FailMessage(rank, ERROR_LOCATION, __VA_ARGS__)
13 void FailMessage(int rank, const char *location, char *format, ...);
14 
15 /******************************** M A C R O S *********************************/
16 
17 /******************************************************************************/
18 /*
19  * WARN_RESET will display a custom error message and set value to default
20  */
21 #define WARN_RESET(MSG, TO_STRUCT_PTR, FROM_STRUCT_PTR, MEMBER) do { \
22  (TO_STRUCT_PTR)->MEMBER = (FROM_STRUCT_PTR)->MEMBER; \
23  if (rank == 0) { \
24  fprintf(out_logfile, "WARNING: %s. Using value of %d.\n", \
25  MSG, (TO_STRUCT_PTR)->MEMBER); \
26  } \
27  fflush(out_logfile); \
28 } while (0)
29 
30 extern int aiori_warning_as_errors;
31 
32 #define WARN(MSG) do { \
33  if(aiori_warning_as_errors){ ERR(MSG); } \
34  if (verbose > VERBOSE_2) { \
35  fprintf(out_logfile, "WARNING: %s, (%s:%d).\n", \
36  MSG, __FILE__, __LINE__); \
37  } else { \
38  fprintf(out_logfile, "WARNING: %s.\n", MSG); \
39  } \
40  fflush(out_logfile); \
41 } while (0)
42 
43 
44 /* warning with format string and errno printed */
45 #define EWARNF(FORMAT, ...) do { \
46  if(aiori_warning_as_errors){ ERRF(FORMAT, __VA_ARGS__); } \
47  if (verbose > VERBOSE_2) { \
48  fprintf(out_logfile, "WARNING: " FORMAT ", (%s:%d).\n", \
49  __VA_ARGS__, __FILE__, __LINE__); \
50  } else { \
51  fprintf(out_logfile, "WARNING: " FORMAT "\n", \
52  __VA_ARGS__); \
53  } \
54  fflush(out_logfile); \
55 } while (0)
56 
57 
58 /* warning with errno printed */
59 #define EWARN(MSG) do { \
60  EWARNF("%s", MSG); \
61 } while (0)
62 
63 
64 /* warning with format string and errno printed */
65 #define EINFO(FORMAT, ...) do { \
66  if (verbose > VERBOSE_2) { \
67  fprintf(out_logfile, "INFO: " FORMAT ", (%s:%d).\n", \
68  __VA_ARGS__, __FILE__, __LINE__); \
69  } else { \
70  fprintf(out_logfile, "INFO: " FORMAT "\n", \
71  __VA_ARGS__); \
72  } \
73  fflush(out_logfile); \
74 } while (0)
75 
76 /* display error message with format string and terminate execution */
77 #define ERRF(FORMAT, ...) do { \
78  fprintf(out_logfile, "ERROR: " FORMAT ", (%s:%d)\n", \
79  __VA_ARGS__, __FILE__, __LINE__); \
80  fflush(out_logfile); \
81  MPI_Abort(MPI_COMM_WORLD, -1); \
82 } while (0)
83 
84 
85 /* display error message and terminate execution */
86 #define ERR_ERRNO(MSG) do { \
87  ERRF("%s", MSG); \
88 } while (0)
89 
90 
91 /* display a simple error message (i.e. errno is not set) and terminate execution */
92 #define ERR(MSG) do { \
93  fprintf(out_logfile, "ERROR: %s, (%s:%d)\n", \
94  MSG, __FILE__, __LINE__); \
95  fflush(out_logfile); \
96  MPI_Abort(MPI_COMM_WORLD, -1); \
97 } while (0)
98 
99 
100 /******************************************************************************/
101 /*
102  * MPI_CHECKF will display a custom format string as well as an error string
103  * from the MPI_STATUS and then exit the program
104  */
105 
106 #define MPI_CHECKF(MPI_STATUS, FORMAT, ...) do { \
107  char resultString[MPI_MAX_ERROR_STRING]; \
108  int resultLength; \
109  int checkf_mpi_status = MPI_STATUS; \
110  \
111  if (checkf_mpi_status != MPI_SUCCESS) { \
112  MPI_Error_string(checkf_mpi_status, resultString, &resultLength);\
113  fprintf(out_logfile, "ERROR: " FORMAT ", MPI %s, (%s:%d)\n", \
114  __VA_ARGS__, resultString, __FILE__, __LINE__); \
115  fflush(out_logfile); \
116  MPI_Abort(MPI_COMM_WORLD, -1); \
117  } \
118 } while(0)
119 
120 
121 /******************************************************************************/
122 /*
123  * MPI_CHECK will display a custom error message as well as an error string
124  * from the MPI_STATUS and then exit the program
125  */
126 
127 #define MPI_CHECK(MPI_STATUS, MSG) do { \
128  MPI_CHECKF(MPI_STATUS, "%s", MSG); \
129 } while(0)
130 
131 #endif
void FailMessage(int rank, const char *location, char *format,...)
Definition: utilities.c:134
FILE * out_logfile
Definition: utilities.c:72
int verbose
Definition: utilities.c:70
int aiori_warning_as_errors
Definition: ior.c:85
int rank
Definition: utilities.c:68